コード例 #1
0
        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 void Details_ReturnsARecipe_WhenTheRecipeIDIsVald()
        {
            //Arrange
                    var adminController = new AdminController(session);

                    var recipe1 = session.Query<Recipe>().SingleOrDefault(x => x.Title == "Title1");
            //Act
                    ViewResult result = adminController.Details(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);
        }
コード例 #3
0
        public void Index_ReturnsListOfRecipes_WhenThereAreRecipesInDB()
        {
            //Arrange
                    var adminController = new AdminController(session);
            //Act
                    ViewResult result = adminController.Index() as ViewResult;
            //Assert
                    Assert.IsNotNull(result);

            //Act
                    var actual = result.Model as List<Recipe>;
                    var expected = session.Query<Recipe>().OrderBy(x => x.ID).ToList();
            //Assert
                    CollectionAssert.AreEqual(actual, expected);
        }