feat(furniture-domain): enforce availability decision invariants
This commit is contained in:
parent
4af857b490
commit
c4149af23a
@ -4,6 +4,8 @@
|
|||||||
- Availability decision outcome remains unchanged for equivalent inputs.
|
- Availability decision outcome remains unchanged for equivalent inputs.
|
||||||
- Correlation propagation behavior remains unchanged.
|
- Correlation propagation behavior remains unchanged.
|
||||||
- Transport contracts stay stable at service boundary.
|
- Transport contracts stay stable at service boundary.
|
||||||
|
- Missing display names map to `Unknown Furniture`.
|
||||||
|
- Negative inventory quantities are clamped to `0`.
|
||||||
|
|
||||||
## Validation Approach
|
## Validation Approach
|
||||||
- Compare pre/post extraction contract examples.
|
- Compare pre/post extraction contract examples.
|
||||||
|
|||||||
@ -38,10 +38,17 @@ public sealed class FurnitureAvailabilityDecisionService : IFurnitureAvailabilit
|
|||||||
ProductContractResponse catalogResponse,
|
ProductContractResponse catalogResponse,
|
||||||
InventoryItemLookupResponse inventoryResponse)
|
InventoryItemLookupResponse inventoryResponse)
|
||||||
{
|
{
|
||||||
|
var displayName = string.IsNullOrWhiteSpace(catalogResponse.DisplayName)
|
||||||
|
? "Unknown Furniture"
|
||||||
|
: catalogResponse.DisplayName;
|
||||||
|
var quantityAvailable = inventoryResponse.QuantityAvailable < 0
|
||||||
|
? 0
|
||||||
|
: inventoryResponse.QuantityAvailable;
|
||||||
|
|
||||||
return new FurnitureAvailabilityDecisionResponse(
|
return new FurnitureAvailabilityDecisionResponse(
|
||||||
request.FurnitureId,
|
request.FurnitureId,
|
||||||
catalogResponse.DisplayName,
|
displayName,
|
||||||
inventoryResponse.QuantityAvailable);
|
quantityAvailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ResolveCorrelationId(string correlationId)
|
private static string ResolveCorrelationId(string correlationId)
|
||||||
|
|||||||
@ -51,4 +51,42 @@ public class FurnitureAvailabilityDecisionServiceTests
|
|||||||
Assert.Equal("Chair", response.DisplayName);
|
Assert.Equal("Chair", response.DisplayName);
|
||||||
Assert.Equal(12, response.QuantityAvailable);
|
Assert.Equal(12, response.QuantityAvailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ComposeResponse_WhenCatalogDisplayNameMissing_UsesFallbackName()
|
||||||
|
{
|
||||||
|
var service = new FurnitureAvailabilityDecisionService();
|
||||||
|
var request = new FurnitureAvailabilityDecisionRequest("FUR-004", "corr-004");
|
||||||
|
var catalog = new ProductContractResponse(
|
||||||
|
new CatalogContractEnvelope("1.0.0", "corr-004"),
|
||||||
|
"FUR-004",
|
||||||
|
string.Empty);
|
||||||
|
var inventory = new InventoryItemLookupResponse(
|
||||||
|
new InventoryContractEnvelope("1.0.0", "corr-004"),
|
||||||
|
"FUR-004",
|
||||||
|
5);
|
||||||
|
|
||||||
|
var response = service.ComposeResponse(request, catalog, inventory);
|
||||||
|
|
||||||
|
Assert.Equal("Unknown Furniture", response.DisplayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ComposeResponse_WhenInventoryNegative_ClampsQuantityToZero()
|
||||||
|
{
|
||||||
|
var service = new FurnitureAvailabilityDecisionService();
|
||||||
|
var request = new FurnitureAvailabilityDecisionRequest("FUR-005", "corr-005");
|
||||||
|
var catalog = new ProductContractResponse(
|
||||||
|
new CatalogContractEnvelope("1.0.0", "corr-005"),
|
||||||
|
"FUR-005",
|
||||||
|
"Shelf");
|
||||||
|
var inventory = new InventoryItemLookupResponse(
|
||||||
|
new InventoryContractEnvelope("1.0.0", "corr-005"),
|
||||||
|
"FUR-005",
|
||||||
|
-3);
|
||||||
|
|
||||||
|
var response = service.ComposeResponse(request, catalog, inventory);
|
||||||
|
|
||||||
|
Assert.Equal(0, response.QuantityAvailable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user