コード例 #1
0
        public async Task DeletePreviousRecipeAllergensByRecipeId_WithExistentRecipeId_ShouldSuccessfullyDelete()
        {
            var errorMessagePrefix = "RecipeAllergenService DeletePreviousRecipeAllergensByRecipeId() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var recipeAllergenRepository = new EfRepository <RecipeAllergen>(context);
            var recipeAllergenService    = new RecipeAllergenService(recipeAllergenRepository);

            await this.SeedDataAsync(context);

            var recipeId = context.Recipes.First(x => x.Title == "Recipe with milk and eggs").Id;

            // Act
            var recipeAllergensCount = recipeAllergenRepository.All().Count();

            recipeAllergenService.DeletePreviousRecipeAllergensByRecipeId(recipeId);
            await recipeAllergenRepository.SaveChangesAsync();

            var actualResult   = recipeAllergenRepository.All().Count();
            var expectedResult = recipeAllergensCount - 2;

            // Assert
            Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count is not reduced properly.");
        }
コード例 #2
0
        public async Task DeletePreviousRecipeAllergensByRecipeId_WithNonExistentRecipeId_ShouldWorkProperly()
        {
            var errorMessagePrefix = "RecipeAllergenService DeletePreviousRecipeAllergensByRecipeId() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var recipeAllergenRepository = new EfRepository <RecipeAllergen>(context);
            var recipeAllergenService    = new RecipeAllergenService(recipeAllergenRepository);

            await this.SeedDataAsync(context);

            var nonExistentRecipeId = Guid.NewGuid().ToString();

            // Act
            var recipeAllergensCount = recipeAllergenRepository.All().Count();

            recipeAllergenService.DeletePreviousRecipeAllergensByRecipeId(nonExistentRecipeId);
            await recipeAllergenRepository.SaveChangesAsync();

            var actualResult   = recipeAllergenRepository.All().Count();
            var expectedResult = recipeAllergensCount;

            // Assert
            Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count does not match.");
        }