Testing Strategies
Prerequisites: Entity Framework Core & databases
A unit test (xUnit, from Level 2) verifies one class in
isolation; an integration test verifies several real pieces
working together, often against ASP.NET Core's WebApplicationFactory
to spin up the whole app in-process for the test.
public class OrderServiceTests {
[Fact]
public void AppliesDiscountForLargeOrders() {
var emailSenderMock = new Mock<IEmailSender>(); // Moq — a mocking library
var service = new OrderService(emailSenderMock.Object);
double total = service.CalculateTotal(150.0);
Assert.Equal(135.0, total); // 10% off orders over 100
}
}
Moq stands in for a real dependency the same way Mockito does
in Java, letting OrderService's own logic be tested without a
real email provider.