示例#1
0
        public async void EditMakesNewInstructions()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("EditMakesNewInstructions").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                Instructions recipe = new Instructions();
                recipe.RecipeID     = 1;
                recipe.StepNumberID = 2;
                recipe.Action       = "Boil water";
                Instructions recipe2 = new Instructions();
                recipe2.RecipeID     = 3;
                recipe2.StepNumberID = 4;
                recipe2.Action       = "Mash taters";
                Instructions edit = new Instructions();
                edit.RecipeID     = 5;
                edit.StepNumberID = 1;
                edit.Action       = "Beat eggs";

                //Act
                InstructionsController instructionsController = new InstructionsController(context, configuration);
                await instructionsController.Post(recipe);

                await instructionsController.Post(recipe2);

                var data = await instructionsController.Put(5, 1, edit);

                //Assert
                Assert.IsType <RedirectToActionResult>(data);
            }
        }
示例#2
0
        public async void CannotDeleteInstruction()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CannotDeleteInstruction").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                Instructions recipe = new Instructions();
                recipe.RecipeID     = 1;
                recipe.StepNumberID = 2;
                recipe.Action       = "Boil water";
                Instructions recipe2 = new Instructions();
                recipe2.RecipeID     = 3;
                recipe2.StepNumberID = 4;
                recipe2.Action       = "Mash taters";

                //Act
                InstructionsController instructionsController = new InstructionsController(context, configuration);
                await instructionsController.Post(recipe);

                await instructionsController.Post(recipe2);

                var result = await instructionsController.Delete(5, 5);

                //Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
示例#3
0
        public async void CanGetOneInstruction()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CanGetOneInstruction").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                Instructions recipe = new Instructions();
                recipe.RecipeID     = 1;
                recipe.StepNumberID = 2;
                recipe.Action       = "Boil water";
                Instructions recipe2 = new Instructions();
                recipe.RecipeID     = 2;
                recipe.StepNumberID = 1;
                recipe.Action       = "Mash taters";
                Instructions recipe3 = new Instructions();
                recipe.RecipeID     = 3;
                recipe.StepNumberID = 1;
                recipe.Action       = "Beat eggs";

                //Act
                InstructionsController InstructionsController = new InstructionsController(context, configuration);
                await InstructionsController.Post(recipe);

                await InstructionsController.Post(recipe2);

                await InstructionsController.Post(recipe3);

                var result = InstructionsController.Get(3, 1);

                //Assert
                Assert.IsType <OkObjectResult>(result);
            }
        }
示例#4
0
        public async void CanCreateInstructions()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CanCreateInstructions").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                Instructions recipe = new Instructions();
                recipe.RecipeID     = 1;
                recipe.StepNumberID = 2;
                recipe.Action       = "Boil water";

                //Act
                InstructionsController InstructionsController = new InstructionsController(context, configuration);
                await InstructionsController.Post(recipe);

                var result = await context.Instructions.FirstOrDefaultAsync(c => c.RecipeID == recipe.RecipeID);

                //Assert
                Assert.Equal(recipe, result);
            }
        }