84 lines
3.2 KiB
C#
84 lines
3.2 KiB
C#
using BuildingBlock.Catalog.Contracts.Conventions;
|
|
using BuildingBlock.Catalog.Contracts.Products;
|
|
using BuildingBlock.Catalog.Contracts.Responses;
|
|
using BuildingBlock.Inventory.Contracts.Conventions;
|
|
using BuildingBlock.Inventory.Contracts.Requests;
|
|
using BuildingBlock.Inventory.Contracts.Responses;
|
|
using Furniture.Service.Application.Adapters;
|
|
using Furniture.Service.Application.Ports;
|
|
using Furniture.Service.Application.UseCases;
|
|
using Furniture.Service.Contracts.UseCases;
|
|
|
|
namespace Furniture.Service.Application.UnitTests;
|
|
|
|
public class GetFurnitureAvailabilityUseCaseTests
|
|
{
|
|
[Fact]
|
|
public async Task HandleAsync_WhenCalled_DelegatesToReadPort()
|
|
{
|
|
var adapter = new FakeFurnitureAvailabilityContractAdapter();
|
|
var catalogPort = new FakeCatalogProductReadPort();
|
|
var inventoryPort = new FakeFurnitureAvailabilityReadPort();
|
|
var useCase = new GetFurnitureAvailabilityUseCase(adapter, catalogPort, inventoryPort);
|
|
|
|
var response = await useCase.HandleAsync(new GetFurnitureAvailabilityRequest("FUR-001", "corr-123"));
|
|
|
|
Assert.Equal("FUR-001", response.FurnitureId);
|
|
Assert.Equal("Chair", response.DisplayName);
|
|
Assert.Equal(10, response.QuantityAvailable);
|
|
}
|
|
|
|
private sealed class FakeFurnitureAvailabilityContractAdapter : IFurnitureAvailabilityContractAdapter
|
|
{
|
|
public ProductContract ToCatalogRequest(GetFurnitureAvailabilityRequest request)
|
|
{
|
|
return new ProductContract(
|
|
new CatalogContractEnvelope("1.0.0", request.CorrelationId),
|
|
request.FurnitureId,
|
|
string.Empty);
|
|
}
|
|
|
|
public InventoryItemLookupRequest ToInventoryRequest(GetFurnitureAvailabilityRequest request)
|
|
{
|
|
return new InventoryItemLookupRequest(
|
|
new InventoryContractEnvelope("1.0.0", request.CorrelationId),
|
|
request.FurnitureId);
|
|
}
|
|
|
|
public GetFurnitureAvailabilityResponse ToServiceResponse(
|
|
GetFurnitureAvailabilityRequest request,
|
|
ProductContractResponse catalogResponse,
|
|
InventoryItemLookupResponse inventoryResponse)
|
|
{
|
|
return new GetFurnitureAvailabilityResponse(
|
|
request.FurnitureId,
|
|
catalogResponse.DisplayName,
|
|
inventoryResponse.QuantityAvailable);
|
|
}
|
|
}
|
|
|
|
private sealed class FakeCatalogProductReadPort : ICatalogProductReadPort
|
|
{
|
|
public Task<ProductContractResponse> ReadProductAsync(ProductContract request)
|
|
{
|
|
return Task.FromResult(
|
|
new ProductContractResponse(
|
|
new CatalogContractEnvelope("1.0.0", request.Envelope.CorrelationId),
|
|
request.ProductId,
|
|
"Chair"));
|
|
}
|
|
}
|
|
|
|
private sealed class FakeFurnitureAvailabilityReadPort : IFurnitureAvailabilityReadPort
|
|
{
|
|
public Task<InventoryItemLookupResponse> ReadAvailabilityAsync(InventoryItemLookupRequest request)
|
|
{
|
|
return Task.FromResult(
|
|
new InventoryItemLookupResponse(
|
|
new InventoryContractEnvelope("1.0.0", request.Envelope.CorrelationId),
|
|
request.ItemCode,
|
|
10));
|
|
}
|
|
}
|
|
}
|