public void Category_ReturnsIEnumerableCake_False() { //Arrange var newCake = new List <Cake> { new Cake { Id = 1, Name = "Royal Cake", Category = new Category { Id = 1, Name = "CiocolateCake" }, Description = "Best cake", ImageUrl = "/img/img1.jpg", IsCakeOfTheWeek = true, Price = 12, Stock = 10, Weigth = "100" } }; var mockRepositoryWrapper = new Mock <IRepositoryWrapper>(); mockRepositoryWrapper.Setup(repo => repo.Cake.CreateAsync(newCake.Find(x => x.Id == 1))); var controller = new CakeController(mockRepositoryWrapper.Object); //Act var result = controller.Category("PieceOfCake"); //Assert Assert.Null(result.Result); }
public void Category_ReturnsIEnumerableCake_Success() { //Arrange var newCake = new List <Cake> { new Cake { Id = 1, Name = "Royal Cake", Category = new Category { Id = 1, Name = "PieceOfCake" }, Description = "Best cake", ImageUrl = "/img/img1.jpg", IsCakeOfTheWeek = true, Price = 12, Stock = 10, Weigth = "100" } }; var mockRepositoryWrapper = new Mock <IRepositoryWrapper>(); mockRepositoryWrapper.Setup(repo => repo.Cake.GetCakeByCategoryName("PieceOfCake")) .Returns(Task.FromResult(newCake)); var controller = new CakeController(mockRepositoryWrapper.Object); //Act var result = controller.Category("PieceOfCake"); //Assert var ienumerableResult = Assert.IsAssignableFrom <IEnumerable <Cake> >(result.Result); Assert.Single(ienumerableResult); Assert.NotNull(result.Result); Assert.Single(result.Result); }