public async Task GetRecipeIdsByLifestyleIdAsync_WithExistentLifestyleId_ShouldReturnCorrectResult() { var errorMessagePrefix = "RecipeLifestyleService GetRecipeIdsByLifestyleIdAsync() 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 lifestyleId = context.Lifestyles.First(x => x.Type == "Vegetarian").Id; // Act var actualResult = (await recipeLifestyleService .GetRecipeIdsByLifestyleIdAsync(lifestyleId)) .ToList(); var expectedResult = await context.RecipeLifestyles .Where(x => x.LifestyleId == lifestyleId) .Select(x => x.RecipeId) .ToListAsync(); // Assert Assert.True(expectedResult.Count == actualResult.Count, errorMessagePrefix + " " + "Collections count mismatch."); for (int i = 0; i < actualResult.Count; i++) { Assert.True(expectedResult[i] == actualResult[i], errorMessagePrefix + " " + "RecipeId is not returned properly."); } }
public async Task GetRecipeIdsByLifestyleIdAsync_WithNonExistentLifestyleId_ShouldReturnEmptyCollection() { var errorMessagePrefix = "RecipeLifestyleService GetRecipeIdsByLifestyleIdAsync() 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 nonExistentLifestyleId = 10000; // Act var actualResult = (await recipeLifestyleService .GetRecipeIdsByLifestyleIdAsync(nonExistentLifestyleId)) .Count; var expectedResult = 0; // Assert Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Collections is not empty."); }