public void DetailRecipe_Test()
        {
            mockRepo.Setup(repo => repo.Recipe.FindByCondition(r => r.ID == It.IsAny <int>())).Returns(AllRecipes());
            var controllerActionResult = recipeController.Details(It.IsAny <int>());

            Assert.NotNull(controllerActionResult);
        }
示例#2
0
        public void RecipeDetails()
        {
            var controllerContext = new Mock <ControllerContext>();
            var principal         = new Mock <IPrincipal>();

            principal.Setup(p => p.IsInRole("Administrator")).Returns(true);
            principal.SetupGet(x => x.Identity.Name).Returns("rr");
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);
            controller.ControllerContext = controllerContext.Object;

            string[]   tags           = { "first", "second", "third" };
            ViewRecipe expectedRecipe = new ViewRecipe
            {
                Id               = 1,
                UserId           = "1",
                Text             = "Some text1",
                Likes            = 0,
                ImageUrl         = "Some url1",
                Name             = "Recipe1",
                Tags             = tags,
                IngridietsString = "first, second, third"
            };

            ViewResult result = controller.Details(1) as ViewResult;

            Assert.IsTrue(result.Model is ViewRecipe);
            Assert.AreEqual(expectedRecipe.Id, ((ViewRecipe)result.Model).Id);
        }