public async Task GetRecipeIdsByAllergenIdsAsync_WithNonExistentAllergenIds_ShouldReturnEmptyCollection() { var errorMessagePrefix = "RecipeAllergenService GetRecipeIdsByAllergenIdsAsync() 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 nonExistentAllergenIds = new List <int>() { 10000, 10001 }; // Act var actualResult = (await recipeAllergenService .GetRecipeIdsByAllergenIdsAsync(nonExistentAllergenIds)) .Count; var expectedResult = 0; // Assert Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Collections is not empty."); }
public async Task GetRecipeIdsByAllergenIdsAsync_WithExistentAllergenIds_ShouldReturnCorrectResult() { var errorMessagePrefix = "RecipeAllergenService GetRecipeIdsByAllergenIdsAsync() 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 allergenIds = await context.Allergens.Select(x => x.Id).ToListAsync(); // Act var actualResult = (await recipeAllergenService .GetRecipeIdsByAllergenIdsAsync(allergenIds)) .ToList(); var expectedResult = await context.RecipeAllergens .Where(x => allergenIds.Contains(x.AllergenId)) .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."); } }