コード例 #1
0
        public void CreatePostAction_ModelStateValid_UpdateAndSaveAreCalled()
        {
            // arrange
            var                 mock       = new Mock <IArchitectRepository>();
            Architect           architect  = new Architect();
            ArchitectController controller = new ArchitectController(mock.Object);

            // act
            RedirectToRouteResult result = controller.Create(architect) as RedirectToRouteResult;

            // assert
            mock.Verify(a => a.Create(architect));
            mock.Verify(a => a.Save());
        }
コード例 #2
0
        public void CreatePostAction_ModelStateValid_RedirectToIndexView()
        {
            // arrange
            string expected = "Index";
            var    mock     = new Mock <IArchitectRepository>();

            Architect           architect  = new Architect();
            ArchitectController controller = new ArchitectController(mock.Object);

            // act
            RedirectToRouteResult result = controller.Create(architect) as RedirectToRouteResult;

            // assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result.RouteValues["action"]);
        }
コード例 #3
0
        public void CreatePostAction_ModelStateNotValid_ReturnCreateView()
        {
            // arrange
            string expected = "Create";
            var    mock     = new Mock <IArchitectRepository>();

            Architect           architect  = new Architect();
            ArchitectController controller = new ArchitectController(mock.Object);

            controller.ModelState.AddModelError("FirstName", "FirstName is required");

            // act
            ViewResult result = controller.Create(architect) as ViewResult;

            // assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result.ViewName);
        }