Пример #1
0
        public async void AddChildRecipe_ToInitializedDbTable_AddedRecipeEqualExpectedRecipe()
        {
            // arrange
            var recipes = GetRecipes();

            fixture.db.Add(recipes[0]);
            await fixture.db.SaveChangesAsync();

            int parentId = recipes[0].Id;
            var expected = recipes[1];

            // act
            await logic.AddChildDataModelAsync(expected, parentId);

            // assert
            var actualRecipe = await fixture.db.Recipe.FirstOrDefaultAsync(i => i.Id == expected.Id);

            var actualInheritance = await fixture.db.RecipeInheritance.FirstOrDefaultAsync(i => i.ParentId == parentId);

            Assert.Equal(expected.Id, actualRecipe.Id);
            Assert.Equal(expected.Content, actualRecipe.Content);
            Assert.Equal(expected.GovermentApproval, actualRecipe.GovermentApproval);
            Assert.Equal(expected.TechApproval, actualRecipe.TechApproval);

            Assert.Equal(expected.Id, actualInheritance.ChildId);
            Assert.Equal(parentId, actualInheritance.ParentId);
        }
Пример #2
0
        public async Task <IActionResult> AddChildSingleItem(Recipe model, int parentId)
        {
            var statusMessage = await logicValidation.CheckGetSingleDataModelAsync(parentId);

            if (statusMessage.IsCompleted)
            {
                var recipe = await logic.AddChildDataModelAsync(model, parentId);

                await logProvider.AddToLogAsync($"Added new recipe (Id: {recipe.Id}), which is child to recipe (Id: {parentId}).");

                return(RedirectToRoute(RecipesRouting.Index));
            }
            else
            {
                return(View("CustomError", statusMessage));
            }
        }