-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters