Пример #1
0
        public async Task GetByRecipeIdAsync_WithExistentRecipeId_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "RecipeAllergenService GetByRecipeIdAsync() 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 actualResult = (await recipeAllergenService
                                .GetByRecipeIdAsync(recipeId))
                               .ToList();
            var expectedResult = await context.RecipeAllergens
                                 .Where(x => x.RecipeId == recipeId)
                                 .To <RecipeAllergenServiceModel>()
                                 .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].AllergenId == actualResult[i].AllergenId, errorMessagePrefix + " " + "AllergenId is not returned properly.");
                Assert.True(expectedResult[i].Allergen.Name == actualResult[i].Allergen.Name, errorMessagePrefix + " " + "Allergen Name is not returned properly.");
            }
        }
Пример #2
0
        public async Task GetByRecipeIdAsync_WithNonExistentRecipeId_ShouldReturnEmptyCollection()
        {
            var errorMessagePrefix = "RecipeAllergenService GetByRecipeIdAsync() 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 actualResult   = (await recipeAllergenService.GetByRecipeIdAsync(nonExistentRecipeId)).Count;
            var expectedResult = 0;

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