mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-08-22 19:28:34 +00:00
chore: Code Cleanup
This commit is contained in:
parent
a3152580a2
commit
61bcab6d77
@ -62,7 +62,10 @@ public static class ServiceCollectionExtension
|
|||||||
services.AddAuthentication(
|
services.AddAuthentication(
|
||||||
options => { options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; })
|
options => { options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; })
|
||||||
.AddJwtBearer(
|
.AddJwtBearer(
|
||||||
jwtOptions => { jwtOptions.TokenValidationParameters = CreateTokenValidationParameters(configuration); });
|
jwtOptions =>
|
||||||
|
{
|
||||||
|
jwtOptions.TokenValidationParameters = CreateTokenValidationParameters(configuration);
|
||||||
|
});
|
||||||
|
|
||||||
services
|
services
|
||||||
.AddOptions<TokenSettings>()
|
.AddOptions<TokenSettings>()
|
||||||
|
@ -4,9 +4,7 @@ namespace CleanArchitecture.Api.Models;
|
|||||||
|
|
||||||
public sealed class DetailedError
|
public sealed class DetailedError
|
||||||
{
|
{
|
||||||
[JsonPropertyName("code")]
|
[JsonPropertyName("code")] public string Code { get; init; } = string.Empty;
|
||||||
public string Code { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
[JsonPropertyName("data")]
|
[JsonPropertyName("data")] public object? Data { get; init; }
|
||||||
public object? Data { get; init; }
|
|
||||||
}
|
}
|
@ -6,15 +6,12 @@ namespace CleanArchitecture.Api.Models;
|
|||||||
|
|
||||||
public sealed class ResponseMessage<T>
|
public sealed class ResponseMessage<T>
|
||||||
{
|
{
|
||||||
[JsonPropertyName("success")]
|
[JsonPropertyName("success")] public bool Success { get; init; }
|
||||||
public bool Success { get; init; }
|
|
||||||
|
|
||||||
[JsonPropertyName("errors")]
|
[JsonPropertyName("errors")] public IEnumerable<string>? Errors { get; init; }
|
||||||
public IEnumerable<string>? Errors { get; init; }
|
|
||||||
|
|
||||||
[JsonPropertyName("detailedErrors")]
|
[JsonPropertyName("detailedErrors")]
|
||||||
public IEnumerable<DetailedError> DetailedErrors { get; init; } = Enumerable.Empty<DetailedError>();
|
public IEnumerable<DetailedError> DetailedErrors { get; init; } = Enumerable.Empty<DetailedError>();
|
||||||
|
|
||||||
[JsonPropertyName("data")]
|
[JsonPropertyName("data")] public T? Data { get; init; }
|
||||||
public T? Data { get; init; }
|
|
||||||
}
|
}
|
@ -61,9 +61,9 @@ var app = builder.Build();
|
|||||||
using (var scope = app.Services.CreateScope())
|
using (var scope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
var services = scope.ServiceProvider;
|
var services = scope.ServiceProvider;
|
||||||
ApplicationDbContext appDbContext = services.GetRequiredService<ApplicationDbContext>();
|
var appDbContext = services.GetRequiredService<ApplicationDbContext>();
|
||||||
EventStoreDbContext storeDbContext = services.GetRequiredService<EventStoreDbContext>();
|
var storeDbContext = services.GetRequiredService<EventStoreDbContext>();
|
||||||
DomainNotificationStoreDbContext domainStoreDbContext = services.GetRequiredService<DomainNotificationStoreDbContext>();
|
var domainStoreDbContext = services.GetRequiredService<DomainNotificationStoreDbContext>();
|
||||||
|
|
||||||
appDbContext.EnsureMigrationsApplied();
|
appDbContext.EnsureMigrationsApplied();
|
||||||
|
|
||||||
|
@ -10,16 +10,16 @@ namespace CleanArchitecture.Application.Tests.Fixtures.Queries.Tenants;
|
|||||||
|
|
||||||
public sealed class GetAllTenantsTestFixture : QueryHandlerBaseFixture
|
public sealed class GetAllTenantsTestFixture : QueryHandlerBaseFixture
|
||||||
{
|
{
|
||||||
public GetAllTenantsQueryHandler QueryHandler { get; }
|
|
||||||
private ITenantRepository TenantRepository { get; }
|
|
||||||
|
|
||||||
public GetAllTenantsTestFixture()
|
public GetAllTenantsTestFixture()
|
||||||
{
|
{
|
||||||
TenantRepository = Substitute.For<ITenantRepository>();
|
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)
|
public Tenant SetupTenant(bool deleted = false)
|
||||||
{
|
{
|
||||||
var tenant = new Tenant(Guid.NewGuid(), "Tenant 1");
|
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 sealed class GetTenantByIdTestFixture : QueryHandlerBaseFixture
|
||||||
{
|
{
|
||||||
public GetTenantByIdQueryHandler QueryHandler { get; }
|
|
||||||
private ITenantRepository TenantRepository { get; }
|
|
||||||
|
|
||||||
public GetTenantByIdTestFixture()
|
public GetTenantByIdTestFixture()
|
||||||
{
|
{
|
||||||
TenantRepository = Substitute.For<ITenantRepository>();
|
TenantRepository = Substitute.For<ITenantRepository>();
|
||||||
|
|
||||||
QueryHandler = new(
|
QueryHandler = new GetTenantByIdQueryHandler(
|
||||||
TenantRepository,
|
TenantRepository,
|
||||||
Bus);
|
Bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GetTenantByIdQueryHandler QueryHandler { get; }
|
||||||
|
private ITenantRepository TenantRepository { get; }
|
||||||
|
|
||||||
public Tenant SetupTenant(bool deleted = false)
|
public Tenant SetupTenant(bool deleted = false)
|
||||||
{
|
{
|
||||||
var tenant = new Tenant(Guid.NewGuid(), "Tenant 1");
|
var tenant = new Tenant(Guid.NewGuid(), "Tenant 1");
|
||||||
|
@ -15,5 +15,4 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -30,7 +30,8 @@ public static class ServiceCollectionExtension
|
|||||||
|
|
||||||
// Tenant
|
// Tenant
|
||||||
services.AddScoped<IRequestHandler<GetTenantByIdQuery, TenantViewModel?>, GetTenantByIdQueryHandler>();
|
services.AddScoped<IRequestHandler<GetTenantByIdQuery, TenantViewModel?>, GetTenantByIdQueryHandler>();
|
||||||
services.AddScoped<IRequestHandler<GetAllTenantsQuery, IEnumerable<TenantViewModel>>, GetAllTenantsQueryHandler>();
|
services
|
||||||
|
.AddScoped<IRequestHandler<GetAllTenantsQuery, IEnumerable<TenantViewModel>>, GetAllTenantsQueryHandler>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,4 @@ using MediatR;
|
|||||||
|
|
||||||
namespace CleanArchitecture.Application.Queries.Tenants.GetAll;
|
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 :
|
public sealed class GetTenantByIdQueryHandler :
|
||||||
IRequestHandler<GetTenantByIdQuery, TenantViewModel?>
|
IRequestHandler<GetTenantByIdQuery, TenantViewModel?>
|
||||||
{
|
{
|
||||||
private readonly ITenantRepository _tenantRepository;
|
|
||||||
private readonly IMediatorHandler _bus;
|
private readonly IMediatorHandler _bus;
|
||||||
|
private readonly ITenantRepository _tenantRepository;
|
||||||
|
|
||||||
public GetTenantByIdQueryHandler(ITenantRepository tenantRepository, IMediatorHandler bus)
|
public GetTenantByIdQueryHandler(ITenantRepository tenantRepository, IMediatorHandler bus)
|
||||||
{
|
{
|
||||||
|
@ -8,15 +8,11 @@ namespace CleanArchitecture.Domain.Tests.CommandHandler.Tenant.CreateTenant;
|
|||||||
|
|
||||||
public sealed class CreateTenantCommandTestFixture : CommandHandlerFixtureBase
|
public sealed class CreateTenantCommandTestFixture : CommandHandlerFixtureBase
|
||||||
{
|
{
|
||||||
public CreateTenantCommandHandler CommandHandler { get;}
|
|
||||||
|
|
||||||
private ITenantRepository TenantRepository { get; }
|
|
||||||
|
|
||||||
public CreateTenantCommandTestFixture()
|
public CreateTenantCommandTestFixture()
|
||||||
{
|
{
|
||||||
TenantRepository = Substitute.For<ITenantRepository>();
|
TenantRepository = Substitute.For<ITenantRepository>();
|
||||||
|
|
||||||
CommandHandler = new(
|
CommandHandler = new CreateTenantCommandHandler(
|
||||||
Bus,
|
Bus,
|
||||||
UnitOfWork,
|
UnitOfWork,
|
||||||
NotificationHandler,
|
NotificationHandler,
|
||||||
@ -24,6 +20,10 @@ public sealed class CreateTenantCommandTestFixture : CommandHandlerFixtureBase
|
|||||||
User);
|
User);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CreateTenantCommandHandler CommandHandler { get; }
|
||||||
|
|
||||||
|
private ITenantRepository TenantRepository { get; }
|
||||||
|
|
||||||
public void SetupUser()
|
public void SetupUser()
|
||||||
{
|
{
|
||||||
User.GetUserRole().Returns(UserRole.User);
|
User.GetUserRole().Returns(UserRole.User);
|
||||||
|
@ -46,7 +46,7 @@ public sealed class CreateTenantCommandValidationTests :
|
|||||||
Guid? id = null,
|
Guid? id = null,
|
||||||
string? name = null)
|
string? name = null)
|
||||||
{
|
{
|
||||||
return new(
|
return new CreateTenantCommand(
|
||||||
id ?? Guid.NewGuid(),
|
id ?? Guid.NewGuid(),
|
||||||
name ?? "Test Tenant");
|
name ?? "Test Tenant");
|
||||||
}
|
}
|
||||||
|
@ -7,17 +7,12 @@ namespace CleanArchitecture.Domain.Tests.CommandHandler.Tenant.DeleteTenant;
|
|||||||
|
|
||||||
public sealed class DeleteTenantCommandTestFixture : CommandHandlerFixtureBase
|
public sealed class DeleteTenantCommandTestFixture : CommandHandlerFixtureBase
|
||||||
{
|
{
|
||||||
public DeleteTenantCommandHandler CommandHandler { get;}
|
|
||||||
|
|
||||||
private ITenantRepository TenantRepository { get; }
|
|
||||||
private IUserRepository UserRepository { get; }
|
|
||||||
|
|
||||||
public DeleteTenantCommandTestFixture()
|
public DeleteTenantCommandTestFixture()
|
||||||
{
|
{
|
||||||
TenantRepository = Substitute.For<ITenantRepository>();
|
TenantRepository = Substitute.For<ITenantRepository>();
|
||||||
UserRepository = Substitute.For<IUserRepository>();
|
UserRepository = Substitute.For<IUserRepository>();
|
||||||
|
|
||||||
CommandHandler = new(
|
CommandHandler = new DeleteTenantCommandHandler(
|
||||||
Bus,
|
Bus,
|
||||||
UnitOfWork,
|
UnitOfWork,
|
||||||
NotificationHandler,
|
NotificationHandler,
|
||||||
@ -26,6 +21,11 @@ public sealed class DeleteTenantCommandTestFixture : CommandHandlerFixtureBase
|
|||||||
User);
|
User);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DeleteTenantCommandHandler CommandHandler { get; }
|
||||||
|
|
||||||
|
private ITenantRepository TenantRepository { get; }
|
||||||
|
private IUserRepository UserRepository { get; }
|
||||||
|
|
||||||
public Entities.Tenant SetupTenant()
|
public Entities.Tenant SetupTenant()
|
||||||
{
|
{
|
||||||
var tenant = new Entities.Tenant(Guid.NewGuid(), "TestTenant");
|
var tenant = new Entities.Tenant(Guid.NewGuid(), "TestTenant");
|
||||||
|
@ -33,6 +33,6 @@ public sealed class DeleteTenantCommandValidationTests :
|
|||||||
|
|
||||||
private static DeleteTenantCommand CreateTestCommand(Guid? tenantId = null)
|
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 System;
|
||||||
using CleanArchitecture.Domain.Commands.Tenants.UpdateTenant;
|
using CleanArchitecture.Domain.Commands.Tenants.UpdateTenant;
|
||||||
using CleanArchitecture.Domain.Enums;
|
using CleanArchitecture.Domain.Enums;
|
||||||
using CleanArchitecture.Domain.Interfaces;
|
|
||||||
using CleanArchitecture.Domain.Interfaces.Repositories;
|
using CleanArchitecture.Domain.Interfaces.Repositories;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
|
|
||||||
@ -9,15 +8,11 @@ namespace CleanArchitecture.Domain.Tests.CommandHandler.Tenant.UpdateTenant;
|
|||||||
|
|
||||||
public sealed class UpdateTenantCommandTestFixture : CommandHandlerFixtureBase
|
public sealed class UpdateTenantCommandTestFixture : CommandHandlerFixtureBase
|
||||||
{
|
{
|
||||||
public UpdateTenantCommandHandler CommandHandler { get;}
|
|
||||||
|
|
||||||
private ITenantRepository TenantRepository { get; }
|
|
||||||
|
|
||||||
public UpdateTenantCommandTestFixture()
|
public UpdateTenantCommandTestFixture()
|
||||||
{
|
{
|
||||||
TenantRepository = Substitute.For<ITenantRepository>();
|
TenantRepository = Substitute.For<ITenantRepository>();
|
||||||
|
|
||||||
CommandHandler = new(
|
CommandHandler = new UpdateTenantCommandHandler(
|
||||||
Bus,
|
Bus,
|
||||||
UnitOfWork,
|
UnitOfWork,
|
||||||
NotificationHandler,
|
NotificationHandler,
|
||||||
@ -25,6 +20,10 @@ public sealed class UpdateTenantCommandTestFixture : CommandHandlerFixtureBase
|
|||||||
User);
|
User);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UpdateTenantCommandHandler CommandHandler { get; }
|
||||||
|
|
||||||
|
private ITenantRepository TenantRepository { get; }
|
||||||
|
|
||||||
public void SetupUser()
|
public void SetupUser()
|
||||||
{
|
{
|
||||||
User.GetUserRole().Returns(UserRole.User);
|
User.GetUserRole().Returns(UserRole.User);
|
||||||
|
@ -46,7 +46,7 @@ public sealed class UpdateTenantCommandValidationTests :
|
|||||||
Guid? id = null,
|
Guid? id = null,
|
||||||
string? name = null)
|
string? name = null)
|
||||||
{
|
{
|
||||||
return new(
|
return new UpdateTenantCommand(
|
||||||
id ?? Guid.NewGuid(),
|
id ?? Guid.NewGuid(),
|
||||||
name ?? "Test Tenant");
|
name ?? "Test Tenant");
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ public sealed class ChangePasswordCommandValidationTests :
|
|||||||
private static ChangePasswordCommand CreateTestCommand(
|
private static ChangePasswordCommand CreateTestCommand(
|
||||||
string? password = null, string? newPassword = null)
|
string? password = null, string? newPassword = null)
|
||||||
{
|
{
|
||||||
return new(
|
return new ChangePasswordCommand(
|
||||||
password ?? "z8]tnayvd5FNLU9:]AQm",
|
password ?? "z8]tnayvd5FNLU9:]AQm",
|
||||||
newPassword ?? "z8]tnayvd5FNLU9:]AQw");
|
newPassword ?? "z8]tnayvd5FNLU9:]AQw");
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ public sealed class CreateUserCommandValidationTests :
|
|||||||
string? lastName = null,
|
string? lastName = null,
|
||||||
string? password = null)
|
string? password = null)
|
||||||
{
|
{
|
||||||
return new(
|
return new CreateUserCommand(
|
||||||
userId ?? Guid.NewGuid(),
|
userId ?? Guid.NewGuid(),
|
||||||
tenantId ?? Guid.NewGuid(),
|
tenantId ?? Guid.NewGuid(),
|
||||||
email ?? "test@email.com",
|
email ?? "test@email.com",
|
||||||
|
@ -33,6 +33,6 @@ public sealed class DeleteUserCommandValidationTests :
|
|||||||
|
|
||||||
private static DeleteUserCommand CreateTestCommand(Guid? userId = null)
|
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? email = null,
|
||||||
string? password = null)
|
string? password = null)
|
||||||
{
|
{
|
||||||
return new(
|
return new LoginUserCommand(
|
||||||
email ?? "test@email.com",
|
email ?? "test@email.com",
|
||||||
password ?? "Po=PF]PC6t.?8?ks)A6W");
|
password ?? "Po=PF]PC6t.?8?ks)A6W");
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ public sealed class UpdateUserCommandValidationTests :
|
|||||||
string? lastName = null,
|
string? lastName = null,
|
||||||
UserRole? role = null)
|
UserRole? role = null)
|
||||||
{
|
{
|
||||||
return new(
|
return new UpdateUserCommand(
|
||||||
userId ?? Guid.NewGuid(),
|
userId ?? Guid.NewGuid(),
|
||||||
email ?? "test@email.com",
|
email ?? "test@email.com",
|
||||||
firstName ?? "test",
|
firstName ?? "test",
|
||||||
|
@ -59,17 +59,20 @@ public sealed class ApiUser : IUser
|
|||||||
{
|
{
|
||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
|
|
||||||
var identity = _httpContextAccessor.HttpContext?.User.Identity;
|
var identity = _httpContextAccessor.HttpContext?.User.Identity;
|
||||||
if (identity is null)
|
if (identity is null)
|
||||||
{
|
{
|
||||||
_name = string.Empty;
|
_name = string.Empty;
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(identity.Name))
|
if (!string.IsNullOrWhiteSpace(identity.Name))
|
||||||
{
|
{
|
||||||
_name = identity.Name;
|
_name = identity.Name;
|
||||||
return identity.Name;
|
return identity.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
var claim = _httpContextAccessor.HttpContext!.User.Claims
|
var claim = _httpContextAccessor.HttpContext!.User.Claims
|
||||||
.FirstOrDefault(c => string.Equals(c.Type, ClaimTypes.Name, StringComparison.OrdinalIgnoreCase))?
|
.FirstOrDefault(c => string.Equals(c.Type, ClaimTypes.Name, StringComparison.OrdinalIgnoreCase))?
|
||||||
.Value;
|
.Value;
|
||||||
|
@ -9,9 +9,9 @@ namespace CleanArchitecture.Domain.Commands;
|
|||||||
|
|
||||||
public abstract class CommandHandlerBase
|
public abstract class CommandHandlerBase
|
||||||
{
|
{
|
||||||
protected readonly IMediatorHandler Bus;
|
|
||||||
private readonly DomainNotificationHandler _notifications;
|
private readonly DomainNotificationHandler _notifications;
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
|
protected readonly IMediatorHandler Bus;
|
||||||
|
|
||||||
protected CommandHandlerBase(
|
protected CommandHandlerBase(
|
||||||
IMediatorHandler bus,
|
IMediatorHandler bus,
|
||||||
|
@ -6,13 +6,13 @@ public sealed class CreateTenantCommand : CommandBase
|
|||||||
{
|
{
|
||||||
private static readonly CreateTenantCommandValidation s_validation = new();
|
private static readonly CreateTenantCommandValidation s_validation = new();
|
||||||
|
|
||||||
public string Name { get; }
|
|
||||||
|
|
||||||
public CreateTenantCommand(Guid tenantId, string name) : base(tenantId)
|
public CreateTenantCommand(Guid tenantId, string name) : base(tenantId)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Name { get; }
|
||||||
|
|
||||||
public override bool IsValid()
|
public override bool IsValid()
|
||||||
{
|
{
|
||||||
ValidationResult = s_validation.Validate(this);
|
ValidationResult = s_validation.Validate(this);
|
||||||
|
@ -15,8 +15,8 @@ public sealed class DeleteTenantCommandHandler : CommandHandlerBase,
|
|||||||
IRequestHandler<DeleteTenantCommand>
|
IRequestHandler<DeleteTenantCommand>
|
||||||
{
|
{
|
||||||
private readonly ITenantRepository _tenantRepository;
|
private readonly ITenantRepository _tenantRepository;
|
||||||
private readonly IUserRepository _userRepository;
|
|
||||||
private readonly IUser _user;
|
private readonly IUser _user;
|
||||||
|
private readonly IUserRepository _userRepository;
|
||||||
|
|
||||||
public DeleteTenantCommandHandler(
|
public DeleteTenantCommandHandler(
|
||||||
IMediatorHandler bus,
|
IMediatorHandler bus,
|
||||||
|
@ -6,13 +6,13 @@ public sealed class UpdateTenantCommand : CommandBase
|
|||||||
{
|
{
|
||||||
private static readonly UpdateTenantCommandValidation s_validation = new();
|
private static readonly UpdateTenantCommandValidation s_validation = new();
|
||||||
|
|
||||||
public string Name { get; }
|
|
||||||
|
|
||||||
public UpdateTenantCommand(Guid tenantId, string name) : base(tenantId)
|
public UpdateTenantCommand(Guid tenantId, string name) : base(tenantId)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Name { get; }
|
||||||
|
|
||||||
public override bool IsValid()
|
public override bool IsValid()
|
||||||
{
|
{
|
||||||
ValidationResult = s_validation.Validate(this);
|
ValidationResult = s_validation.Validate(this);
|
||||||
|
@ -15,9 +15,9 @@ namespace CleanArchitecture.Domain.Commands.Users.CreateUser;
|
|||||||
public sealed class CreateUserCommandHandler : CommandHandlerBase,
|
public sealed class CreateUserCommandHandler : CommandHandlerBase,
|
||||||
IRequestHandler<CreateUserCommand>
|
IRequestHandler<CreateUserCommand>
|
||||||
{
|
{
|
||||||
private readonly IUserRepository _userRepository;
|
|
||||||
private readonly ITenantRepository _tenantRepository;
|
private readonly ITenantRepository _tenantRepository;
|
||||||
private readonly IUser _user;
|
private readonly IUser _user;
|
||||||
|
private readonly IUserRepository _userRepository;
|
||||||
|
|
||||||
public CreateUserCommandHandler(
|
public CreateUserCommandHandler(
|
||||||
IMediatorHandler bus,
|
IMediatorHandler bus,
|
||||||
|
@ -4,11 +4,6 @@ namespace CleanArchitecture.Domain.DomainEvents;
|
|||||||
|
|
||||||
public class StoredDomainEvent : DomainEvent
|
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(
|
public StoredDomainEvent(
|
||||||
DomainEvent domainEvent,
|
DomainEvent domainEvent,
|
||||||
string data,
|
string data,
|
||||||
@ -24,5 +19,11 @@ public class StoredDomainEvent : DomainEvent
|
|||||||
|
|
||||||
// EF Constructor
|
// EF Constructor
|
||||||
protected StoredDomainEvent() : base(Guid.NewGuid())
|
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,11 +5,6 @@ namespace CleanArchitecture.Domain.DomainNotifications;
|
|||||||
|
|
||||||
public class StoredDomainNotification : DomainNotification
|
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(
|
public StoredDomainNotification(
|
||||||
DomainNotification domainNotification,
|
DomainNotification domainNotification,
|
||||||
string data,
|
string data,
|
||||||
@ -31,5 +26,11 @@ public class StoredDomainNotification : DomainNotification
|
|||||||
|
|
||||||
// EF Constructor
|
// EF Constructor
|
||||||
protected StoredDomainNotification() : base(string.Empty, string.Empty, string.Empty)
|
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 class Tenant : Entity
|
||||||
{
|
{
|
||||||
public string Name { get; private set; }
|
|
||||||
|
|
||||||
public virtual ICollection<User> Users { get; private set; } = new HashSet<User>();
|
|
||||||
|
|
||||||
public Tenant(
|
public Tenant(
|
||||||
Guid id,
|
Guid id,
|
||||||
string name) : base(id)
|
string name) : base(id)
|
||||||
@ -16,6 +12,10 @@ public class Tenant : Entity
|
|||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Name { get; private set; }
|
||||||
|
|
||||||
|
public virtual ICollection<User> Users { get; private set; } = new HashSet<User>();
|
||||||
|
|
||||||
public void SetName(string name)
|
public void SetName(string name)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
|
@ -1,22 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using CleanArchitecture.Domain.Enums;
|
using CleanArchitecture.Domain.Enums;
|
||||||
|
|
||||||
namespace CleanArchitecture.Domain.Entities;
|
namespace CleanArchitecture.Domain.Entities;
|
||||||
|
|
||||||
public class User : Entity
|
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(
|
public User(
|
||||||
Guid id,
|
Guid id,
|
||||||
Guid tenantId,
|
Guid tenantId,
|
||||||
@ -34,6 +22,17 @@ public class User : Entity
|
|||||||
Role = role;
|
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)
|
public void SetEmail(string email)
|
||||||
{
|
{
|
||||||
Email = email;
|
Email = email;
|
||||||
|
@ -5,10 +5,10 @@ namespace CleanArchitecture.Domain.Events.Tenant;
|
|||||||
|
|
||||||
public sealed class TenantCreatedEvent : DomainEvent
|
public sealed class TenantCreatedEvent : DomainEvent
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public TenantCreatedEvent(Guid tenantId, string name) : base(tenantId)
|
public TenantCreatedEvent(Guid tenantId, string name) : base(tenantId)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
}
|
}
|
@ -5,10 +5,10 @@ namespace CleanArchitecture.Domain.Events.Tenant;
|
|||||||
|
|
||||||
public sealed class TenantUpdatedEvent : DomainEvent
|
public sealed class TenantUpdatedEvent : DomainEvent
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public TenantUpdatedEvent(Guid tenantId, string name) : base(tenantId)
|
public TenantUpdatedEvent(Guid tenantId, string name) : base(tenantId)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
using System;
|
|
||||||
using CleanArchitecture.Domain.Constants;
|
using CleanArchitecture.Domain.Constants;
|
||||||
using CleanArchitecture.Domain.Entities;
|
using CleanArchitecture.Domain.Entities;
|
||||||
using CleanArchitecture.Domain.Enums;
|
using CleanArchitecture.Domain.Enums;
|
||||||
|
@ -9,9 +9,9 @@ namespace CleanArchitecture.Infrastructure.EventSourcing;
|
|||||||
|
|
||||||
public sealed class DomainEventStore : IDomainEventStore
|
public sealed class DomainEventStore : IDomainEventStore
|
||||||
{
|
{
|
||||||
private readonly EventStoreDbContext _eventStoreDbContext;
|
|
||||||
private readonly DomainNotificationStoreDbContext _domainNotificationStoreDbContext;
|
|
||||||
private readonly IEventStoreContext _context;
|
private readonly IEventStoreContext _context;
|
||||||
|
private readonly DomainNotificationStoreDbContext _domainNotificationStoreDbContext;
|
||||||
|
private readonly EventStoreDbContext _eventStoreDbContext;
|
||||||
|
|
||||||
public DomainEventStore(
|
public DomainEventStore(
|
||||||
EventStoreDbContext eventStoreDbContext,
|
EventStoreDbContext eventStoreDbContext,
|
||||||
|
@ -14,7 +14,8 @@ public sealed class EventStoreContext : IEventStoreContext
|
|||||||
_user = user;
|
_user = user;
|
||||||
|
|
||||||
if (httpContextAccessor?.HttpContext is null ||
|
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()}";
|
_correlationId = $"internal - {Guid.NewGuid()}";
|
||||||
}
|
}
|
||||||
@ -24,7 +25,13 @@ public sealed class EventStoreContext : IEventStoreContext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCorrelationId() => _correlationId;
|
public string GetCorrelationId()
|
||||||
|
{
|
||||||
public string GetUserEmail() => _user?.GetUserEmail() ?? string.Empty;
|
return _correlationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetUserEmail()
|
||||||
|
{
|
||||||
|
return _user?.GetUserEmail() ?? string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
@ -5,6 +5,12 @@
|
|||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
[assembly: SuppressMessage("Style", "IDE0161:Convert to file-scoped namespace", Justification = "<Pending>", Scope = "namespace", Target = "~N:CleanArchitecture.Infrastructure.Migrations")]
|
[assembly:
|
||||||
[assembly: SuppressMessage("Style", "IDE0161:Convert to file-scoped namespace", Justification = "<Pending>", Scope = "namespace", Target = "~N:CleanArchitecture.Infrastructure.Migrations.EventStoreDb")]
|
SuppressMessage("Style", "IDE0161:Convert to file-scoped namespace", Justification = "<Pending>",
|
||||||
[assembly: SuppressMessage("Style", "IDE0161:Convert to file-scoped namespace", Justification = "<Pending>", Scope = "namespace", Target = "~N:CleanArchitecture.Infrastructure.Migrations.DomainNotificationStoreDb")]
|
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
|
public sealed class InMemoryBus : IMediatorHandler
|
||||||
{
|
{
|
||||||
private readonly IMediator _mediator;
|
|
||||||
private readonly IDomainEventStore _domainEventStore;
|
private readonly IDomainEventStore _domainEventStore;
|
||||||
|
private readonly IMediator _mediator;
|
||||||
|
|
||||||
public InMemoryBus(
|
public InMemoryBus(
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using System;
|
#nullable disable
|
||||||
|
|
||||||
|
using System;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
#nullable disable
|
namespace CleanArchitecture.Infrastructure.Migrations.DomainNotificationStoreDb;
|
||||||
|
|
||||||
namespace CleanArchitecture.Infrastructure.Migrations.DomainNotificationStoreDb
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class AddDomainNotificationStore : Migration
|
public partial class AddDomainNotificationStore : Migration
|
||||||
{
|
{
|
||||||
@ -12,32 +12,28 @@ namespace CleanArchitecture.Infrastructure.Migrations.DomainNotificationStoreDb
|
|||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "StoredDomainNotifications",
|
"StoredDomainNotifications",
|
||||||
columns: table => new
|
table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
Id = table.Column<Guid>("uniqueidentifier", nullable: false),
|
||||||
Data = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
Data = table.Column<string>("nvarchar(max)", nullable: false),
|
||||||
User = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
User = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||||
CorrelationId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
CorrelationId = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||||
AggregateId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
AggregateId = table.Column<Guid>("uniqueidentifier", nullable: false),
|
||||||
MessageType = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
MessageType = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||||
Timestamp = table.Column<DateTime>(type: "datetime2", nullable: false),
|
Timestamp = table.Column<DateTime>("datetime2", nullable: false),
|
||||||
Key = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
Key = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||||
Value = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: false),
|
Value = table.Column<string>("nvarchar(1024)", maxLength: 1024, nullable: false),
|
||||||
Code = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
Code = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||||
Version = table.Column<int>(type: "int", nullable: false)
|
Version = table.Column<int>("int", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table => { table.PrimaryKey("PK_StoredDomainNotifications", x => x.Id); });
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_StoredDomainNotifications", x => x.Id);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "StoredDomainNotifications");
|
"StoredDomainNotifications");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
using System;
|
#nullable disable
|
||||||
|
|
||||||
|
using System;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
#nullable disable
|
namespace CleanArchitecture.Infrastructure.Migrations.EventStoreDb;
|
||||||
|
|
||||||
namespace CleanArchitecture.Infrastructure.Migrations.EventStoreDb
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class AddEventStore : Migration
|
public partial class AddEventStore : Migration
|
||||||
{
|
{
|
||||||
@ -12,28 +12,24 @@ namespace CleanArchitecture.Infrastructure.Migrations.EventStoreDb
|
|||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "StoredDomainEvents",
|
"StoredDomainEvents",
|
||||||
columns: table => new
|
table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
Id = table.Column<Guid>("uniqueidentifier", nullable: false),
|
||||||
Data = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
Data = table.Column<string>("nvarchar(max)", nullable: false),
|
||||||
User = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
User = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||||
CorrelationId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
CorrelationId = table.Column<string>("nvarchar(100)", maxLength: 100, nullable: false),
|
||||||
AggregateId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
AggregateId = table.Column<Guid>("uniqueidentifier", nullable: false),
|
||||||
Action = table.Column<string>(type: "varchar(100)", nullable: false),
|
Action = table.Column<string>("varchar(100)", nullable: false),
|
||||||
CreationDate = table.Column<DateTime>(type: "datetime2", nullable: false)
|
CreationDate = table.Column<DateTime>("datetime2", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table => { table.PrimaryKey("PK_StoredDomainEvents", x => x.Id); });
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_StoredDomainEvents", x => x.Id);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "StoredDomainEvents");
|
"StoredDomainEvents");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CleanArchitecture.Application.ViewModels.Users;
|
using CleanArchitecture.Application.ViewModels.Users;
|
||||||
|
@ -7,9 +7,6 @@ namespace CleanArchitecture.IntegrationTests.Fixtures.gRPC;
|
|||||||
|
|
||||||
public sealed class GetTenantsByIdsTestFixture : TestFixtureBase
|
public sealed class GetTenantsByIdsTestFixture : TestFixtureBase
|
||||||
{
|
{
|
||||||
public GrpcChannel GrpcChannel { get; }
|
|
||||||
public Guid CreatedTenantId { get; } = Guid.NewGuid();
|
|
||||||
|
|
||||||
public GetTenantsByIdsTestFixture()
|
public GetTenantsByIdsTestFixture()
|
||||||
{
|
{
|
||||||
GrpcChannel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions
|
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)
|
protected override void SeedTestData(ApplicationDbContext context)
|
||||||
{
|
{
|
||||||
base.SeedTestData(context);
|
base.SeedTestData(context);
|
||||||
@ -30,7 +30,7 @@ public sealed class GetTenantsByIdsTestFixture : TestFixtureBase
|
|||||||
|
|
||||||
public Tenant CreateTenant()
|
public Tenant CreateTenant()
|
||||||
{
|
{
|
||||||
return new(
|
return new Tenant(
|
||||||
CreatedTenantId,
|
CreatedTenantId,
|
||||||
"Test Tenant");
|
"Test Tenant");
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,6 @@ namespace CleanArchitecture.IntegrationTests.Fixtures.gRPC;
|
|||||||
|
|
||||||
public sealed class GetUsersByIdsTestFixture : TestFixtureBase
|
public sealed class GetUsersByIdsTestFixture : TestFixtureBase
|
||||||
{
|
{
|
||||||
public GrpcChannel GrpcChannel { get; }
|
|
||||||
public Guid CreatedUserId { get; } = Guid.NewGuid();
|
|
||||||
|
|
||||||
public GetUsersByIdsTestFixture()
|
public GetUsersByIdsTestFixture()
|
||||||
{
|
{
|
||||||
GrpcChannel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions
|
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)
|
protected override void SeedTestData(ApplicationDbContext context)
|
||||||
{
|
{
|
||||||
base.SeedTestData(context);
|
base.SeedTestData(context);
|
||||||
|
@ -47,14 +47,14 @@ public sealed class CleanArchitectureWebApplicationFactory : WebApplicationFacto
|
|||||||
services.SetupTestDatabase<EventStoreDbContext>(_connection);
|
services.SetupTestDatabase<EventStoreDbContext>(_connection);
|
||||||
services.SetupTestDatabase<DomainNotificationStoreDbContext>(_connection);
|
services.SetupTestDatabase<DomainNotificationStoreDbContext>(_connection);
|
||||||
|
|
||||||
ServiceProvider sp = services.BuildServiceProvider();
|
var sp = services.BuildServiceProvider();
|
||||||
|
|
||||||
using IServiceScope scope = sp.CreateScope();
|
using var scope = sp.CreateScope();
|
||||||
IServiceProvider scopedServices = scope.ServiceProvider;
|
var scopedServices = scope.ServiceProvider;
|
||||||
|
|
||||||
ApplicationDbContext applicationDbContext = scopedServices.GetRequiredService<ApplicationDbContext>();
|
var applicationDbContext = scopedServices.GetRequiredService<ApplicationDbContext>();
|
||||||
EventStoreDbContext storeDbContext = scopedServices.GetRequiredService<EventStoreDbContext>();
|
var storeDbContext = scopedServices.GetRequiredService<EventStoreDbContext>();
|
||||||
DomainNotificationStoreDbContext domainStoreDbContext = scopedServices.GetRequiredService<DomainNotificationStoreDbContext>();
|
var domainStoreDbContext = scopedServices.GetRequiredService<DomainNotificationStoreDbContext>();
|
||||||
|
|
||||||
applicationDbContext.EnsureMigrationsApplied();
|
applicationDbContext.EnsureMigrationsApplied();
|
||||||
|
|
||||||
|
@ -10,24 +10,24 @@ namespace CleanArchitecture.gRPC.Tests.Fixtures;
|
|||||||
|
|
||||||
public sealed class TenantTestFixture
|
public sealed class TenantTestFixture
|
||||||
{
|
{
|
||||||
public TenantsApiImplementation TenantsApiImplementation { get; }
|
|
||||||
private ITenantRepository TenantRepository { get; }
|
|
||||||
|
|
||||||
public IEnumerable<Tenant> ExistingTenants { get; }
|
|
||||||
|
|
||||||
public TenantTestFixture()
|
public TenantTestFixture()
|
||||||
{
|
{
|
||||||
TenantRepository = Substitute.For<ITenantRepository>();
|
TenantRepository = Substitute.For<ITenantRepository>();
|
||||||
|
|
||||||
ExistingTenants = new List<Tenant>
|
ExistingTenants = new List<Tenant>
|
||||||
{
|
{
|
||||||
new Tenant(Guid.NewGuid(), "Tenant 1"),
|
new(Guid.NewGuid(), "Tenant 1"),
|
||||||
new Tenant(Guid.NewGuid(), "Tenant 2"),
|
new(Guid.NewGuid(), "Tenant 2"),
|
||||||
new Tenant(Guid.NewGuid(), "Tenant 3"),
|
new(Guid.NewGuid(), "Tenant 3")
|
||||||
};
|
};
|
||||||
|
|
||||||
TenantRepository.GetAllNoTracking().Returns(ExistingTenants.BuildMock());
|
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
|
public sealed class CleanArchitecture : ICleanArchitecture
|
||||||
{
|
{
|
||||||
private readonly IUsersContext _users;
|
|
||||||
private readonly ITenantsContext _tenants;
|
|
||||||
|
|
||||||
public IUsersContext Users => _users;
|
|
||||||
public ITenantsContext Tenants => _tenants;
|
|
||||||
|
|
||||||
public CleanArchitecture(
|
public CleanArchitecture(
|
||||||
IUsersContext users,
|
IUsersContext users,
|
||||||
ITenantsContext tenants)
|
ITenantsContext tenants)
|
||||||
{
|
{
|
||||||
_users = users;
|
Users = users;
|
||||||
_tenants = tenants;
|
Tenants = tenants;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public IUsersContext Users { get; }
|
||||||
|
|
||||||
|
public ITenantsContext Tenants { get; }
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user