2장. 단위 테스트란 무엇인가
Last updated
Last updated
public void Purchase_fails_when_not_enough_inventory()
{
//준비
var store = new Store();
store.AddInventory(Product.shampoo, 10);
var customer = new Customer();
//실행
bool success = customer.Purchase(store, Product.Shampoo, 15);
//검증 (실패 했기에 수량 변화가 없음)
Assert.False(success);
Assert.Equals(10, store.GetInventory(Product.Shampoo));
}
public void Purchase_fails_when_not_enough_inventory()
{
//준비
var store = new Mock<IStore>();
storeMock
.Setup(x => x.HasEnoughInventory(Product.Shampoo, 5))
.Return(false)
var customer = new Customer();
//실행
bool success = customer.Purchase(storeMock.Object, Product.Shampoo, 5);
//검증 (실패 했기에 수량 변화가 없음)
Assert.False(success);
storeMock.Verify(
x => x.RemoveInventory(Product.Shampoo, 5),
Times.Never);
}