public void GetCartItemById_WhenValidIdPassed_ReturnsCorrectCartItem() { //Arrange var moq = new Mock <IBookAsCartItemService>(); moq.Setup(i => i.GetOneCartItem(1)).Returns(DummyCartItem().FirstOrDefault(x => x.Id == 1)); //Act var controller = new BookAsCartItemController(moq.Object); var cart_Item = controller.GetCartItemById(1).Result as OkObjectResult; //Assert Assert.Equal(4, (cart_Item.Value as BookAsCartItemDTO).Quantity); }
public void GetCartItemById_WhenValidIdIsPassed_ReturnsOkResult() { //Arrange var moq = new Mock <IBookAsCartItemService>(); moq.Setup(x => x.GetOneCartItem(2)).Returns(DummyCartItem().FirstOrDefault(i => i.Id == 2)); //Act var controller = new BookAsCartItemController(moq.Object); var myResult = controller.GetCartItemById(2);//Id 2 is a valid id //Assert Assert.IsType <OkObjectResult>(myResult.Result); }