Skip to content

Commit

Permalink
just-in-case
Browse files Browse the repository at this point in the history
  • Loading branch information
Edrisym committed Dec 7, 2024
1 parent 2f25b76 commit b13c76e
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 2 deletions.
7 changes: 5 additions & 2 deletions EWallet.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Security.Authentication;
using EWallet.Infrastructure.ExceptionHandler;
using Figgle;

Expand Down Expand Up @@ -26,4 +25,8 @@
app.MapFallback(()
=> Results.NotFound("Route not found"));

app.Run();
app.Run();

public partial class Program
{
}
56 changes: 56 additions & 0 deletions Integrations/IntegrationFixture.cs
Original file line number Diff line number Diff line change
@@ -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<MsSqlContainer>()
.ConfigureDatabaseConfiguration("sa", "reallyStrongPwd123!", "WalletDb")
.Build();

_container.StartAsync().GetAwaiter().GetResult();
}

public WalletDbContext CreateContext()
{
var connectionString = _container.GetConnectionString();

var dbContext = new WalletDbContext(
new DbContextOptionsBuilder<WalletDbContext>()
.UseSqlServer(connectionString)
.Options);

dbContext.Database.EnsureCreated();

return dbContext;
}

public async ValueTask DisposeAsync()
{
await _container.StopAsync();
}

public async Task<HttpResponseMessage> SendRequestAsync(HttpRequestMessage request)
{
return await _client.SendAsync(request);
}

public void Dispose()
{
_container.StopAsync().GetAwaiter().GetResult();
}
}
}
56 changes: 56 additions & 0 deletions Integrations/Wallet/WalletEndpointTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
31 changes: 31 additions & 0 deletions Integrations/Wallet/WalletIntegrationTestManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using EWallet.Api.Wallets.EndPoints;

namespace Integrations.Wallet;

public class WalletIntegrationTestManager : IClassFixture<IntegrationFixture>
{
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);
// }
}
7 changes: 7 additions & 0 deletions Wallet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit b13c76e

Please sign in to comment.