コード例 #1
0
        public void Test_Detail_By_Id()
        {
            //Arrange
            var moqService = new Moq.Mock<INerdDinnerService>();
            moqService.Setup(a => a.GetDinner(1)).Returns(GetSomeDinnerWithDinnerIdOfOne());
            var controller = new DinnerController(moqService.Object);

            //Act
            var result = controller.Detail(1) as PartialViewResult;
            var dinner = result.Model as Dinner;

            //Assert
            Assert.AreEqual(result.ViewName, "_DinnerDetails");
            Assert.AreEqual(dinner.DinnerId, 1);
        }
コード例 #2
0
        public void Test_Edit_By_Dinner_Id_Returns_Dinner()
        {
            // Arrange
            var moqService = new Moq.Mock<INerdDinnerService>();
            moqService.Setup(x => x.GetDinner(1)).Returns(GetSomeDinnerWithDinnerIdOfOne());

            DinnerController controller = new DinnerController(moqService.Object);

            // Act
            ViewResult result = controller.Edit(1) as ViewResult;
            var dinner = (Dinner)result.Model;

            // Assert
            Assert.AreEqual(dinner.DinnerId, 1);
        }
コード例 #3
0
        public void Test_Edit_Redirects_With_Incorrect_User()
        {
            // Arrange
            var moqService = new Moq.Mock<INerdDinnerService>();
            var expectedDinner = GetSomeDinnerWithDinnerIdOfOne();
            expectedDinner.CreatedBy = "system";
            moqService.Setup(a => a.GetDinner(expectedDinner.DinnerId)).Returns(expectedDinner);
            var context = new Mock<HttpContextBase>();
            context.SetupGet(p => p.User.Identity.Name).Returns("blablabla");
            var controller = new DinnerController(moqService.Object);
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);

            // Act
            var result = controller.Edit(expectedDinner.DinnerId) as RedirectToRouteResult;

            //Assert
            Assert.AreEqual(result.RouteValues["action"], "LogOn");
            Assert.AreEqual(result.RouteValues["controller"], "Account");
        }
コード例 #4
0
        public void Test_Edit_Redirects_With_Correct_User()
        {
            // Arrange
            var moqService = new Moq.Mock<INerdDinnerService>();
            var expectedDinner = GetSomeDinnerWithDinnerIdOfOne();
            expectedDinner.CreatedBy = "system";
            moqService.Setup(a => a.GetDinner(expectedDinner.DinnerId)).Returns(expectedDinner);
            var context = new Mock<HttpContextBase>();
            context.SetupGet(p => p.User.Identity.Name).Returns(expectedDinner.CreatedBy);
            var controller = new DinnerController(moqService.Object);
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);

            // Act
            var result = controller.Edit(expectedDinner.DinnerId) as ViewResult;

            //Assert
            Assert.IsNotNull(result);
        }