I have a class using an interface that has a void method similar to this witch, now a fully functional method:
public void SellGivenQuantityOfProduct(Product product, int quantity)
{
product.StockQuantity = product.StockQuantity - quantity;
}
But, working in the TDD way, I started to do it as shown below, but the calculation never happens in my test method
[TestMethod]
public void Can_Sell_Given_Quantity_Of_Single_Products_Stock_Quantity()
{
var mock = new Mock<ISellBuyPipeLine>();
mock.Setup(o => o.Products).Returns(new Product[]
{
new Product() {ArticleNr = 87, StockQuantity = 10}
});
var product = mock.Object.Products.First();
var choosenProductToSell = new SellBuyProduct() {Product = product, Quantity = 5};
mock.Object.SellGivenQuantityOfProduct(product, choosenProductToSell.Quantity);
int expectedSellValue = product.StockQuantity;
Assert.AreEqual(5, expectedSellValue);
}
If I use outcommented lines and fall into a class containing my method, it works right! But I want to use a layout.
What am I doing wrong?
Am I using the wrong approach?
source
share