public void UsersController_Create_Invalid_Model_State()
        {
            // arrange
            _sut.ModelState.AddModelError("FirstName", "First name is required");
            var userView = new UserViewModel();

            // act
            var actual = _sut.Create(userView);

            // assert
            actual
                .AssertViewRendered()
                .ForView("New")
                .WithViewData<UserViewModel>()
                .ShouldBe(userView);
        }
        public void AutoMapAttribute_OnActionExecuted()
        {
            // arrange
            var user = new User();
            var userView = new UserViewModel();
            var filterContext = new ActionExecutedContext();
            _controller.ViewData.Model = user;
            filterContext.Controller = _controller;
            _mapperStub
                .Stub(x => x.Map(user, typeof(User), typeof(UserViewModel)))
                .Return(userView);

            // act
            _sut.OnActionExecuted(filterContext);

            // assert
            _controller.ViewData.Model.ShouldBe(userView);
        }
示例#3
0
        public void UserMapper_Map_From_UserViewModel_to_User()
        {
            // arrange
            var user = new UserViewModel
            {
                Id = 10,
                FirstName = "John",
                LastName = "Smith",
                Age = 56
            };

            // act
            var actual = (User)_sut.Map(user, typeof(UserViewModel), typeof(User));

            // assert
            actual.Id.ShouldBe(user.Id);
            actual.FirstName.ShouldBe(user.FirstName);
            actual.LastName.ShouldBe(user.LastName);
            actual.Age.ShouldBe(user.Age);
        }
        public void UsersController_Create_Success()
        {
            // arrange
            var userView = new UserViewModel();
            var user = new User();
            _userMapperStub
                .Stub(x => x.Map(userView, typeof(UserViewModel), typeof(User)))
                .Return(user);

            // act
            var actual = _sut.Create(userView);

            // assert
            actual
                .AssertActionRedirect()
                .ToAction<UsersController>(c => c.Index());
            _repositoryStub.AssertWasCalled(x => x.Save(user));
        }
        public void AutoMapAttribute_OnActionExecuted_Controller_Not_Implementing_IModelMapperController()
        {
            // arrange
            var user = new User();
            var userView = new UserViewModel();
            var filterContext = new ActionExecutedContext();

            // act
            _sut.OnActionExecuted(filterContext);

            // assert
            _mapperStub.AssertWasNotCalled(
                x => x.Map(null, null, null),
                x => x.IgnoreArguments()
            );
        }