# Testing Strategy Unit and integration testing for CQRS handlers. ## Unit Testing Handlers ```csharp public class PlaceOrderCommandHandlerTests { [Fact] public async Task Handle_ShouldCreateOrder() { // Arrange var repository = new Mock(); var handler = new PlaceOrderCommandHandler(repository.Object); var command = new PlaceOrderCommand { CustomerId = 1, Items = new List { new() { ProductId = 1, ProductName = "Widget", Quantity = 2, Price = 10.00m } } }; // Act var result = await handler.HandleAsync(command, CancellationToken.None); // Assert repository.Verify(r => r.AddAsync(It.IsAny(), It.IsAny()), Times.Once); } } ``` ## Integration Testing ```csharp public class OrderApiTests : IClassFixture> { private readonly HttpClient _client; public OrderApiTests(WebApplicationFactory factory) { _client = factory.CreateClient(); } [Fact] public async Task PlaceOrder_ShouldReturn201() { var command = new PlaceOrderCommand { CustomerId = 1, Items = new List { new() { ProductId = 1, ProductName = "Widget", Quantity = 2, Price = 10.00m } } }; var response = await _client.PostAsJsonAsync("/api/command/placeOrder", command); response.StatusCode.Should().Be(HttpStatusCode.Created); } } ``` ## See Also - [Modular Solution Overview](README.md) - [Testing Best Practices](../../best-practices/testing.md)