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 GetByRecipeIdAsync_WithExistentRecipeId_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "RecipeLifestyleService GetByRecipeIdAsync() 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 actualResult = (await recipeLifestyleService
                                .GetByRecipeIdAsync(recipeId))
                               .ToList();
            var expectedResult = await context.RecipeLifestyles
                                 .Where(x => x.RecipeId == recipeId)
                                 .To <RecipeLifestyleServiceModel>()
                                 .ToListAsync();

            // Assert
            Assert.True(expectedResult.Count == actualResult.Count, errorMessagePrefix + " " + "Collections count mismatch.");

            for (int i = 0; i < actualResult.Count; i++)
            {
                Assert.True(expectedResult[i].RecipeId == actualResult[i].RecipeId, errorMessagePrefix + " " + "RecipeId is not returned properly.");
                Assert.True(expectedResult[i].Recipe.Title == actualResult[i].Recipe.Title, errorMessagePrefix + " " + "Recipe Title is not returned properly.");
                Assert.True(expectedResult[i].LifestyleId == actualResult[i].LifestyleId, errorMessagePrefix + " " + "LifestyleId is not returned properly.");
                Assert.True(expectedResult[i].Lifestyle.Type == actualResult[i].Lifestyle.Type, errorMessagePrefix + " " + "Lifestyle Type is not returned 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.");
        }
        public async Task GetByRecipeIdAsync_WithNonExistentRecipeId_ShouldReturnEmptyCollection()
        {
            var errorMessagePrefix = "RecipeLifestyleService GetByRecipeIdAsync() 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 actualResult   = (await recipeLifestyleService.GetByRecipeIdAsync(recipeId)).Count;
            var expectedResult = 0;

            // Assert
            Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Collections is not empty.");
        }