Format ./web/backend/Features/Features.Breweries.Tests

This commit is contained in:
Aaron Po
2026-06-20 15:09:42 -04:00
parent 0f77ae43b5
commit aadeab3afa
8 changed files with 48 additions and 47 deletions

View File

@@ -19,24 +19,13 @@ public class CreateBreweryHandlerTests
private static CreateBreweryLocation ValidLocation()
{
return new CreateBreweryLocation(
Guid.NewGuid(),
"123 Main St",
null,
"12345",
null
);
return new CreateBreweryLocation(Guid.NewGuid(), "123 Main St", null, "12345", null);
}
[Fact]
public async Task Handle_PersistsEntity_WithNewIdsAndCreatedAt()
{
CreateBreweryCommand command = new(
Guid.NewGuid(),
"MyBrew",
"Desc",
ValidLocation()
);
CreateBreweryCommand command = new(Guid.NewGuid(), "MyBrew", "Desc", ValidLocation());
BreweryPost? persisted = null;
_repoMock

View File

@@ -96,7 +96,9 @@ public class UpdateBreweryHandlerTests
await _handler.Handle(command, CancellationToken.None);
persisted!.Location.Should().NotBeNull();
persisted.Location!.BreweryPostLocationId.Should().Be(locationCommand.BreweryPostLocationId);
persisted
.Location!.BreweryPostLocationId.Should()
.Be(locationCommand.BreweryPostLocationId);
persisted.Location.BreweryPostId.Should().Be(command.BreweryPostId);
persisted.Location.CityId.Should().Be(locationCommand.CityId);
persisted.Location.AddressLine1.Should().Be(locationCommand.AddressLine1);

View File

@@ -20,10 +20,12 @@ public class GetAllBreweriesHandlerTests
[Fact]
public async Task Handle_PassesLimitAndOffset_ToRepository()
{
_repoMock.Setup(r => r.GetAllAsync(10, 5))
.ReturnsAsync(Array.Empty<BreweryPost>());
_repoMock.Setup(r => r.GetAllAsync(10, 5)).ReturnsAsync(Array.Empty<BreweryPost>());
IEnumerable<BreweryDto> result = await _handler.Handle(new GetAllBreweriesQuery(10, 5), CancellationToken.None);
IEnumerable<BreweryDto> result = await _handler.Handle(
new GetAllBreweriesQuery(10, 5),
CancellationToken.None
);
result.Should().BeEmpty();
_repoMock.Verify(r => r.GetAllAsync(10, 5), Times.Once);
@@ -35,13 +37,18 @@ public class GetAllBreweriesHandlerTests
BreweryPost[] breweries = new[]
{
new BreweryPost { BreweryPostId = Guid.NewGuid(), BreweryName = "A" },
new BreweryPost { BreweryPostId = Guid.NewGuid(), BreweryName = "B" }
new BreweryPost { BreweryPostId = Guid.NewGuid(), BreweryName = "B" },
};
_repoMock.Setup(r => r.GetAllAsync(null, null))
.ReturnsAsync(breweries);
_repoMock.Setup(r => r.GetAllAsync(null, null)).ReturnsAsync(breweries);
IEnumerable<BreweryDto> result = await _handler.Handle(new GetAllBreweriesQuery(null, null), CancellationToken.None);
IEnumerable<BreweryDto> result = await _handler.Handle(
new GetAllBreweriesQuery(null, null),
CancellationToken.None
);
result.Select(b => b.BreweryPostId).Should().BeEquivalentTo(breweries.Select(b => b.BreweryPostId));
result
.Select(b => b.BreweryPostId)
.Should()
.BeEquivalentTo(breweries.Select(b => b.BreweryPostId));
}
}

View File

@@ -21,10 +21,12 @@ public class GetBreweryByIdHandlerTests
public async Task Handle_ReturnsBrewery_WhenFound()
{
BreweryPost brewery = new() { BreweryPostId = Guid.NewGuid(), BreweryName = "Test" };
_repoMock.Setup(r => r.GetByIdAsync(brewery.BreweryPostId))
.ReturnsAsync(brewery);
_repoMock.Setup(r => r.GetByIdAsync(brewery.BreweryPostId)).ReturnsAsync(brewery);
BreweryDto? result = await _handler.Handle(new GetBreweryByIdQuery(brewery.BreweryPostId), CancellationToken.None);
BreweryDto? result = await _handler.Handle(
new GetBreweryByIdQuery(brewery.BreweryPostId),
CancellationToken.None
);
result.Should().NotBeNull();
result!.BreweryPostId.Should().Be(brewery.BreweryPostId);
@@ -34,10 +36,12 @@ public class GetBreweryByIdHandlerTests
public async Task Handle_ReturnsNull_WhenNotFound()
{
Guid id = Guid.NewGuid();
_repoMock.Setup(r => r.GetByIdAsync(id))
.ReturnsAsync((BreweryPost?)null);
_repoMock.Setup(r => r.GetByIdAsync(id)).ReturnsAsync((BreweryPost?)null);
BreweryDto? result = await _handler.Handle(new GetBreweryByIdQuery(id), CancellationToken.None);
BreweryDto? result = await _handler.Handle(
new GetBreweryByIdQuery(id),
CancellationToken.None
);
result.Should().BeNull();
}

View File

@@ -81,8 +81,7 @@ public class BreweryRepositoryTests
public async Task CreateAsync_ExecutesSuccessfully()
{
MockDbConnection conn = new();
conn.Mocks.When(cmd => cmd.CommandText == "USP_CreateBrewery")
.ReturnsScalar(1);
conn.Mocks.When(cmd => cmd.CommandText == "USP_CreateBrewery").ReturnsScalar(1);
BreweryRepository repo = CreateRepo(conn);
BreweryPost brewery = new()
{
@@ -97,8 +96,8 @@ public class BreweryRepositoryTests
CityId = Guid.NewGuid(),
AddressLine1 = "123 Main St",
PostalCode = "12345",
Coordinates = [0x00, 0x01]
}
Coordinates = [0x00, 0x01],
},
};
// Should not throw