Beispiel #1
0
        public async Task GetAllActiveCakes_ShouldReturnAllCakesNotDeleted()
        {
            //Arrange
            var db = this.SetDb();

            var repo = new Repository <Product>(db);

            var cakeModel1 = new CreateCakeViewModel {
                Name = "Chocolate Peanut Cake", CategoryId = 1, Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136591/Chocolate_and_Peanut_cake.jpg"
            };

            var cakeModel2 = new CreateCakeViewModel {
                Name = "Chocolate Drip Cake", CategoryId = 1, Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_Drip_cake.jpg"
            };

            var cakeService = new CakeService(null, repo, this.Mapper);

            await cakeService.AddCakeToDb(cakeModel1);

            await cakeService.AddCakeToDb(cakeModel2);

            var deleteCake = await repo.GetByIdAsync(1);

            deleteCake.IsDeleted = true;
            deleteCake.Category  = new Category {
                Id = 1, Type = Models.Enums.CategoryType.Cake
            };

            var activeCake = await repo.GetByIdAsync(2);

            activeCake.Category = new Category {
                Id = 1, Type = Models.Enums.CategoryType.Cake
            };
            await repo.SaveChangesAsync();

            //Act

            var allActiveCakes = cakeService.GetAllActiveCakes();

            var expectedCakesCount = 1;
            var actualCakesCount   = allActiveCakes.Count();

            //Assert
            Assert.Equal(expectedCakesCount, actualCakesCount);
        }