mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Format: ./src/Core/Service
This commit is contained in:
@@ -23,7 +23,6 @@ public class RegisterServiceTest
|
|||||||
_tokenServiceMock = new Mock<ITokenService>();
|
_tokenServiceMock = new Mock<ITokenService>();
|
||||||
_emailServiceMock = new Mock<IEmailService>();
|
_emailServiceMock = new Mock<IEmailService>();
|
||||||
|
|
||||||
|
|
||||||
_registerService = new RegisterService(
|
_registerService = new RegisterService(
|
||||||
_authRepoMock.Object,
|
_authRepoMock.Object,
|
||||||
_passwordInfraMock.Object,
|
_passwordInfraMock.Object,
|
||||||
@@ -97,7 +96,6 @@ public class RegisterServiceTest
|
|||||||
.Setup(x => x.GenerateRefreshToken(It.IsAny<UserAccount>()))
|
.Setup(x => x.GenerateRefreshToken(It.IsAny<UserAccount>()))
|
||||||
.Returns("refresh-token");
|
.Returns("refresh-token");
|
||||||
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await _registerService.RegisterAsync(
|
var result = await _registerService.RegisterAsync(
|
||||||
userAccount,
|
userAccount,
|
||||||
@@ -134,8 +132,14 @@ public class RegisterServiceTest
|
|||||||
),
|
),
|
||||||
Times.Once
|
Times.Once
|
||||||
);
|
);
|
||||||
_emailServiceMock.Verify(x => x.SendRegistrationEmailAsync(It.IsAny<UserAccount>(), It.IsAny<string>()),
|
_emailServiceMock.Verify(
|
||||||
Times.Once);
|
x =>
|
||||||
|
x.SendRegistrationEmailAsync(
|
||||||
|
It.IsAny<UserAccount>(),
|
||||||
|
It.IsAny<string>()
|
||||||
|
),
|
||||||
|
Times.Once
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -54,7 +54,10 @@ public class RegisterService(
|
|||||||
var refreshToken = tokenService.GenerateRefreshToken(createdUser);
|
var refreshToken = tokenService.GenerateRefreshToken(createdUser);
|
||||||
|
|
||||||
// send confirmation email
|
// send confirmation email
|
||||||
await emailService.SendRegistrationEmailAsync(createdUser, "some-confirmation-token");
|
await emailService.SendRegistrationEmailAsync(
|
||||||
|
createdUser,
|
||||||
|
"some-confirmation-token"
|
||||||
|
);
|
||||||
|
|
||||||
return new AuthServiceReturn(createdUser, refreshToken, accessToken);
|
return new AuthServiceReturn(createdUser, refreshToken, accessToken);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,11 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Domain.Entities\Domain.Entities.csproj" />
|
<ProjectReference Include="..\..\Domain.Entities\Domain.Entities.csproj" />
|
||||||
<ProjectReference Include="..\..\Domain.Exceptions\Domain.Exceptions.csproj" />
|
<ProjectReference Include="..\..\Domain.Exceptions\Domain.Exceptions.csproj" />
|
||||||
<ProjectReference
|
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Email\Infrastructure.Email.csproj" />
|
||||||
Include="..\..\Infrastructure\Infrastructure.Email\Infrastructure.Email.csproj" />
|
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Email.Templates\Infrastructure.Email.Templates.csproj" />
|
||||||
<ProjectReference
|
|
||||||
Include="..\..\Infrastructure\Infrastructure.Email.Templates\Infrastructure.Email.Templates.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Jwt\Infrastructure.Jwt.csproj" />
|
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Jwt\Infrastructure.Jwt.csproj" />
|
||||||
<ProjectReference
|
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Repository\Infrastructure.Repository.csproj" />
|
||||||
Include="..\..\Infrastructure\Infrastructure.Repository\Infrastructure.Repository.csproj" />
|
<ProjectReference Include="..\..\Infrastructure\Infrastructure.PasswordHashing\Infrastructure.PasswordHashing.csproj" />
|
||||||
<ProjectReference
|
|
||||||
Include="..\..\Infrastructure\Infrastructure.PasswordHashing\Infrastructure.PasswordHashing.csproj" />
|
|
||||||
<ProjectReference Include="..\Service.Emails\Service.Emails.csproj" />
|
<ProjectReference Include="..\Service.Emails\Service.Emails.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -6,21 +6,30 @@ namespace Service.Emails;
|
|||||||
|
|
||||||
public interface IEmailService
|
public interface IEmailService
|
||||||
{
|
{
|
||||||
public Task SendRegistrationEmailAsync(UserAccount createdUser, string confirmationToken);
|
public Task SendRegistrationEmailAsync(
|
||||||
|
UserAccount createdUser,
|
||||||
|
string confirmationToken
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EmailService(
|
public class EmailService(
|
||||||
IEmailProvider emailProvider,
|
IEmailProvider emailProvider,
|
||||||
IEmailTemplateProvider emailTemplateProvider) : IEmailService
|
IEmailTemplateProvider emailTemplateProvider
|
||||||
|
) : IEmailService
|
||||||
{
|
{
|
||||||
public async Task SendRegistrationEmailAsync(UserAccount createdUser, string confirmationToken)
|
public async Task SendRegistrationEmailAsync(
|
||||||
|
UserAccount createdUser,
|
||||||
|
string confirmationToken
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var confirmationLink = $"https://thebiergarten.app/confirm?token={confirmationToken}";
|
var confirmationLink =
|
||||||
|
$"https://thebiergarten.app/confirm?token={confirmationToken}";
|
||||||
|
|
||||||
var emailHtml = await emailTemplateProvider.RenderUserRegisteredEmailAsync(
|
var emailHtml =
|
||||||
createdUser.FirstName,
|
await emailTemplateProvider.RenderUserRegisteredEmailAsync(
|
||||||
confirmationLink
|
createdUser.FirstName,
|
||||||
);
|
confirmationLink
|
||||||
|
);
|
||||||
|
|
||||||
await emailProvider.SendAsync(
|
await emailProvider.SendAsync(
|
||||||
createdUser.Email,
|
createdUser.Email,
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<ItemGroup>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<ProjectReference Include="..\..\Domain.Entities\Domain.Entities.csproj" />
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Email.Templates\Infrastructure.Email.Templates.csproj" />
|
||||||
<Nullable>enable</Nullable>
|
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Email\Infrastructure.Email.csproj" />
|
||||||
</PropertyGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\Domain.Entities\Domain.Entities.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Email.Templates\Infrastructure.Email.Templates.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Email\Infrastructure.Email.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<ItemGroup>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<ProjectReference Include="..\..\Domain.Exceptions\Domain.Exceptions.csproj" />
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Repository\Infrastructure.Repository.csproj" />
|
||||||
<Nullable>enable</Nullable>
|
</ItemGroup>
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\Domain.Exceptions\Domain.Exceptions.csproj" />
|
|
||||||
<ProjectReference
|
|
||||||
Include="..\..\Infrastructure\Infrastructure.Repository\Infrastructure.Repository.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ namespace Service.UserManagement.User;
|
|||||||
|
|
||||||
public interface IUserService
|
public interface IUserService
|
||||||
{
|
{
|
||||||
Task<IEnumerable<UserAccount>> GetAllAsync(int? limit = null, int? offset = null);
|
Task<IEnumerable<UserAccount>> GetAllAsync(
|
||||||
|
int? limit = null,
|
||||||
|
int? offset = null
|
||||||
|
);
|
||||||
Task<UserAccount> GetByIdAsync(Guid id);
|
Task<UserAccount> GetByIdAsync(Guid id);
|
||||||
|
|
||||||
Task UpdateAsync(UserAccount userAccount);
|
Task UpdateAsync(UserAccount userAccount);
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ namespace Service.UserManagement.User;
|
|||||||
|
|
||||||
public class UserService(IUserAccountRepository repository) : IUserService
|
public class UserService(IUserAccountRepository repository) : IUserService
|
||||||
{
|
{
|
||||||
public async Task<IEnumerable<UserAccount>> GetAllAsync(int? limit = null, int? offset = null)
|
public async Task<IEnumerable<UserAccount>> GetAllAsync(
|
||||||
|
int? limit = null,
|
||||||
|
int? offset = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return await repository.GetAllAsync(limit, offset);
|
return await repository.GetAllAsync(limit, offset);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user