Ejemplo n.º 1
0
        public void CreateRecipe()
        {
            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;

            RecipeAddModel recipe = new RecipeAddModel
            {
                Id               = 10,
                UserId           = "10",
                Text             = "Some text10",
                ImageFile        = null,
                Name             = "Recipe10",
                IngridietsString = "first, second, third"
            };

            ViewResult result = controller.Create(recipe) as ViewResult;

            var added = db.FindRecipe(10);

            // Assert
            Assert.AreNotEqual(null, added);
        }
Ejemplo n.º 2
0
        public void Create_CreatesRecipe()
        {
            var expected = new Recipe
            {
                UserId = "test"
            };

            _mockUserRepo.Setup(s => s.GetByAuthId(It.IsAny <string>())).Returns(new User
            {
                Id     = 1,
                AuthId = "test"
            });

            var result = _controller.Create(expected) as OkResult;

            _mockRepo.Verify(s => s.CreateRecipe(expected, true), Times.Once);
            Assert.AreEqual(200, result?.StatusCode);
        }