public void OtherProductController_Post_ShouldReturnAllProducts() { // Arrange _mockService = new Mock <IOtherProductRepo>(); _mockService.Setup(x => x.GetOtherProductsFromRepo(It.IsAny <Product>())).Returns(_dataSource); OtherProductController controller = new OtherProductController(_mockService.Object); // Act IActionResult actionResult = controller.Post(_firstValue); // Assert var okResult = Assert.IsType <OkObjectResult>(actionResult); var contentResult = Assert.IsType <List <Product> >(okResult.Value); Assert.Equal(_firstValue.Name, contentResult.ToArray()[0].Name); Assert.Equal(_firstValue.Price, contentResult.ToArray()[0].Price); }
public void OtherProductController_Post_ShouldReturnAllProducts() { // Arrange _mockService = new Mock <IOtherProductRepo>(); _mockService.Setup(x => x.GetOtherProductsFromRepo(It.IsAny <Product>())).Returns(_dataSource); OtherProductController controller = new OtherProductController(_mockService.Object); // Act IHttpActionResult actionResult = controller.Post(_firstValue); var contentResult = actionResult as OkNegotiatedContentResult <IList <Product> >; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(_firstValue.Id, contentResult.Content[0].Id); Assert.AreEqual(_firstValue.Lib, contentResult.Content[0].Lib); }