コード例 #1
0
        public void CakeOfTheWeek_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 cakeState             = false;
            var mockRepositoryWrapper = new Mock <IRepositoryWrapper>();

            mockRepositoryWrapper.Setup(repo => repo.Cake.GetCakeByIsCakeOfTheWeek(cakeState));
            var controller = new CakeController(mockRepositoryWrapper.Object);

            //Act
            var result = controller.CakeOfTheWeek(cakeState);

            //Assert
            Assert.Null(result.Result);
        }
コード例 #2
0
        public void CakeOfTheWeek_ReturnsIEnumerableCake_Success()
        {
            //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 cakeState             = true;
            var mockRepositoryWrapper = new Mock <IRepositoryWrapper>();

            mockRepositoryWrapper.Setup(repo => repo.Cake.GetCakeByIsCakeOfTheWeek(cakeState))
            .Returns(Task.FromResult(newCake));
            var controller = new CakeController(mockRepositoryWrapper.Object);

            //Act
            var result = controller.CakeOfTheWeek(cakeState);

            //Assert
            var ienumerableResult = Assert.IsAssignableFrom <IEnumerable <Cake> >(result.Result);

            Assert.NotNull(result.Result);
            Assert.Single(result.Result);
            Assert.Equal(result.Result.ToString(), newCake.ToString());
        }