mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-06-30 02:31:08 +00:00
chore: Code Cleanup
This commit is contained in:
parent
a3152580a2
commit
61bcab6d77
@ -7,26 +7,26 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.ApplicationStatus" Version="7.0.0" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="7.0.0" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="7.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.10" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.10" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.ApplicationStatus" Version="7.0.0"/>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="7.0.0"/>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="7.1.0"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.10"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.10"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.10" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.10"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.10"/>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CleanArchitecture.Application\CleanArchitecture.Application.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.gRPC\CleanArchitecture.gRPC.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Infrastructure\CleanArchitecture.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Application\CleanArchitecture.Application.csproj"/>
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj"/>
|
||||
<ProjectReference Include="..\CleanArchitecture.gRPC\CleanArchitecture.gRPC.csproj"/>
|
||||
<ProjectReference Include="..\CleanArchitecture.Infrastructure\CleanArchitecture.Infrastructure.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -60,9 +60,12 @@ public static class ServiceCollectionExtension
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
services.AddAuthentication(
|
||||
options => { options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; })
|
||||
options => { options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; })
|
||||
.AddJwtBearer(
|
||||
jwtOptions => { jwtOptions.TokenValidationParameters = CreateTokenValidationParameters(configuration); });
|
||||
jwtOptions =>
|
||||
{
|
||||
jwtOptions.TokenValidationParameters = CreateTokenValidationParameters(configuration);
|
||||
});
|
||||
|
||||
services
|
||||
.AddOptions<TokenSettings>()
|
||||
|
@ -4,9 +4,7 @@ namespace CleanArchitecture.Api.Models;
|
||||
|
||||
public sealed class DetailedError
|
||||
{
|
||||
[JsonPropertyName("code")]
|
||||
public string Code { get; init; } = string.Empty;
|
||||
[JsonPropertyName("code")] public string Code { get; init; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("data")]
|
||||
public object? Data { get; init; }
|
||||
[JsonPropertyName("data")] public object? Data { get; init; }
|
||||
}
|
@ -6,15 +6,12 @@ namespace CleanArchitecture.Api.Models;
|
||||
|
||||
public sealed class ResponseMessage<T>
|
||||
{
|
||||
[JsonPropertyName("success")]
|
||||
public bool Success { get; init; }
|
||||
[JsonPropertyName("success")] public bool Success { get; init; }
|
||||
|
||||
[JsonPropertyName("errors")]
|
||||
public IEnumerable<string>? Errors { get; init; }
|
||||
[JsonPropertyName("errors")] public IEnumerable<string>? Errors { get; init; }
|
||||
|
||||
[JsonPropertyName("detailedErrors")]
|
||||
public IEnumerable<DetailedError> DetailedErrors { get; init; } = Enumerable.Empty<DetailedError>();
|
||||
|
||||
[JsonPropertyName("data")]
|
||||
public T? Data { get; init; }
|
||||
[JsonPropertyName("data")] public T? Data { get; init; }
|
||||
}
|
@ -61,9 +61,9 @@ var app = builder.Build();
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var services = scope.ServiceProvider;
|
||||
ApplicationDbContext appDbContext = services.GetRequiredService<ApplicationDbContext>();
|
||||
EventStoreDbContext storeDbContext = services.GetRequiredService<EventStoreDbContext>();
|
||||
DomainNotificationStoreDbContext domainStoreDbContext = services.GetRequiredService<DomainNotificationStoreDbContext>();
|
||||
var appDbContext = services.GetRequiredService<ApplicationDbContext>();
|
||||
var storeDbContext = services.GetRequiredService<EventStoreDbContext>();
|
||||
var domainStoreDbContext = services.GetRequiredService<DomainNotificationStoreDbContext>();
|
||||
|
||||
appDbContext.EnsureMigrationsApplied();
|
||||
|
||||
|
@ -8,11 +8,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
|
||||
<PackageReference Include="MockQueryable.NSubstitute" Version="7.0.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0"/>
|
||||
<PackageReference Include="MockQueryable.NSubstitute" Version="7.0.0"/>
|
||||
<PackageReference Include="NSubstitute" Version="5.0.0"/>
|
||||
<PackageReference Include="xunit" Version="2.5.0"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@ -24,8 +24,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CleanArchitecture.Application\CleanArchitecture.Application.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Application\CleanArchitecture.Application.csproj"/>
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -11,9 +11,9 @@ public class QueryHandlerBaseFixture
|
||||
public QueryHandlerBaseFixture VerifyExistingNotification(string key, string errorCode, string message)
|
||||
{
|
||||
Bus.Received(1).RaiseEventAsync(Arg.Is<DomainNotification>(notification =>
|
||||
notification.Key == key &&
|
||||
notification.Code == errorCode &&
|
||||
notification.Value == message));
|
||||
notification.Key == key &&
|
||||
notification.Code == errorCode &&
|
||||
notification.Value == message));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -10,16 +10,16 @@ namespace CleanArchitecture.Application.Tests.Fixtures.Queries.Tenants;
|
||||
|
||||
public sealed class GetAllTenantsTestFixture : QueryHandlerBaseFixture
|
||||
{
|
||||
public GetAllTenantsQueryHandler QueryHandler { get; }
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
|
||||
public GetAllTenantsTestFixture()
|
||||
{
|
||||
TenantRepository = Substitute.For<ITenantRepository>();
|
||||
|
||||
QueryHandler = new(TenantRepository);
|
||||
QueryHandler = new GetAllTenantsQueryHandler(TenantRepository);
|
||||
}
|
||||
|
||||
public GetAllTenantsQueryHandler QueryHandler { get; }
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
|
||||
public Tenant SetupTenant(bool deleted = false)
|
||||
{
|
||||
var tenant = new Tenant(Guid.NewGuid(), "Tenant 1");
|
||||
|
@ -10,18 +10,18 @@ namespace CleanArchitecture.Application.Tests.Fixtures.Queries.Tenants;
|
||||
|
||||
public sealed class GetTenantByIdTestFixture : QueryHandlerBaseFixture
|
||||
{
|
||||
public GetTenantByIdQueryHandler QueryHandler { get; }
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
|
||||
public GetTenantByIdTestFixture()
|
||||
{
|
||||
TenantRepository = Substitute.For<ITenantRepository>();
|
||||
|
||||
QueryHandler = new(
|
||||
QueryHandler = new GetTenantByIdQueryHandler(
|
||||
TenantRepository,
|
||||
Bus);
|
||||
}
|
||||
|
||||
public GetTenantByIdQueryHandler QueryHandler { get; }
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
|
||||
public Tenant SetupTenant(bool deleted = false)
|
||||
{
|
||||
var tenant = new Tenant(Guid.NewGuid(), "Tenant 1");
|
||||
|
@ -24,13 +24,13 @@ public sealed class GetAllUsersTestFixture : QueryHandlerBaseFixture
|
||||
public void SetupUserAsync()
|
||||
{
|
||||
var user = new User(
|
||||
ExistingUserId,
|
||||
Guid.NewGuid(),
|
||||
"max@mustermann.com",
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"Password",
|
||||
UserRole.User);
|
||||
ExistingUserId,
|
||||
Guid.NewGuid(),
|
||||
"max@mustermann.com",
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"Password",
|
||||
UserRole.User);
|
||||
|
||||
var query = new[] { user }.BuildMock();
|
||||
|
||||
@ -40,13 +40,13 @@ public sealed class GetAllUsersTestFixture : QueryHandlerBaseFixture
|
||||
public void SetupDeletedUserAsync()
|
||||
{
|
||||
var user = new User(
|
||||
ExistingUserId,
|
||||
Guid.NewGuid(),
|
||||
"max@mustermann.com",
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"Password",
|
||||
UserRole.User);
|
||||
ExistingUserId,
|
||||
Guid.NewGuid(),
|
||||
"max@mustermann.com",
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"Password",
|
||||
UserRole.User);
|
||||
|
||||
user.Delete();
|
||||
|
||||
|
@ -25,13 +25,13 @@ public sealed class GetUserByIdTestFixture : QueryHandlerBaseFixture
|
||||
public void SetupUserAsync()
|
||||
{
|
||||
var user = new User(
|
||||
ExistingUserId,
|
||||
Guid.NewGuid(),
|
||||
"max@mustermann.com",
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"Password",
|
||||
UserRole.User);
|
||||
ExistingUserId,
|
||||
Guid.NewGuid(),
|
||||
"max@mustermann.com",
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"Password",
|
||||
UserRole.User);
|
||||
|
||||
var query = new[] { user }.BuildMock();
|
||||
|
||||
@ -41,13 +41,13 @@ public sealed class GetUserByIdTestFixture : QueryHandlerBaseFixture
|
||||
public void SetupDeletedUserAsync()
|
||||
{
|
||||
var user = new User(
|
||||
ExistingUserId,
|
||||
Guid.NewGuid(),
|
||||
"max@mustermann.com",
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"Password",
|
||||
UserRole.User);
|
||||
ExistingUserId,
|
||||
Guid.NewGuid(),
|
||||
"max@mustermann.com",
|
||||
"Max",
|
||||
"Mustermann",
|
||||
"Password",
|
||||
UserRole.User);
|
||||
|
||||
user.Delete();
|
||||
|
||||
|
@ -6,14 +6,13 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.10"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Proto\CleanArchitecture.Proto.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj"/>
|
||||
<ProjectReference Include="..\CleanArchitecture.Proto\CleanArchitecture.Proto.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
</Project>
|
||||
|
@ -30,7 +30,8 @@ public static class ServiceCollectionExtension
|
||||
|
||||
// Tenant
|
||||
services.AddScoped<IRequestHandler<GetTenantByIdQuery, TenantViewModel?>, GetTenantByIdQueryHandler>();
|
||||
services.AddScoped<IRequestHandler<GetAllTenantsQuery, IEnumerable<TenantViewModel>>, GetAllTenantsQueryHandler>();
|
||||
services
|
||||
.AddScoped<IRequestHandler<GetAllTenantsQuery, IEnumerable<TenantViewModel>>, GetAllTenantsQueryHandler>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
@ -4,4 +4,4 @@ using MediatR;
|
||||
|
||||
namespace CleanArchitecture.Application.Queries.Tenants.GetAll;
|
||||
|
||||
public sealed record GetAllTenantsQuery() : IRequest<IEnumerable<TenantViewModel>>;
|
||||
public sealed record GetAllTenantsQuery : IRequest<IEnumerable<TenantViewModel>>;
|
@ -14,8 +14,8 @@ namespace CleanArchitecture.Application.Queries.Tenants.GetTenantById;
|
||||
public sealed class GetTenantByIdQueryHandler :
|
||||
IRequestHandler<GetTenantByIdQuery, TenantViewModel?>
|
||||
{
|
||||
private readonly ITenantRepository _tenantRepository;
|
||||
private readonly IMediatorHandler _bus;
|
||||
private readonly ITenantRepository _tenantRepository;
|
||||
|
||||
public GetTenantByIdQueryHandler(ITenantRepository tenantRepository, IMediatorHandler bus)
|
||||
{
|
||||
|
@ -8,11 +8,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.0" />
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3"/>
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0"/>
|
||||
<PackageReference Include="NSubstitute" Version="5.0.0"/>
|
||||
<PackageReference Include="xunit" Version="2.5.0"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@ -24,7 +24,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -8,15 +8,11 @@ namespace CleanArchitecture.Domain.Tests.CommandHandler.Tenant.CreateTenant;
|
||||
|
||||
public sealed class CreateTenantCommandTestFixture : CommandHandlerFixtureBase
|
||||
{
|
||||
public CreateTenantCommandHandler CommandHandler { get;}
|
||||
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
|
||||
public CreateTenantCommandTestFixture()
|
||||
{
|
||||
TenantRepository = Substitute.For<ITenantRepository>();
|
||||
|
||||
CommandHandler = new(
|
||||
CommandHandler = new CreateTenantCommandHandler(
|
||||
Bus,
|
||||
UnitOfWork,
|
||||
NotificationHandler,
|
||||
@ -24,6 +20,10 @@ public sealed class CreateTenantCommandTestFixture : CommandHandlerFixtureBase
|
||||
User);
|
||||
}
|
||||
|
||||
public CreateTenantCommandHandler CommandHandler { get; }
|
||||
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
|
||||
public void SetupUser()
|
||||
{
|
||||
User.GetUserRole().Returns(UserRole.User);
|
||||
|
@ -46,7 +46,7 @@ public sealed class CreateTenantCommandValidationTests :
|
||||
Guid? id = null,
|
||||
string? name = null)
|
||||
{
|
||||
return new(
|
||||
return new CreateTenantCommand(
|
||||
id ?? Guid.NewGuid(),
|
||||
name ?? "Test Tenant");
|
||||
}
|
||||
|
@ -7,17 +7,12 @@ namespace CleanArchitecture.Domain.Tests.CommandHandler.Tenant.DeleteTenant;
|
||||
|
||||
public sealed class DeleteTenantCommandTestFixture : CommandHandlerFixtureBase
|
||||
{
|
||||
public DeleteTenantCommandHandler CommandHandler { get;}
|
||||
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
private IUserRepository UserRepository { get; }
|
||||
|
||||
public DeleteTenantCommandTestFixture()
|
||||
{
|
||||
TenantRepository = Substitute.For<ITenantRepository>();
|
||||
UserRepository = Substitute.For<IUserRepository>();
|
||||
|
||||
CommandHandler = new(
|
||||
CommandHandler = new DeleteTenantCommandHandler(
|
||||
Bus,
|
||||
UnitOfWork,
|
||||
NotificationHandler,
|
||||
@ -26,6 +21,11 @@ public sealed class DeleteTenantCommandTestFixture : CommandHandlerFixtureBase
|
||||
User);
|
||||
}
|
||||
|
||||
public DeleteTenantCommandHandler CommandHandler { get; }
|
||||
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
private IUserRepository UserRepository { get; }
|
||||
|
||||
public Entities.Tenant SetupTenant()
|
||||
{
|
||||
var tenant = new Entities.Tenant(Guid.NewGuid(), "TestTenant");
|
||||
|
@ -33,6 +33,6 @@ public sealed class DeleteTenantCommandValidationTests :
|
||||
|
||||
private static DeleteTenantCommand CreateTestCommand(Guid? tenantId = null)
|
||||
{
|
||||
return new(tenantId ?? Guid.NewGuid());
|
||||
return new DeleteTenantCommand(tenantId ?? Guid.NewGuid());
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using CleanArchitecture.Domain.Commands.Tenants.UpdateTenant;
|
||||
using CleanArchitecture.Domain.Enums;
|
||||
using CleanArchitecture.Domain.Interfaces;
|
||||
using CleanArchitecture.Domain.Interfaces.Repositories;
|
||||
using NSubstitute;
|
||||
|
||||
@ -9,15 +8,11 @@ namespace CleanArchitecture.Domain.Tests.CommandHandler.Tenant.UpdateTenant;
|
||||
|
||||
public sealed class UpdateTenantCommandTestFixture : CommandHandlerFixtureBase
|
||||
{
|
||||
public UpdateTenantCommandHandler CommandHandler { get;}
|
||||
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
|
||||
public UpdateTenantCommandTestFixture()
|
||||
{
|
||||
TenantRepository = Substitute.For<ITenantRepository>();
|
||||
|
||||
CommandHandler = new(
|
||||
CommandHandler = new UpdateTenantCommandHandler(
|
||||
Bus,
|
||||
UnitOfWork,
|
||||
NotificationHandler,
|
||||
@ -25,6 +20,10 @@ public sealed class UpdateTenantCommandTestFixture : CommandHandlerFixtureBase
|
||||
User);
|
||||
}
|
||||
|
||||
public UpdateTenantCommandHandler CommandHandler { get; }
|
||||
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
|
||||
public void SetupUser()
|
||||
{
|
||||
User.GetUserRole().Returns(UserRole.User);
|
||||
|
@ -46,7 +46,7 @@ public sealed class UpdateTenantCommandValidationTests :
|
||||
Guid? id = null,
|
||||
string? name = null)
|
||||
{
|
||||
return new(
|
||||
return new UpdateTenantCommand(
|
||||
id ?? Guid.NewGuid(),
|
||||
name ?? "Test Tenant");
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public sealed class ChangePasswordCommandValidationTests :
|
||||
private static ChangePasswordCommand CreateTestCommand(
|
||||
string? password = null, string? newPassword = null)
|
||||
{
|
||||
return new(
|
||||
return new ChangePasswordCommand(
|
||||
password ?? "z8]tnayvd5FNLU9:]AQm",
|
||||
newPassword ?? "z8]tnayvd5FNLU9:]AQw");
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ public sealed class CreateUserCommandValidationTests :
|
||||
string? lastName = null,
|
||||
string? password = null)
|
||||
{
|
||||
return new(
|
||||
return new CreateUserCommand(
|
||||
userId ?? Guid.NewGuid(),
|
||||
tenantId ?? Guid.NewGuid(),
|
||||
email ?? "test@email.com",
|
||||
|
@ -33,6 +33,6 @@ public sealed class DeleteUserCommandValidationTests :
|
||||
|
||||
private static DeleteUserCommand CreateTestCommand(Guid? userId = null)
|
||||
{
|
||||
return new(userId ?? Guid.NewGuid());
|
||||
return new DeleteUserCommand(userId ?? Guid.NewGuid());
|
||||
}
|
||||
}
|
@ -125,7 +125,7 @@ public sealed class LoginUserCommandValidationTests :
|
||||
string? email = null,
|
||||
string? password = null)
|
||||
{
|
||||
return new(
|
||||
return new LoginUserCommand(
|
||||
email ?? "test@email.com",
|
||||
password ?? "Po=PF]PC6t.?8?ks)A6W");
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public sealed class UpdateUserCommandValidationTests :
|
||||
string? lastName = null,
|
||||
UserRole? role = null)
|
||||
{
|
||||
return new(
|
||||
return new UpdateUserCommand(
|
||||
userId ?? Guid.NewGuid(),
|
||||
email ?? "test@email.com",
|
||||
firstName ?? "test",
|
||||
|
@ -59,17 +59,20 @@ public sealed class ApiUser : IUser
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
var identity = _httpContextAccessor.HttpContext?.User.Identity;
|
||||
if (identity is null)
|
||||
{
|
||||
_name = string.Empty;
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(identity.Name))
|
||||
{
|
||||
_name = identity.Name;
|
||||
return identity.Name;
|
||||
}
|
||||
|
||||
var claim = _httpContextAccessor.HttpContext!.User.Claims
|
||||
.FirstOrDefault(c => string.Equals(c.Type, ClaimTypes.Name, StringComparison.OrdinalIgnoreCase))?
|
||||
.Value;
|
||||
|
@ -6,14 +6,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||
<PackageReference Include="FluentValidation" Version="11.7.1" />
|
||||
<PackageReference Include="MediatR" Version="12.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.32.1" />
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3"/>
|
||||
<PackageReference Include="FluentValidation" Version="11.7.1"/>
|
||||
<PackageReference Include="MediatR" Version="12.1.1"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1"/>
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.32.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -9,9 +9,9 @@ namespace CleanArchitecture.Domain.Commands;
|
||||
|
||||
public abstract class CommandHandlerBase
|
||||
{
|
||||
protected readonly IMediatorHandler Bus;
|
||||
private readonly DomainNotificationHandler _notifications;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
protected readonly IMediatorHandler Bus;
|
||||
|
||||
protected CommandHandlerBase(
|
||||
IMediatorHandler bus,
|
||||
|
@ -6,13 +6,13 @@ public sealed class CreateTenantCommand : CommandBase
|
||||
{
|
||||
private static readonly CreateTenantCommandValidation s_validation = new();
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public CreateTenantCommand(Guid tenantId, string name) : base(tenantId)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public override bool IsValid()
|
||||
{
|
||||
ValidationResult = s_validation.Validate(this);
|
||||
|
@ -15,8 +15,8 @@ public sealed class DeleteTenantCommandHandler : CommandHandlerBase,
|
||||
IRequestHandler<DeleteTenantCommand>
|
||||
{
|
||||
private readonly ITenantRepository _tenantRepository;
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IUser _user;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public DeleteTenantCommandHandler(
|
||||
IMediatorHandler bus,
|
||||
|
@ -6,13 +6,13 @@ public sealed class UpdateTenantCommand : CommandBase
|
||||
{
|
||||
private static readonly UpdateTenantCommandValidation s_validation = new();
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public UpdateTenantCommand(Guid tenantId, string name) : base(tenantId)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public override bool IsValid()
|
||||
{
|
||||
ValidationResult = s_validation.Validate(this);
|
||||
|
@ -15,9 +15,9 @@ namespace CleanArchitecture.Domain.Commands.Users.CreateUser;
|
||||
public sealed class CreateUserCommandHandler : CommandHandlerBase,
|
||||
IRequestHandler<CreateUserCommand>
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly ITenantRepository _tenantRepository;
|
||||
private readonly IUser _user;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public CreateUserCommandHandler(
|
||||
IMediatorHandler bus,
|
||||
|
@ -4,11 +4,6 @@ namespace CleanArchitecture.Domain.DomainEvents;
|
||||
|
||||
public class StoredDomainEvent : DomainEvent
|
||||
{
|
||||
public Guid Id { get; private set; }
|
||||
public string Data { get; private set; } = string.Empty;
|
||||
public string User { get; private set; } = string.Empty;
|
||||
public string CorrelationId { get; private set; } = string.Empty;
|
||||
|
||||
public StoredDomainEvent(
|
||||
DomainEvent domainEvent,
|
||||
string data,
|
||||
@ -24,5 +19,11 @@ public class StoredDomainEvent : DomainEvent
|
||||
|
||||
// EF Constructor
|
||||
protected StoredDomainEvent() : base(Guid.NewGuid())
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
public Guid Id { get; private set; }
|
||||
public string Data { get; private set; } = string.Empty;
|
||||
public string User { get; private set; } = string.Empty;
|
||||
public string CorrelationId { get; private set; } = string.Empty;
|
||||
}
|
@ -5,21 +5,16 @@ namespace CleanArchitecture.Domain.DomainNotifications;
|
||||
|
||||
public class StoredDomainNotification : DomainNotification
|
||||
{
|
||||
public Guid Id { get; private set; }
|
||||
public string SerializedData { get; private set; } = string.Empty;
|
||||
public string User { get; private set; } = string.Empty;
|
||||
public string CorrelationId { get; private set; } = string.Empty;
|
||||
|
||||
public StoredDomainNotification(
|
||||
DomainNotification domainNotification,
|
||||
string data,
|
||||
string user,
|
||||
string correlationId) : base(
|
||||
domainNotification.Key,
|
||||
domainNotification.Value,
|
||||
domainNotification.Code,
|
||||
null,
|
||||
domainNotification.AggregateId)
|
||||
domainNotification.Key,
|
||||
domainNotification.Value,
|
||||
domainNotification.Code,
|
||||
null,
|
||||
domainNotification.AggregateId)
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
User = user;
|
||||
@ -31,5 +26,11 @@ public class StoredDomainNotification : DomainNotification
|
||||
|
||||
// EF Constructor
|
||||
protected StoredDomainNotification() : base(string.Empty, string.Empty, string.Empty)
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
public Guid Id { get; private set; }
|
||||
public string SerializedData { get; private set; } = string.Empty;
|
||||
public string User { get; private set; } = string.Empty;
|
||||
public string CorrelationId { get; private set; } = string.Empty;
|
||||
}
|
@ -5,10 +5,6 @@ namespace CleanArchitecture.Domain.Entities;
|
||||
|
||||
public class Tenant : Entity
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
|
||||
public virtual ICollection<User> Users { get; private set; } = new HashSet<User>();
|
||||
|
||||
public Tenant(
|
||||
Guid id,
|
||||
string name) : base(id)
|
||||
@ -16,6 +12,10 @@ public class Tenant : Entity
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public string Name { get; private set; }
|
||||
|
||||
public virtual ICollection<User> Users { get; private set; } = new HashSet<User>();
|
||||
|
||||
public void SetName(string name)
|
||||
{
|
||||
Name = name;
|
||||
|
@ -1,22 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using CleanArchitecture.Domain.Enums;
|
||||
|
||||
namespace CleanArchitecture.Domain.Entities;
|
||||
|
||||
public class User : Entity
|
||||
{
|
||||
public string Email { get; private set; }
|
||||
public string FirstName { get; private set; }
|
||||
public string LastName { get; private set; }
|
||||
public string Password { get; private set; }
|
||||
public UserRole Role { get; private set; }
|
||||
|
||||
public string FullName => $"{FirstName}, {LastName}";
|
||||
|
||||
public Guid TenantId { get; private set; }
|
||||
public virtual Tenant Tenant { get; private set; } = null!;
|
||||
|
||||
public User(
|
||||
Guid id,
|
||||
Guid tenantId,
|
||||
@ -34,6 +22,17 @@ public class User : Entity
|
||||
Role = role;
|
||||
}
|
||||
|
||||
public string Email { get; private set; }
|
||||
public string FirstName { get; private set; }
|
||||
public string LastName { get; private set; }
|
||||
public string Password { get; private set; }
|
||||
public UserRole Role { get; private set; }
|
||||
|
||||
public string FullName => $"{FirstName}, {LastName}";
|
||||
|
||||
public Guid TenantId { get; private set; }
|
||||
public virtual Tenant Tenant { get; private set; } = null!;
|
||||
|
||||
public void SetEmail(string email)
|
||||
{
|
||||
Email = email;
|
||||
|
@ -5,10 +5,10 @@ namespace CleanArchitecture.Domain.Events.Tenant;
|
||||
|
||||
public sealed class TenantCreatedEvent : DomainEvent
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public TenantCreatedEvent(Guid tenantId, string name) : base(tenantId)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
}
|
@ -5,10 +5,10 @@ namespace CleanArchitecture.Domain.Events.Tenant;
|
||||
|
||||
public sealed class TenantUpdatedEvent : DomainEvent
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public TenantUpdatedEvent(Guid tenantId, string name) : base(tenantId)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
}
|
@ -8,10 +8,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0"/>
|
||||
<PackageReference Include="NSubstitute" Version="5.0.0"/>
|
||||
<PackageReference Include="xunit" Version="2.5.0"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@ -23,7 +23,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CleanArchitecture.Infrastructure\CleanArchitecture.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Infrastructure\CleanArchitecture.Infrastructure.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -6,19 +6,19 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MediatR" Version="12.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10" />
|
||||
<PackageReference Include="MediatR" Version="12.1.1"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.10"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.10"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using CleanArchitecture.Domain.Constants;
|
||||
using CleanArchitecture.Domain.Entities;
|
||||
using CleanArchitecture.Domain.Enums;
|
||||
|
@ -9,9 +9,9 @@ namespace CleanArchitecture.Infrastructure.EventSourcing;
|
||||
|
||||
public sealed class DomainEventStore : IDomainEventStore
|
||||
{
|
||||
private readonly EventStoreDbContext _eventStoreDbContext;
|
||||
private readonly DomainNotificationStoreDbContext _domainNotificationStoreDbContext;
|
||||
private readonly IEventStoreContext _context;
|
||||
private readonly DomainNotificationStoreDbContext _domainNotificationStoreDbContext;
|
||||
private readonly EventStoreDbContext _eventStoreDbContext;
|
||||
|
||||
public DomainEventStore(
|
||||
EventStoreDbContext eventStoreDbContext,
|
||||
|
@ -14,7 +14,8 @@ public sealed class EventStoreContext : IEventStoreContext
|
||||
_user = user;
|
||||
|
||||
if (httpContextAccessor?.HttpContext is null ||
|
||||
!httpContextAccessor.HttpContext.Request.Headers.TryGetValue("X-CLEAN-ARCHITECTURE-CORRELATION-ID", out var id))
|
||||
!httpContextAccessor.HttpContext.Request.Headers.TryGetValue("X-CLEAN-ARCHITECTURE-CORRELATION-ID",
|
||||
out var id))
|
||||
{
|
||||
_correlationId = $"internal - {Guid.NewGuid()}";
|
||||
}
|
||||
@ -24,7 +25,13 @@ public sealed class EventStoreContext : IEventStoreContext
|
||||
}
|
||||
}
|
||||
|
||||
public string GetCorrelationId() => _correlationId;
|
||||
public string GetCorrelationId()
|
||||
{
|
||||
return _correlationId;
|
||||
}
|
||||
|
||||
public string GetUserEmail() => _user?.GetUserEmail() ?? string.Empty;
|
||||
public string GetUserEmail()
|
||||
{
|
||||
return _user?.GetUserEmail() ?? string.Empty;
|
||||
}
|
||||
}
|
@ -16,18 +16,18 @@ public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddInfrastructure(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration,
|
||||
string migrationsAssemblyName,
|
||||
string connectionStringName = "DefaultConnection")
|
||||
IConfiguration configuration,
|
||||
string migrationsAssemblyName,
|
||||
string connectionStringName = "DefaultConnection")
|
||||
{
|
||||
// Add event store db context
|
||||
services.AddDbContext<EventStoreDbContext>(
|
||||
options =>
|
||||
{
|
||||
options.UseSqlServer(
|
||||
configuration.GetConnectionString(connectionStringName),
|
||||
b => b.MigrationsAssembly(migrationsAssemblyName));
|
||||
});
|
||||
options =>
|
||||
{
|
||||
options.UseSqlServer(
|
||||
configuration.GetConnectionString(connectionStringName),
|
||||
b => b.MigrationsAssembly(migrationsAssemblyName));
|
||||
});
|
||||
|
||||
services.AddDbContext<DomainNotificationStoreDbContext>(
|
||||
options =>
|
||||
|
@ -5,6 +5,12 @@
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[assembly: SuppressMessage("Style", "IDE0161:Convert to file-scoped namespace", Justification = "<Pending>", Scope = "namespace", Target = "~N:CleanArchitecture.Infrastructure.Migrations")]
|
||||
[assembly: SuppressMessage("Style", "IDE0161:Convert to file-scoped namespace", Justification = "<Pending>", Scope = "namespace", Target = "~N:CleanArchitecture.Infrastructure.Migrations.EventStoreDb")]
|
||||
[assembly: SuppressMessage("Style", "IDE0161:Convert to file-scoped namespace", Justification = "<Pending>", Scope = "namespace", Target = "~N:CleanArchitecture.Infrastructure.Migrations.DomainNotificationStoreDb")]
|
||||
[assembly:
|
||||
SuppressMessage("Style", "IDE0161:Convert to file-scoped namespace", Justification = "<Pending>",
|
||||
Scope = "namespace", Target = "~N:CleanArchitecture.Infrastructure.Migrations")]
|
||||
[assembly:
|
||||
SuppressMessage("Style", "IDE0161:Convert to file-scoped namespace", Justification = "<Pending>",
|
||||
Scope = "namespace", Target = "~N:CleanArchitecture.Infrastructure.Migrations.EventStoreDb")]
|
||||
[assembly:
|
||||
SuppressMessage("Style", "IDE0161:Convert to file-scoped namespace", Justification = "<Pending>",
|
||||
Scope = "namespace", Target = "~N:CleanArchitecture.Infrastructure.Migrations.DomainNotificationStoreDb")]
|
@ -8,8 +8,8 @@ namespace CleanArchitecture.Infrastructure;
|
||||
|
||||
public sealed class InMemoryBus : IMediatorHandler
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IDomainEventStore _domainEventStore;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public InMemoryBus(
|
||||
IMediator mediator,
|
||||
|
@ -1,43 +1,39 @@
|
||||
using System;
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
namespace CleanArchitecture.Infrastructure.Migrations.DomainNotificationStoreDb;
|
||||
|
||||
namespace CleanArchitecture.Infrastructure.Migrations.DomainNotificationStoreDb
|
||||
/// <inheritdoc />
|
||||
public partial class AddDomainNotificationStore : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddDomainNotificationStore : Migration
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "StoredDomainNotifications",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
Data = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
User = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
CorrelationId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
AggregateId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
MessageType = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
Timestamp = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Key = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
Value = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: false),
|
||||
Code = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
Version = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_StoredDomainNotifications", x => x.Id);
|
||||
});
|
||||
}
|
||||
migrationBuilder.CreateTable(
|
||||
"StoredDomainNotifications",
|
||||
table => new
|
||||
{
|
||||
Id = table.Column<Guid>("uniqueidentifier", nullable: false),
|
||||
Data = table.Column<string>("nvarchar(max)", nullable: false),
|
||||
User = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||
CorrelationId = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||
AggregateId = table.Column<Guid>("uniqueidentifier", nullable: false),
|
||||
MessageType = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||
Timestamp = table.Column<DateTime>("datetime2", nullable: false),
|
||||
Key = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||
Value = table.Column<string>("nvarchar(1024)", maxLength: 1024, nullable: false),
|
||||
Code = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||
Version = table.Column<int>("int", nullable: false)
|
||||
},
|
||||
constraints: table => { table.PrimaryKey("PK_StoredDomainNotifications", x => x.Id); });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "StoredDomainNotifications");
|
||||
}
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
"StoredDomainNotifications");
|
||||
}
|
||||
}
|
@ -1,39 +1,35 @@
|
||||
using System;
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
namespace CleanArchitecture.Infrastructure.Migrations.EventStoreDb;
|
||||
|
||||
namespace CleanArchitecture.Infrastructure.Migrations.EventStoreDb
|
||||
/// <inheritdoc />
|
||||
public partial class AddEventStore : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddEventStore : Migration
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "StoredDomainEvents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
Data = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
User = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
CorrelationId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
AggregateId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
Action = table.Column<string>(type: "varchar(100)", nullable: false),
|
||||
CreationDate = table.Column<DateTime>(type: "datetime2", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_StoredDomainEvents", x => x.Id);
|
||||
});
|
||||
}
|
||||
migrationBuilder.CreateTable(
|
||||
"StoredDomainEvents",
|
||||
table => new
|
||||
{
|
||||
Id = table.Column<Guid>("uniqueidentifier", nullable: false),
|
||||
Data = table.Column<string>("nvarchar(max)", nullable: false),
|
||||
User = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||
CorrelationId = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||
AggregateId = table.Column<Guid>("uniqueidentifier", nullable: false),
|
||||
Action = table.Column<string>("varchar(100)", nullable: false),
|
||||
CreationDate = table.Column<DateTime>("datetime2", nullable: false)
|
||||
},
|
||||
constraints: table => { table.PrimaryKey("PK_StoredDomainEvents", x => x.Id); });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "StoredDomainEvents");
|
||||
}
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
"StoredDomainEvents");
|
||||
}
|
||||
}
|
@ -8,14 +8,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.10" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="7.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.10" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.0" />
|
||||
<PackageReference Include="Xunit.Priority" Version="1.1.6" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.10"/>
|
||||
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="7.0.10"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.10"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.10"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0"/>
|
||||
<PackageReference Include="xunit" Version="2.5.0"/>
|
||||
<PackageReference Include="Xunit.Priority" Version="1.1.6"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@ -27,8 +27,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CleanArchitecture.Api\CleanArchitecture.Api.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Infrastructure\CleanArchitecture.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Api\CleanArchitecture.Api.csproj"/>
|
||||
<ProjectReference Include="..\CleanArchitecture.Infrastructure\CleanArchitecture.Infrastructure.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using CleanArchitecture.Application.ViewModels.Users;
|
||||
|
@ -7,9 +7,6 @@ namespace CleanArchitecture.IntegrationTests.Fixtures.gRPC;
|
||||
|
||||
public sealed class GetTenantsByIdsTestFixture : TestFixtureBase
|
||||
{
|
||||
public GrpcChannel GrpcChannel { get; }
|
||||
public Guid CreatedTenantId { get; } = Guid.NewGuid();
|
||||
|
||||
public GetTenantsByIdsTestFixture()
|
||||
{
|
||||
GrpcChannel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions
|
||||
@ -18,6 +15,9 @@ public sealed class GetTenantsByIdsTestFixture : TestFixtureBase
|
||||
});
|
||||
}
|
||||
|
||||
public GrpcChannel GrpcChannel { get; }
|
||||
public Guid CreatedTenantId { get; } = Guid.NewGuid();
|
||||
|
||||
protected override void SeedTestData(ApplicationDbContext context)
|
||||
{
|
||||
base.SeedTestData(context);
|
||||
@ -30,7 +30,7 @@ public sealed class GetTenantsByIdsTestFixture : TestFixtureBase
|
||||
|
||||
public Tenant CreateTenant()
|
||||
{
|
||||
return new(
|
||||
return new Tenant(
|
||||
CreatedTenantId,
|
||||
"Test Tenant");
|
||||
}
|
||||
|
@ -9,9 +9,6 @@ namespace CleanArchitecture.IntegrationTests.Fixtures.gRPC;
|
||||
|
||||
public sealed class GetUsersByIdsTestFixture : TestFixtureBase
|
||||
{
|
||||
public GrpcChannel GrpcChannel { get; }
|
||||
public Guid CreatedUserId { get; } = Guid.NewGuid();
|
||||
|
||||
public GetUsersByIdsTestFixture()
|
||||
{
|
||||
GrpcChannel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions
|
||||
@ -20,6 +17,9 @@ public sealed class GetUsersByIdsTestFixture : TestFixtureBase
|
||||
});
|
||||
}
|
||||
|
||||
public GrpcChannel GrpcChannel { get; }
|
||||
public Guid CreatedUserId { get; } = Guid.NewGuid();
|
||||
|
||||
protected override void SeedTestData(ApplicationDbContext context)
|
||||
{
|
||||
base.SeedTestData(context);
|
||||
|
@ -47,19 +47,19 @@ public sealed class CleanArchitectureWebApplicationFactory : WebApplicationFacto
|
||||
services.SetupTestDatabase<EventStoreDbContext>(_connection);
|
||||
services.SetupTestDatabase<DomainNotificationStoreDbContext>(_connection);
|
||||
|
||||
ServiceProvider sp = services.BuildServiceProvider();
|
||||
var sp = services.BuildServiceProvider();
|
||||
|
||||
using IServiceScope scope = sp.CreateScope();
|
||||
IServiceProvider scopedServices = scope.ServiceProvider;
|
||||
using var scope = sp.CreateScope();
|
||||
var scopedServices = scope.ServiceProvider;
|
||||
|
||||
ApplicationDbContext applicationDbContext = scopedServices.GetRequiredService<ApplicationDbContext>();
|
||||
EventStoreDbContext storeDbContext = scopedServices.GetRequiredService<EventStoreDbContext>();
|
||||
DomainNotificationStoreDbContext domainStoreDbContext = scopedServices.GetRequiredService<DomainNotificationStoreDbContext>();
|
||||
var applicationDbContext = scopedServices.GetRequiredService<ApplicationDbContext>();
|
||||
var storeDbContext = scopedServices.GetRequiredService<EventStoreDbContext>();
|
||||
var domainStoreDbContext = scopedServices.GetRequiredService<DomainNotificationStoreDbContext>();
|
||||
|
||||
applicationDbContext.EnsureMigrationsApplied();
|
||||
|
||||
var creator2 = (RelationalDatabaseCreator)storeDbContext.Database
|
||||
.GetService<IRelationalDatabaseCreator>();
|
||||
.GetService<IRelationalDatabaseCreator>();
|
||||
creator2.CreateTables();
|
||||
|
||||
var creator3 = (RelationalDatabaseCreator)domainStoreDbContext
|
||||
|
@ -6,16 +6,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Protobuf Include="Users\Models.proto" GrpcServices="Both" />
|
||||
<Protobuf Include="Users\UsersApi.proto" GrpcServices="Both" />
|
||||
<Protobuf Include="Tenants\Models.proto" GrpcServices="Both" />
|
||||
<Protobuf Include="Tenants\TenantsApi.proto" GrpcServices="Both" />
|
||||
<Protobuf Include="Users\Models.proto" GrpcServices="Both"/>
|
||||
<Protobuf Include="Users\UsersApi.proto" GrpcServices="Both"/>
|
||||
<Protobuf Include="Tenants\Models.proto" GrpcServices="Both"/>
|
||||
<Protobuf Include="Tenants\TenantsApi.proto" GrpcServices="Both"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.24.0" />
|
||||
<PackageReference Include="Google.Protobuf.Tools" Version="3.24.0" />
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.55.0" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.24.0"/>
|
||||
<PackageReference Include="Google.Protobuf.Tools" Version="3.24.0"/>
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.55.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,9 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
@ -8,11 +8,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
|
||||
<PackageReference Include="MockQueryable.NSubstitute" Version="7.0.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0"/>
|
||||
<PackageReference Include="MockQueryable.NSubstitute" Version="7.0.0"/>
|
||||
<PackageReference Include="NSubstitute" Version="5.0.0"/>
|
||||
<PackageReference Include="xunit" Version="2.5.0"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@ -24,9 +24,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CleanArchitecture.Application\CleanArchitecture.Application.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.gRPC\CleanArchitecture.gRPC.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Application\CleanArchitecture.Application.csproj"/>
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj"/>
|
||||
<ProjectReference Include="..\CleanArchitecture.gRPC\CleanArchitecture.gRPC.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -10,24 +10,24 @@ namespace CleanArchitecture.gRPC.Tests.Fixtures;
|
||||
|
||||
public sealed class TenantTestFixture
|
||||
{
|
||||
public TenantsApiImplementation TenantsApiImplementation { get; }
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
|
||||
public IEnumerable<Tenant> ExistingTenants { get; }
|
||||
|
||||
public TenantTestFixture()
|
||||
{
|
||||
TenantRepository = Substitute.For<ITenantRepository>();
|
||||
|
||||
ExistingTenants = new List<Tenant>
|
||||
{
|
||||
new Tenant(Guid.NewGuid(), "Tenant 1"),
|
||||
new Tenant(Guid.NewGuid(), "Tenant 2"),
|
||||
new Tenant(Guid.NewGuid(), "Tenant 3"),
|
||||
new(Guid.NewGuid(), "Tenant 1"),
|
||||
new(Guid.NewGuid(), "Tenant 2"),
|
||||
new(Guid.NewGuid(), "Tenant 3")
|
||||
};
|
||||
|
||||
TenantRepository.GetAllNoTracking().Returns(ExistingTenants.BuildMock());
|
||||
|
||||
TenantsApiImplementation = new(TenantRepository);
|
||||
TenantsApiImplementation = new TenantsApiImplementation(TenantRepository);
|
||||
}
|
||||
|
||||
public TenantsApiImplementation TenantsApiImplementation { get; }
|
||||
private ITenantRepository TenantRepository { get; }
|
||||
|
||||
public IEnumerable<Tenant> ExistingTenants { get; }
|
||||
}
|
@ -4,18 +4,15 @@ namespace CleanArchitecture.gRPC;
|
||||
|
||||
public sealed class CleanArchitecture : ICleanArchitecture
|
||||
{
|
||||
private readonly IUsersContext _users;
|
||||
private readonly ITenantsContext _tenants;
|
||||
|
||||
public IUsersContext Users => _users;
|
||||
public ITenantsContext Tenants => _tenants;
|
||||
|
||||
public CleanArchitecture(
|
||||
IUsersContext users,
|
||||
ITenantsContext tenants)
|
||||
{
|
||||
_users = users;
|
||||
_tenants = tenants;
|
||||
|
||||
Users = users;
|
||||
Tenants = tenants;
|
||||
}
|
||||
|
||||
public IUsersContext Users { get; }
|
||||
|
||||
public ITenantsContext Tenants { get; }
|
||||
}
|
@ -6,9 +6,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Proto\CleanArchitecture.Proto.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Shared\CleanArchitecture.Shared.csproj" />
|
||||
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj"/>
|
||||
<ProjectReference Include="..\CleanArchitecture.Proto\CleanArchitecture.Proto.csproj"/>
|
||||
<ProjectReference Include="..\CleanArchitecture.Shared\CleanArchitecture.Shared.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user