Create() private method

private Create ( ) : System.Web.Mvc.ActionResult
return System.Web.Mvc.ActionResult
コード例 #1
0
        public void CreateAction_With_New_Dinner_Should_Return_View_And_Repo_Should_Contain_New_Dinner()
        {
            // Arrange
            var mock = new Mock<ControllerContext>();

            var nerdIdentity = FakeIdentity.CreateIdentity("SomeUser");
            var testData = FakeDinnerData.CreateTestDinners();
            var repository = new FakeDinnerRepository(testData);
            var controller = new DinnersController(repository);
            controller.ControllerContext = mock.Object;
            mock.SetupGet(p => p.HttpContext.User.Identity).Returns(nerdIdentity);

            var dinner = FakeDinnerData.CreateDinner();

            // Act
            ActionResult result = (ActionResult)controller.Create(dinner);

            // Assert
            Assert.AreEqual(102, repository.All.Count());
            Assert.IsInstanceOf<RedirectToRouteResult>(result);
        }
コード例 #2
0
        public void CreateAction_With_New_Dinner_Should_Return_View_And_Repo_Should_Contain_New_Dinner()
        {
            // Arrange
            var mock = new Mock<ControllerContext>();
            mock.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("ScottHa");
            mock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);

            var repository = new NhDinnerRepository(Session);

            var controller = new DinnersController(Session, repository);
            controller.ControllerContext = mock.Object;

            var dinner = FakeDinnerData.CreateDinner();

            // Act
            ActionResult result = controller.Create(dinner);

            // Assert
            Assert.AreEqual(101, repository.FindAllDinners().Count());
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
        }