diff --git a/EWallet.Api/Program.cs b/EWallet.Api/Program.cs index 1dd438a..a36cc16 100644 --- a/EWallet.Api/Program.cs +++ b/EWallet.Api/Program.cs @@ -1,4 +1,3 @@ -using System.Security.Authentication; using EWallet.Infrastructure.ExceptionHandler; using Figgle; @@ -26,4 +25,8 @@ app.MapFallback(() => Results.NotFound("Route not found")); -app.Run(); \ No newline at end of file +app.Run(); + +public partial class Program +{ +} \ No newline at end of file diff --git a/Integrations/IntegrationFixture.cs b/Integrations/IntegrationFixture.cs new file mode 100644 index 0000000..f468926 --- /dev/null +++ b/Integrations/IntegrationFixture.cs @@ -0,0 +1,56 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.TestHost; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using TestContainers.Container.Abstractions.Hosting; +using TestContainers.Container.Database.Hosting; +using TestContainers.Container.Database.MsSql; + +namespace Integrations +{ + public class IntegrationFixture : IAsyncDisposable + { + private readonly MsSqlContainer _container; + private readonly TestServer _server; + private readonly HttpClient _client; + + public IntegrationFixture() + { + _container = new ContainerBuilder() + .ConfigureDatabaseConfiguration("sa", "reallyStrongPwd123!", "WalletDb") + .Build(); + + _container.StartAsync().GetAwaiter().GetResult(); + } + + public WalletDbContext CreateContext() + { + var connectionString = _container.GetConnectionString(); + + var dbContext = new WalletDbContext( + new DbContextOptionsBuilder() + .UseSqlServer(connectionString) + .Options); + + dbContext.Database.EnsureCreated(); + + return dbContext; + } + + public async ValueTask DisposeAsync() + { + await _container.StopAsync(); + } + + public async Task SendRequestAsync(HttpRequestMessage request) + { + return await _client.SendAsync(request); + } + + public void Dispose() + { + _container.StopAsync().GetAwaiter().GetResult(); + } + } +} \ No newline at end of file diff --git a/Integrations/Wallet/WalletEndpointTests.cs b/Integrations/Wallet/WalletEndpointTests.cs new file mode 100644 index 0000000..583e3ed --- /dev/null +++ b/Integrations/Wallet/WalletEndpointTests.cs @@ -0,0 +1,56 @@ +using System.Net; +using System.Net.Http.Json; +using EWallet.Api.Wallets.EndPoints; +using FluentAssertions; +using Microsoft.AspNetCore.Builder; + +namespace Integrations.Wallet; + +public class WalletEndpointTests +{ + private readonly WalletDbContext _db; + private readonly IntegrationFixture _fixture; + + public WalletEndpointTests(IntegrationFixture fixture) + { + _db = fixture.CreateContext(); + _fixture = fixture; + } + + public async Task TestGetApi() + { + // Arrange + var request = new HttpRequestMessage(HttpMethod.Get, "/api/v1/wallets"); + + // Act + var response = await _fixture.SendRequestAsync(request); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + + var responseContent = await response.Content.ReadAsStringAsync(); + Assert.Equal("Test response", responseContent); + } + + public async Task Ensure_Wallet_Created_Successfully(WalletDto request) + { + // Arrange + // Act + // var response = await _factory.PostAsJsonAsync("/api/v1/wallets/", request); + // Assert + // response.Should().BeSuccessful(); + // response.Should().NotBeNull(); + } + + public async Task Ensure_Wallet_Created_With_All_Fields_Successfully(WalletDto request) + { + // Arrange + var wallet = new WalletDto(10m, Guid.NewGuid()); + + // Act + // var response = await _factory.CreateClient().PostAsJsonAsync("/api/v1/wallets/", request); + + // Assert + // response.Should().BeEquivalentTo(request); + } +} \ No newline at end of file diff --git a/Integrations/Wallet/WalletIntegrationTestManager.cs b/Integrations/Wallet/WalletIntegrationTestManager.cs new file mode 100644 index 0000000..433fa24 --- /dev/null +++ b/Integrations/Wallet/WalletIntegrationTestManager.cs @@ -0,0 +1,31 @@ +using EWallet.Api.Wallets.EndPoints; + +namespace Integrations.Wallet; + +public class WalletIntegrationTestManager : IClassFixture +{ + private readonly IntegrationFixture _factory; + private readonly WalletEndpointTests _endpointTests; + + public WalletIntegrationTestManager(IntegrationFixture factory) + { + _factory = factory; + _endpointTests = new WalletEndpointTests(_factory); + } + + + [Fact] + public async Task TestGetApi() + { + await _endpointTests.TestGetApi(); + } + // [Fact] + // public async Task Ensure_Wallet_Create_Successfully() + // { + // // Test data + // var wallet = new WalletDto(10m, Guid.NewGuid()); + // + // // Use the endpoint tests + // await _endpointTests.Ensure_Wallet_Created_Successfully(wallet); + // } +} \ No newline at end of file diff --git a/Wallet.sln b/Wallet.sln index 277b951..5e4f34c 100644 --- a/Wallet.sln +++ b/Wallet.sln @@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JwtAuth.Api", "JwtAuth.Api\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EWallet.Infrastructure", "EWallet.Infrastructure\EWallet.Infrastructure.csproj", "{11280331-D7E1-4855-B31C-EC52A73DAEBA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Integrations", "Integrations\Integrations.csproj", "{BB633941-0CD1-4296-BB5B-13773E61C2C3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -34,11 +36,16 @@ Global {11280331-D7E1-4855-B31C-EC52A73DAEBA}.Debug|Any CPU.Build.0 = Debug|Any CPU {11280331-D7E1-4855-B31C-EC52A73DAEBA}.Release|Any CPU.ActiveCfg = Release|Any CPU {11280331-D7E1-4855-B31C-EC52A73DAEBA}.Release|Any CPU.Build.0 = Release|Any CPU + {BB633941-0CD1-4296-BB5B-13773E61C2C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BB633941-0CD1-4296-BB5B-13773E61C2C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BB633941-0CD1-4296-BB5B-13773E61C2C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BB633941-0CD1-4296-BB5B-13773E61C2C3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {628581B3-CBF4-47B5-A7BE-D81634999389} = {9B06A700-D91F-43C8-977D-CCA3FBFE244A} {0D30908F-DE5A-4896-B97A-0F1A61D958AA} = {272CA49E-0294-4E32-A94C-635F32D0B74A} {1AD22D7C-F858-470C-819C-49ADF31A0F81} = {272CA49E-0294-4E32-A94C-635F32D0B74A} {11280331-D7E1-4855-B31C-EC52A73DAEBA} = {272CA49E-0294-4E32-A94C-635F32D0B74A} + {BB633941-0CD1-4296-BB5B-13773E61C2C3} = {9B06A700-D91F-43C8-977D-CCA3FBFE244A} EndGlobalSection EndGlobal