Skip to content

Commit 6eeb180

Browse files
committed
Update integration test package versions
1 parent c0f5d5e commit 6eeb180

File tree

7 files changed

+285
-7
lines changed

7 files changed

+285
-7
lines changed

Equinox.sln

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "6 - Tests", "6 - Tests", "{
3939
EndProject
4040
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Equinox.Tests.Architecture", "tests\Equinox.Tests.Architecture\Equinox.Tests.Architecture.csproj", "{C4036D98-A669-440C-9970-05DB45815949}"
4141
EndProject
42+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Equinox.Tests.Unit", "tests\Equinox.Tests.Unit\Equinox.Tests.Unit.csproj", "{3DD828A1-824E-4301-9EC4-3EADBDA78CA9}"
43+
EndProject
44+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Equinox.Tests.Integration", "tests\Equinox.Tests.Integration\Equinox.Tests.Integration.csproj", "{ABDB7393-5855-432D-9382-274BEC12D90F}"
45+
EndProject
4246
Global
4347
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4448
Debug|Any CPU = Debug|Any CPU
@@ -82,10 +86,18 @@ Global
8286
{B3000AD2-5EAA-49A2-8FC4-10DF329B15B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
8387
{B3000AD2-5EAA-49A2-8FC4-10DF329B15B0}.Release|Any CPU.Build.0 = Release|Any CPU
8488
{C4036D98-A669-440C-9970-05DB45815949}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
85-
{C4036D98-A669-440C-9970-05DB45815949}.Debug|Any CPU.Build.0 = Debug|Any CPU
86-
{C4036D98-A669-440C-9970-05DB45815949}.Release|Any CPU.ActiveCfg = Release|Any CPU
87-
{C4036D98-A669-440C-9970-05DB45815949}.Release|Any CPU.Build.0 = Release|Any CPU
88-
EndGlobalSection
89+
{C4036D98-A669-440C-9970-05DB45815949}.Debug|Any CPU.Build.0 = Debug|Any CPU
90+
{C4036D98-A669-440C-9970-05DB45815949}.Release|Any CPU.ActiveCfg = Release|Any CPU
91+
{C4036D98-A669-440C-9970-05DB45815949}.Release|Any CPU.Build.0 = Release|Any CPU
92+
{3DD828A1-824E-4301-9EC4-3EADBDA78CA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93+
{3DD828A1-824E-4301-9EC4-3EADBDA78CA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
94+
{3DD828A1-824E-4301-9EC4-3EADBDA78CA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
95+
{3DD828A1-824E-4301-9EC4-3EADBDA78CA9}.Release|Any CPU.Build.0 = Release|Any CPU
96+
{ABDB7393-5855-432D-9382-274BEC12D90F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
97+
{ABDB7393-5855-432D-9382-274BEC12D90F}.Debug|Any CPU.Build.0 = Debug|Any CPU
98+
{ABDB7393-5855-432D-9382-274BEC12D90F}.Release|Any CPU.ActiveCfg = Release|Any CPU
99+
{ABDB7393-5855-432D-9382-274BEC12D90F}.Release|Any CPU.Build.0 = Release|Any CPU
100+
EndGlobalSection
89101
GlobalSection(SolutionProperties) = preSolution
90102
HideSolutionNode = FALSE
91103
EndGlobalSection
@@ -100,9 +112,11 @@ Global
100112
{F0DDF87D-98A4-4237-91C9-FD865ED78ABB} = {0CA11832-7E0F-4038-9DB6-FF1E6D14D0DF}
101113
{91F0D76D-2BEA-43D2-B123-DC29F2E87792} = {DF6C4BDE-F3C5-4E53-A5D5-9D27B2D3E38F}
102114
{788030D0-561B-4136-96B4-D5ABFB5CFD07} = {DF6C4BDE-F3C5-4E53-A5D5-9D27B2D3E38F}
103-
{B3000AD2-5EAA-49A2-8FC4-10DF329B15B0} = {DF6C4BDE-F3C5-4E53-A5D5-9D27B2D3E38F}
104-
{C4036D98-A669-440C-9970-05DB45815949} = {7426F6BA-3DAD-411E-9956-3980D42DC36F}
105-
EndGlobalSection
115+
{B3000AD2-5EAA-49A2-8FC4-10DF329B15B0} = {DF6C4BDE-F3C5-4E53-A5D5-9D27B2D3E38F}
116+
{C4036D98-A669-440C-9970-05DB45815949} = {7426F6BA-3DAD-411E-9956-3980D42DC36F}
117+
{3DD828A1-824E-4301-9EC4-3EADBDA78CA9} = {7426F6BA-3DAD-411E-9956-3980D42DC36F}
118+
{ABDB7393-5855-432D-9382-274BEC12D90F} = {7426F6BA-3DAD-411E-9956-3980D42DC36F}
119+
EndGlobalSection
106120
GlobalSection(ExtensibilityGlobals) = postSolution
107121
SolutionGuid = {4050E145-6791-440A-A2E5-75B05ACD4AFE}
108122
EndGlobalSection
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Bogus;
2+
using Equinox.Application.ViewModels;
3+
using Equinox.Tests.Integration.Support;
4+
using System.Net.Http.Json;
5+
using Xunit;
6+
7+
namespace Equinox.Tests.Integration;
8+
9+
public class CustomerApiTests : IClassFixture<CustomWebApplicationFactory>
10+
{
11+
private readonly HttpClient _client;
12+
private readonly Faker _faker = new();
13+
14+
public CustomerApiTests(CustomWebApplicationFactory factory)
15+
{
16+
_client = factory.CreateClient();
17+
}
18+
19+
[Fact(DisplayName = "Posting a new customer should succeed")]
20+
public async Task PostCustomer_ShouldReturnSuccess()
21+
{
22+
// Arrange
23+
var model = new CustomerViewModel
24+
{
25+
Name = _faker.Person.FullName,
26+
Email = _faker.Internet.Email(),
27+
BirthDate = _faker.Person.DateOfBirth.AddYears(-20)
28+
};
29+
30+
// Act
31+
var response = await _client.PostAsJsonAsync("customer", model);
32+
33+
// Assert
34+
Assert.True(response.IsSuccessStatusCode);
35+
}
36+
37+
[Fact(DisplayName = "New customer should appear in get list")]
38+
public async Task CreatedCustomer_ShouldAppear_OnGetAll()
39+
{
40+
// Arrange
41+
var model = new CustomerViewModel
42+
{
43+
Name = _faker.Person.FullName,
44+
Email = _faker.Internet.Email(),
45+
BirthDate = _faker.Person.DateOfBirth.AddYears(-25)
46+
};
47+
await _client.PostAsJsonAsync("customer", model);
48+
49+
// Act
50+
var customers = await _client.GetFromJsonAsync<List<CustomerViewModel>>("customer");
51+
52+
// Assert
53+
Assert.Contains(customers!, c => c.Email == model.Email);
54+
}
55+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
<IsPackable>false</IsPackable>
7+
<IsTestProject>true</IsTestProject>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<PackageReference Include="coverlet.collector" Version="6.0.4">
11+
<PrivateAssets>all</PrivateAssets>
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
</PackageReference>
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
15+
<PackageReference Include="xunit" Version="2.9.3" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
20+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.5" />
21+
<PackageReference Include="Moq" Version="4.20.83" />
22+
<PackageReference Include="Bogus" Version="35.0.1" />
23+
</ItemGroup>
24+
<ItemGroup>
25+
<ProjectReference Include="..\..\src\Equinox.Services.Api\Equinox.Services.Api.csproj" />
26+
<ProjectReference Include="..\..\src\Equinox.Application\Equinox.Application.csproj" />
27+
</ItemGroup>
28+
</Project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Equinox.Infra.CrossCutting.Identity.Data;
2+
using Equinox.Infra.Data.Context;
3+
using Equinox.Services.Api;
4+
using Microsoft.AspNetCore.Authentication;
5+
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.AspNetCore.Mvc.Testing;
7+
using Microsoft.EntityFrameworkCore;
8+
using Microsoft.Extensions.DependencyInjection;
9+
10+
namespace Equinox.Tests.Integration.Support;
11+
12+
public class CustomWebApplicationFactory : WebApplicationFactory<Program>
13+
{
14+
protected override void ConfigureWebHost(IWebHostBuilder builder)
15+
{
16+
builder.UseEnvironment("Testing");
17+
18+
builder.ConfigureServices(services =>
19+
{
20+
// Remove existing DbContexts
21+
var dbContextDescriptor = services.SingleOrDefault(d =>
22+
d.ServiceType == typeof(DbContextOptions<EquinoxContext>));
23+
if (dbContextDescriptor != null) services.Remove(dbContextDescriptor);
24+
25+
var eventStoreDescriptor = services.SingleOrDefault(d =>
26+
d.ServiceType == typeof(DbContextOptions<EventStoreSqlContext>));
27+
if (eventStoreDescriptor != null) services.Remove(eventStoreDescriptor);
28+
29+
var identityDescriptor = services.SingleOrDefault(d =>
30+
d.ServiceType == typeof(DbContextOptions<EquinoxIdentityContext>));
31+
if (identityDescriptor != null) services.Remove(identityDescriptor);
32+
33+
// Add in-memory databases for testing
34+
services.AddDbContext<EquinoxContext>(options =>
35+
options.UseInMemoryDatabase("EquinoxTest"));
36+
services.AddDbContext<EventStoreSqlContext>(options =>
37+
options.UseInMemoryDatabase("EquinoxTestStore"));
38+
services.AddDbContext<EquinoxIdentityContext>(options =>
39+
options.UseInMemoryDatabase("EquinoxTestIdentity"));
40+
41+
// Add test authentication
42+
services.AddAuthentication("Test")
43+
.AddScheme<AuthenticationSchemeOptions, TestAuthHandler>("Test", options => { });
44+
45+
var sp = services.BuildServiceProvider();
46+
using var scope = sp.CreateScope();
47+
scope.ServiceProvider.GetRequiredService<EquinoxContext>().Database.EnsureCreated();
48+
scope.ServiceProvider.GetRequiredService<EventStoreSqlContext>().Database.EnsureCreated();
49+
scope.ServiceProvider.GetRequiredService<EquinoxIdentityContext>().Database.EnsureCreated();
50+
});
51+
}
52+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Security.Claims;
2+
using System.Text.Encodings.Web;
3+
using Microsoft.AspNetCore.Authentication;
4+
using Microsoft.Extensions.Logging;
5+
using Microsoft.Extensions.Options;
6+
7+
namespace Equinox.Tests.Integration.Support;
8+
9+
public class TestAuthHandler : AuthenticationHandler<AuthenticationSchemeOptions>
10+
{
11+
public TestAuthHandler(
12+
IOptionsMonitor<AuthenticationSchemeOptions> options,
13+
ILoggerFactory logger,
14+
UrlEncoder encoder,
15+
ISystemClock clock) : base(options, logger, encoder, clock)
16+
{
17+
}
18+
19+
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
20+
{
21+
var claims = new[]
22+
{
23+
new Claim(ClaimTypes.Name, "integration"),
24+
new Claim("Customers", "Write,Remove")
25+
};
26+
var identity = new ClaimsIdentity(claims, Scheme.Name);
27+
var principal = new ClaimsPrincipal(identity);
28+
var ticket = new AuthenticationTicket(principal, Scheme.Name);
29+
return Task.FromResult(AuthenticateResult.Success(ticket));
30+
}
31+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using Bogus;
2+
using Equinox.Domain.Commands;
3+
using Xunit;
4+
5+
namespace Equinox.Tests.Unit;
6+
7+
public class CustomerCommandValidationTests
8+
{
9+
private readonly Faker _faker = new();
10+
11+
[Fact(DisplayName = "Register command with valid data should be valid")]
12+
public void RegisterNewCustomerCommand_WithValidData_ShouldBeValid()
13+
{
14+
// Arrange
15+
var command = new RegisterNewCustomerCommand(
16+
_faker.Person.FullName,
17+
_faker.Internet.Email(),
18+
_faker.Person.DateOfBirth.AddYears(-18));
19+
20+
// Act
21+
var result = command.IsValid();
22+
23+
// Assert
24+
Assert.True(result);
25+
}
26+
27+
[Fact(DisplayName = "Register command with under age customer should be invalid")]
28+
public void RegisterNewCustomerCommand_UnderAge_ShouldBeInvalid()
29+
{
30+
// Arrange
31+
var command = new RegisterNewCustomerCommand(
32+
_faker.Person.FullName,
33+
_faker.Internet.Email(),
34+
DateTime.Now.AddYears(-17));
35+
36+
// Act
37+
var result = command.IsValid();
38+
39+
// Assert
40+
Assert.False(result);
41+
}
42+
43+
[Fact(DisplayName = "Update command with empty name should be invalid")]
44+
public void UpdateCustomerCommand_EmptyName_ShouldBeInvalid()
45+
{
46+
// Arrange
47+
var command = new UpdateCustomerCommand(
48+
Guid.NewGuid(),
49+
string.Empty,
50+
_faker.Internet.Email(),
51+
_faker.Person.DateOfBirth.AddYears(-20));
52+
53+
// Act
54+
var result = command.IsValid();
55+
56+
// Assert
57+
Assert.False(result);
58+
}
59+
60+
[Fact(DisplayName = "Remove command with empty id should be invalid")]
61+
public void RemoveCustomerCommand_EmptyId_ShouldBeInvalid()
62+
{
63+
// Arrange
64+
var command = new RemoveCustomerCommand(Guid.Empty);
65+
66+
// Act
67+
var result = command.IsValid();
68+
69+
// Assert
70+
Assert.False(result);
71+
}
72+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
<IsPackable>false</IsPackable>
7+
<IsTestProject>true</IsTestProject>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<PackageReference Include="coverlet.collector" Version="6.0.4">
11+
<PrivateAssets>all</PrivateAssets>
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
</PackageReference>
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
15+
<PackageReference Include="xunit" Version="2.9.3" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
20+
<PackageReference Include="Moq" Version="4.20.83" />
21+
<PackageReference Include="Bogus" Version="35.0.1" />
22+
</ItemGroup>
23+
<ItemGroup>
24+
<ProjectReference Include="..\..\src\Equinox.Domain\Equinox.Domain.csproj" />
25+
</ItemGroup>
26+
</Project>

0 commit comments

Comments
 (0)