Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Voltiq.API/Controllers/BaseApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Voltiq.API.Controllers;

[ApiController]
[Produces("application/json", "application/problem+json")]
[Route("api/v{version:apiVersion}/[controller]")]
public abstract class BaseApiController : ControllerBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Voltiq.API.Controllers.Materials;

[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/materials")]
public sealed class MaterialsController : BaseApiController
{
/// <summary>Registers a new material for the authenticated user.</summary>
Expand Down
32 changes: 0 additions & 32 deletions src/Voltiq.API/ExceptionHandlers/UnauthorizedExceptionHandler.cs

This file was deleted.

33 changes: 16 additions & 17 deletions src/Voltiq.API/Voltiq.API.csproj
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<ItemGroup>
<ProjectReference Include="..\Voltiq.Application\Voltiq.Application.csproj" />
<ProjectReference Include="..\Voltiq.Exceptions\Voltiq.Exceptions.csproj" />
<ProjectReference Include="..\Voltiq.Infrastructure\Voltiq.Infrastructure.csproj" />
<ProjectReference Include="..\Voltiq.Application\Voltiq.Application.csproj"/>
<ProjectReference Include="..\Voltiq.Exceptions\Voltiq.Exceptions.csproj"/>
<ProjectReference Include="..\Voltiq.Infrastructure\Voltiq.Infrastructure.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Asp.Versioning.Mvc" Version="8.1.1" />
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.1" />
<PackageReference Include="ErrorOr" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.4" />
<PackageReference Include="Asp.Versioning.Mvc" Version="8.1.1"/>
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.1"/>
<PackageReference Include="ErrorOr" Version="2.0.1"/>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.1.5" />
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0"/>
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0"/>
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.1.5"/>
</ItemGroup>

<ItemGroup>
<Compile Remove="Features\**" />
<Compile Remove="ExceptionHandlers\UnauthorizedExceptionHandler.cs" />
<Compile Remove="Features\**"/>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Remove="Features\**" />
<EmbeddedResource Remove="Features\**"/>
</ItemGroup>

<ItemGroup>
<Content Remove="Features\**" />
<Content Remove="Features\**"/>
</ItemGroup>

<ItemGroup>
<None Remove="Features\**" />
<None Remove="Features\**"/>
</ItemGroup>

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AllowMissingPrunePackageData>true</AllowMissingPrunePackageData>
<UserSecretsId>0cd97f61-50df-4c03-8e90-8348a3369961</UserSecretsId>
</PropertyGroup>
<UserSecretsId>0cd97f61-50df-4c03-8e90-8348a3369961</UserSecretsId>
</PropertyGroup>

</Project>
126 changes: 126 additions & 0 deletions tests/Voltiq.CommonTestUtilities/Builders/TestDataBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using Voltiq.Domain.Entities;
using Voltiq.Domain.Enums;
using Voltiq.Domain.Interfaces;
using Voltiq.Domain.Interfaces.Repositories.Budget;
using Voltiq.Domain.Interfaces.Repositories.Client;
using Voltiq.Domain.Interfaces.Repositories.Material;
using Voltiq.Domain.Interfaces.Repositories.RefreshToken;
using Voltiq.Domain.Interfaces.Repositories.User;
using Voltiq.Domain.ValueObjects;

namespace Voltiq.CommonTestUtilities.Builders;

public static class TestDataBuilder
{
private static CancellationToken Ct => TestContext.Current.CancellationToken;

public static User MakeUser(
string name = "João Silva",
string email = "joao@example.com",
string document = "529.982.247-25",
string passwordHash = "$argon2id$hash")
{
var emailVo = Email.Create(email).Value;
var documentVo = Document.Create(document).Value;
return User.Register(name, emailVo, documentVo, passwordHash);
}

public static Client MakeClient(
Guid userId,
string name = "Cliente Teste",
string email = "cliente@example.com",
string phone = "(11) 99999-9999")
{
var emailVo = Email.Create(email).Value;
return Client.Register(userId, name, phone, emailVo,
Address.Create("Rua das Flores", "123", "São Paulo", "SP", "01310-100"));
}

public static Material MakeMaterial(
Guid userId,
string name = "Cabo 10mm",
decimal defaultPrice = 15.50m,
MaterialUnit unit = MaterialUnit.Metro)
{
return Material.Register(userId, name, defaultPrice, unit);
}

public static Budget MakeBudget(Guid userId, Guid clientId)
{
return Budget.Register(userId, clientId);
}

public static RefreshToken MakeRefreshToken(
string token,
Guid userId,
int daysToExpire = 7)
{
return RefreshToken.Create(token, userId, daysToExpire);
}


public static async Task<User> SeedUserAsync(
IUserWriteOnlyRepository repository,
IUnitOfWork unitOfWork,
string name = "João Silva",
string email = "joao@example.com",
string document = "529.982.247-25")
{
var user = MakeUser(name, email, document);
await repository.AddAsync(user, Ct);
await unitOfWork.SaveChangesAsync(Ct);
return user;
}

public static async Task<Client> SeedClientAsync(
IClientWriteOnlyRepository repository,
IUnitOfWork unitOfWork,
Guid userId,
string name = "Cliente Teste",
string email = "cliente@example.com")
{
var client = MakeClient(userId, name, email);
await repository.AddAsync(client, Ct);
await unitOfWork.SaveChangesAsync(Ct);
return client;
}

public static async Task<Material> SeedMaterialAsync(
IMaterialWriteOnlyRepository repository,
IUnitOfWork unitOfWork,
Guid userId,
string name = "Cabo 10mm",
decimal defaultPrice = 15.50m,
MaterialUnit unit = MaterialUnit.Metro)
{
var material = MakeMaterial(userId, name, defaultPrice, unit);
await repository.AddAsync(material, Ct);
await unitOfWork.SaveChangesAsync(Ct);
return material;
}

public static async Task<Budget> SeedBudgetAsync(
IBudgetWriteOnlyRepository repository,
IUnitOfWork unitOfWork,
Guid userId,
Guid clientId)
{
var budget = MakeBudget(userId, clientId);
await repository.AddAsync(budget, Ct);
await unitOfWork.SaveChangesAsync(Ct);
return budget;
}

public static async Task<RefreshToken> SeedRefreshTokenAsync(
IRefreshTokenWriteOnlyRepository repository,
IUnitOfWork unitOfWork,
Guid userId,
string token = "test-token",
int daysToExpire = 7)
{
var refreshToken = MakeRefreshToken(token, userId, daysToExpire);
await repository.AddAsync(refreshToken, Ct);
await unitOfWork.SaveChangesAsync(Ct);
return refreshToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public sealed class PostgreSqlContainerFixture(IMessageSink messageSink)
: ContainerFixture<PostgreSqlBuilder, PostgreSqlContainer>(messageSink)
{
protected override PostgreSqlBuilder Configure()
=> new PostgreSqlBuilder("postgres:16-alpine");
=> new PostgreSqlBuilder("postgres:17-alpine");
}
Loading
Loading