public void Edit_ReturnsARecipeAndCanUpdateARecipe_WhenTheRecipeIDIsValid()
        {
            //Arrange
                    var adminController = new AdminController(session);

                    var recipe1 = session.Query<Recipe>().SingleOrDefault(x => x.Title == "Title1");
            //Act
                    ViewResult result = adminController.Edit(recipe1.ID) as ViewResult;

                    var actual = result.Model as Recipe;
                    var expected = session.Query<Recipe>().SingleOrDefault(x => x.ID == recipe1.ID);
            //Assert
                    Assert.AreEqual(actual, expected);

                    //update step
                    //in admin-mode all fields cand be updated
            //Arrange
                    var recipeToUpdate = new Recipe
                    {
                        Title = "UpdatedTitle",
                        Description = "UpdatedDescription",
                        ID = recipe1.ID,
                        isIncorrect = false
                    };
            //Act
                    ViewResult resultOnUpdate = adminController.Edit(recipe1.ID) as ViewResult;
                    var expectedAfterUpdate = recipeToUpdate;
                    adminController.Edit(recipeToUpdate);
                    var actualAfterUpdate = session.Query<Recipe>().SingleOrDefault(recipe => recipe.ID == recipeToUpdate.ID);
            //Assert
                    Assert.AreEqual(actualAfterUpdate, expectedAfterUpdate);
        }
예제 #2
0
 public ActionResult Create(Recipe recipe)
 {
     //if (!ModelState.IsValid)
     //    return View();
     recipe.ID = Guid.NewGuid();
     _documentSession.Store(recipe);
     TempData["Success"] = string.Format("Recipe {0} added successfully !", recipe.Title);
     return RedirectToAction("Index");
 }
예제 #3
0
        public ActionResult Edit(Recipe recipe)
        {
            var doc = _documentSession.Query<Recipe>().SingleOrDefault(recipeQuery => recipeQuery.ID == recipe.ID);
            doc.isIncorrect = recipe.isIncorrect;
            _documentSession.SaveChanges();
            TempData["Success"] = string.Format("Saved changes to Recipe {0}", recipe.Title);

            return RedirectToAction("Index");
        }
        public void Edit_ReturnsARecipeAndCanUpdateARecipe_WhenTheRecipeIDIsVali()
        {
            //Arrange
                    var homeController = new HomeController(session);

                    var recipe1 = session.Query<Recipe>().SingleOrDefault(x => x.Title == "Title1");
            //Act
                    ViewResult result = homeController.Edit(recipe1.ID) as ViewResult;
            //Assert
                    Assert.IsNotNull(result);

            //Act
                    var actual = result.Model as Recipe;
                    var expected = session.Query<Recipe>().SingleOrDefault(x => x.ID == recipe1.ID);
            //Assert
                    Assert.AreEqual(actual, expected);

                    //update step
            //Arrange
                    var updatedRecipe = new Recipe
                    {
                        Title = "Title1",
                        Description = "Description1",
                        ID = recipe1.ID,
                        //only the isIncorrect value cand be changet without being signed In
                        isIncorrect = false
                    };
            //Act
                    ViewResult resultOnUpdate = homeController.Edit(updatedRecipe) as ViewResult;

                    var expectedAfterUpdate = updatedRecipe;
                    homeController.Edit(updatedRecipe.ID);
                    var actualAfterUpdate = session.Query<Recipe>().SingleOrDefault(x => x.ID == updatedRecipe.ID);
             //Assert
                    Assert.AreEqual(actualAfterUpdate, expectedAfterUpdate);
        }
        public void InitialiseTest()
        {
            documentStore = new EmbeddableDocumentStore
            {
                RunInMemory = true
            };
            documentStore.Initialize();

            session = documentStore.OpenSession();
                    var recipe1 = new Recipe
                    {
                        Title = "Title1",
                        Description = "Description1",
                        ID = Guid.NewGuid(),
                        isIncorrect = false
                    };
                    session.Store(recipe1);

                    var recipe2 = new Recipe
                    {
                        Title = "Title2",
                        Description = "Description2",
                        ID = Guid.NewGuid(),
                        isIncorrect = true
                    };
                    session.Store(recipe2);

                    var recipe3 = new Recipe
                    {
                        Title = "Title3",
                        Description = "Description3",
                        ID = Guid.NewGuid(),
                        isIncorrect = false
                    };
                    session.Store(recipe3);

                    var recipe4 = new Recipe
                    {
                        Title = "Title4",
                        Description = "Description4",
                        ID = Guid.NewGuid(),
                        isIncorrect = true
                    };
                    session.Store(recipe4);
                    session.SaveChanges();
        }