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
43 changes: 32 additions & 11 deletions content/tests/Company.Template.Api.Tests/Api/ApiRoutesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,42 @@ public sealed class ApiRoutesTests
[Fact]
public void ProductsRoutes_ShouldExposeExpectedRouteTemplates()
{
ApiRoutes.Root.ShouldBe("/api");
ApiRoutes.Products.Base.ShouldBe("/api/products");
ApiRoutes.Products.Collection.ShouldBe("");
ApiRoutes.Products.ById.ShouldBe("/{productId:guid}");
ApiRoutes.Products.Price.ShouldBe("/{productId:guid}/price");
ApiRoutes.Products.Discontinue.ShouldBe("/{productId:guid}/discontinue");
// Arrange

// Act
string root = ApiRoutes.Root;
string productsBase = ApiRoutes.Products.Base;
string collection = ApiRoutes.Products.Collection;
string byId = ApiRoutes.Products.ById;
string price = ApiRoutes.Products.Price;
string discontinue = ApiRoutes.Products.Discontinue;

// Assert
root.ShouldBe("/api");
productsBase.ShouldBe("/api/products");
collection.ShouldBe("");
byId.ShouldBe("/{productId:guid}");
price.ShouldBe("/{productId:guid}/price");
discontinue.ShouldBe("/{productId:guid}/discontinue");
}

[Fact]
public void ProductsRouteNames_ShouldExposeExpectedNames()
{
ApiRoutes.Products.Names.GetProducts.ShouldBe("GetProducts");
ApiRoutes.Products.Names.CreateProduct.ShouldBe("CreateProduct");
ApiRoutes.Products.Names.GetProductById.ShouldBe("GetProductById");
ApiRoutes.Products.Names.ChangeProductPrice.ShouldBe("ChangeProductPrice");
ApiRoutes.Products.Names.DiscontinueProduct.ShouldBe("DiscontinueProduct");
// Arrange

// Act
string getProducts = ApiRoutes.Products.Names.GetProducts;
string createProduct = ApiRoutes.Products.Names.CreateProduct;
string getProductById = ApiRoutes.Products.Names.GetProductById;
string changeProductPrice = ApiRoutes.Products.Names.ChangeProductPrice;
string discontinueProduct = ApiRoutes.Products.Names.DiscontinueProduct;

// Assert
getProducts.ShouldBe("GetProducts");
createProduct.ShouldBe("CreateProduct");
getProductById.ShouldBe("GetProductById");
changeProductPrice.ShouldBe("ChangeProductPrice");
discontinueProduct.ShouldBe("DiscontinueProduct");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public sealed partial class ErrorTests
[Fact]
public void Conflict_WithMessage_ReturnsConflictError()
{
// Arrange

// Act
Error error = Error.Conflict("Product already exists.");

Expand All @@ -19,6 +21,8 @@ public void Conflict_WithMessage_ReturnsConflictError()
[Fact]
public void Conflict_WithCodeAndMessage_ReturnsConflictError()
{
// Arrange

// Act
Error error = Error.Conflict(ErrorCodes.Conflict, "Product already exists.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public sealed partial class ErrorTests
[Fact]
public void ErrorCodeCreate_WithRegularValue_ReturnsCode()
{
// Arrange

// Act
ErrorCode code = ErrorCode.Create("custom_error");

Expand All @@ -20,6 +22,8 @@ public void ErrorCodeCreate_WithRegularValue_ReturnsCode()
[Fact]
public void ErrorCodeCreate_WithNoneValue_ReturnsNoneCode()
{
// Arrange

// Act
ErrorCode code = ErrorCode.Create("none");

Expand All @@ -34,6 +38,8 @@ public void ErrorCodeCreate_WithNoneValue_ReturnsNoneCode()
[InlineData("\t")]
public void ErrorCodeCreate_WithMissingValue_ThrowsArgumentException(string value)
{
// Arrange

// Act
Action action = () => ErrorCode.Create(value);

Expand All @@ -57,6 +63,8 @@ public void ErrorCodeFromDomain_WithDomainCode_PreservesCodeValue()
[Fact]
public void ErrorCodeFromDomain_WithNullDomainCode_ThrowsArgumentNullException()
{
// Arrange

// Act
Action action = () => ErrorCode.FromDomain(null!);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public sealed partial class ErrorTests
[Fact]
public void None_ReturnsNoneError()
{
// Arrange

// Act
Error error = Error.None;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public sealed partial class ErrorTests
[Fact]
public void NotFound_WithMessage_ReturnsNotFoundError()
{
// Arrange

// Act
Error error = Error.NotFound("Product was not found.");

Expand All @@ -19,6 +21,8 @@ public void NotFound_WithMessage_ReturnsNotFoundError()
[Fact]
public void NotFound_WithCodeAndMessage_ReturnsNotFoundError()
{
// Arrange

// Act
Error error = Error.NotFound(ErrorCodes.NotFound, "Product was not found.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public sealed partial class ErrorTests
[Fact]
public void Unknown_WithCodeAndMessage_ReturnsUnknownError()
{
// Arrange

// Act
Error error = Error.Unknown(ErrorCode.Create("unexpected_error"), "Unexpected error.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public sealed partial class ErrorTests
[Fact]
public void Validation_WithMessage_ReturnsValidationError()
{
// Arrange

// Act
Error error = Error.Validation("Invalid input.");

Expand All @@ -20,6 +22,8 @@ public void Validation_WithMessage_ReturnsValidationError()
[Fact]
public void Validation_WithCodeAndMessage_ReturnsValidationError()
{
// Arrange

// Act
Error error = Error.Validation(ErrorCodes.ProductNameRequired, "Product name is required.");

Expand All @@ -32,6 +36,8 @@ public void Validation_WithCodeAndMessage_ReturnsValidationError()
[Fact]
public void Validation_WithTarget_PreservesTarget()
{
// Arrange

// Act
Error error = Error.Validation(ErrorCodes.ProductNameRequired, "Product name is required.", "name");

Expand Down Expand Up @@ -67,6 +73,8 @@ public void Validation_WithDetails_PreservesDetails()
[Fact]
public void Validation_WithNoneCode_ThrowsArgumentException()
{
// Arrange

// Act
Action action = () => Error.Validation(ErrorCode.None, "Invalid input.");

Expand All @@ -80,6 +88,8 @@ public void Validation_WithNoneCode_ThrowsArgumentException()
[InlineData("\t")]
public void Validation_WithMissingCode_ThrowsArgumentException(string code)
{
// Arrange

// Act
Action action = () => Error.Validation(ErrorCode.Create(code), "Invalid input.");

Expand All @@ -93,6 +103,8 @@ public void Validation_WithMissingCode_ThrowsArgumentException(string code)
[InlineData("\t")]
public void Validation_WithMissingMessage_ThrowsArgumentException(string message)
{
// Arrange

// Act
Action action = () => Error.Validation(ErrorCodes.ValidationError, message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public sealed class DomainErrorTests
[Fact]
public void None_ReturnsNoneDomainError()
{
// Arrange

// Act
DomainError error = DomainError.None;

Expand All @@ -17,6 +19,8 @@ public void None_ReturnsNoneDomainError()
[Fact]
public void Create_WithCodeAndMessage_ReturnsDomainError()
{
// Arrange

// Act
DomainError error = DomainError.Create(
DomainErrorCodes.AmountNegative,
Expand All @@ -31,6 +35,8 @@ public void Create_WithCodeAndMessage_ReturnsDomainError()
[Fact]
public void Create_WithNullCode_ThrowsArgumentNullException()
{
// Arrange

// Act
Action action = () => DomainError.Create(null!, "Amount cannot be negative.");

Expand All @@ -41,6 +47,8 @@ public void Create_WithNullCode_ThrowsArgumentNullException()
[Fact]
public void Create_WithNoneCode_ThrowsArgumentException()
{
// Arrange

// Act
Action action = () => DomainError.Create(
DomainErrorCode.None,
Expand All @@ -56,6 +64,8 @@ public void Create_WithNoneCode_ThrowsArgumentException()
[InlineData("\t")]
public void Create_WithMissingMessage_ThrowsArgumentException(string message)
{
// Arrange

// Act
Action action = () => DomainError.Create(DomainErrorCodes.AmountNegative, message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ public void ClearDomainEvents_RemovesRecordedEvents()
[Fact]
public void TryCreate_WithValidValues_ReturnsTrueAndProduct()
{
// Arrange

// Act
bool result = Product.TryCreate(
"Keyboard",
Expand All @@ -333,6 +335,8 @@ public void TryCreate_WithValidValues_ReturnsTrueAndProduct()
[Fact]
public void TryCreate_WithMissingName_ReturnsFalseAndDomainError()
{
// Arrange

// Act
bool result = Product.TryCreate(
" ",
Expand All @@ -353,6 +357,8 @@ public void TryCreate_WithMissingName_ReturnsFalseAndDomainError()
[Fact]
public void TryCreate_WithInvalidPrice_ReturnsFalseAndDomainError()
{
// Arrange

// Act
bool result = Product.TryCreate(
"Keyboard",
Expand Down
Loading
Loading