public async Task DeletePreviousRecipeLifestylesByRecipeId_WithExistentRecipeId_ShouldSuccessfullyDelete() { var errorMessagePrefix = "RecipeLifestyleService DeletePreviousRecipeLifestylesByRecipeId() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var recipeLifestyleRepository = new EfRepository <RecipeLifestyle>(context); var recipeLifestyleService = new RecipeLifestyleService(recipeLifestyleRepository); await this.SeedDataAsync(context); var recipeId = context.Recipes.First(x => x.Title == "Recipe for vegetarians and vegans").Id; // Act var recipeLifestylesCount = recipeLifestyleRepository.All().Count(); recipeLifestyleService.DeletePreviousRecipeLifestylesByRecipeId(recipeId); await recipeLifestyleRepository.SaveChangesAsync(); var actualResult = recipeLifestyleRepository.All().Count(); var expectedResult = recipeLifestylesCount - 2; // Assert Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count is not reduced properly."); }
public async Task DeletePreviousRecipeLifestylesByRecipeId_WithNonExistentRecipeId_ShouldWorkProperly() { var errorMessagePrefix = "RecipeLifestyleService DeletePreviousRecipeLifestylesByRecipeId() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var recipeLifestyleRepository = new EfRepository <RecipeLifestyle>(context); var recipeLifestyleService = new RecipeLifestyleService(recipeLifestyleRepository); await this.SeedDataAsync(context); var recipeId = Guid.NewGuid().ToString(); // Act var recipeAllergensCount = recipeLifestyleRepository.All().Count(); recipeLifestyleService.DeletePreviousRecipeLifestylesByRecipeId(recipeId); await recipeLifestyleRepository.SaveChangesAsync(); var actualResult = recipeLifestyleRepository.All().Count(); var expectedResult = recipeAllergensCount; // Assert Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count does not match."); }