-
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
1 parent
e842c11
commit 26108c9
Showing
13 changed files
with
227 additions
and
34 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
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
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
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
32 changes: 32 additions & 0 deletions
32
...ackend.Modules.Settings.IntegrationTests/Backend.Modules.Settings.IntegrationTests.csproj
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,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.8.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Backend.Modules.Settings\Backend.Modules.Settings.csproj" /> | ||
<ProjectReference Include="..\..\src\Backend.Modules\Backend.Modules.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
6 changes: 6 additions & 0 deletions
6
tests/Backend.Modules.Settings.IntegrationTests/Fixtures/ContainerCollectionFixture.cs
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,6 @@ | ||
namespace Backend.Modules.Settings.IntegrationTests.Fixtures; | ||
|
||
[CollectionDefinition(nameof(ContainerCollectionFixture))] | ||
public class ContainerCollectionFixture : ICollectionFixture<ContainerFixture> | ||
{ | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/Backend.Modules.Settings.IntegrationTests/Fixtures/ContainerFixture.cs
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,33 @@ | ||
using Backend.Modules.Infrastructure.Database; | ||
|
||
namespace Backend.Modules.Settings.IntegrationTests.Fixtures; | ||
|
||
public class ContainerFixture : IDisposable | ||
{ | ||
private readonly ServiceProvider _provider; | ||
|
||
public ContainerFixture() | ||
{ | ||
var configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection() | ||
.AddEnvironmentVariables() | ||
.Build(); | ||
|
||
var services = new ServiceCollection() | ||
.AddModules(configuration) | ||
.AddSettings(configuration); | ||
|
||
services | ||
.AddSingleton<IConfiguration>(configuration); | ||
|
||
_provider = services.BuildServiceProvider(); | ||
_provider.ExecuteDatabaseMigration(x => x.ResetDatabase()); | ||
} | ||
|
||
public IServiceProvider Provider => _provider; | ||
|
||
public void Dispose() | ||
{ | ||
_provider.Dispose(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/Backend.Modules.Settings.IntegrationTests/Fixtures/ProviderExtensions.cs
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,35 @@ | ||
using Backend.Modules.Infrastructure.Tenancy; | ||
|
||
namespace Backend.Modules.Settings.IntegrationTests.Fixtures; | ||
|
||
public static class ProviderExtensions | ||
{ | ||
public static async Task ExecuteCommand(this IServiceProvider provider, IRequest command, Guid? tenant = null) | ||
{ | ||
using var scope = provider.CreateScope(); | ||
if (tenant != null) | ||
{ | ||
SetTenantContext(tenant.Value, scope); | ||
} | ||
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
await mediator.Send(command); | ||
} | ||
|
||
public static async Task<T> ExecuteQuery<T>(this IServiceProvider provider, IRequest<T> query, Guid? tenant = null) | ||
{ | ||
using var scope = provider.CreateScope(); | ||
if (tenant != null) | ||
{ | ||
SetTenantContext(tenant.Value, scope); | ||
} | ||
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
return await mediator.Send(query); | ||
} | ||
|
||
private static void SetTenantContext(Guid tenant, IServiceScope scope) | ||
{ | ||
// resolve the tenant context so that it can be set for this use case | ||
var setter = scope.ServiceProvider.GetRequiredService<ISetTenantContext>(); | ||
setter.SetCurrentTenant(tenant); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/Backend.Modules.Settings.IntegrationTests/GlobalUsings.cs
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,9 @@ | ||
// Global using directives | ||
global using System; | ||
global using System.Collections.Generic; | ||
global using System.Threading.Tasks; | ||
global using FluentAssertions; | ||
global using MediatR; | ||
global using Microsoft.Extensions.Configuration; | ||
global using Microsoft.Extensions.DependencyInjection; | ||
global using Xunit; |
Oops, something went wrong.