public void If_update_to_db_fails_return_default_view()
        {
            #region Arrange

            UserProfileController.ControllerContext = TestHelper.MockControllerContext(UserProfileController).WithAuthenticatedUser("test");
            UserProfileController.ValueProvider     = new FormCollection().ToValueProvider();

            using (Mock.Record())
            {
                Expect.Call(ProfileService.GetByName("test")).Return(Profile);
                Expect.Call(ProfileService.UpdateProfile(Profile)).Return(false);
            }

            #endregion

            #region Act
            ViewResult view;
            using (Mock.Playback())
            {
                view = (ViewResult)UserProfileController.Edit(null);
            }

            #endregion

            #region Assert
            Assert.IsEmpty(view.ViewName);
            Assert.That(view.ViewData.Model, Is.InstanceOf(typeof(ProfileModelDto)));
            Assert.That(view.ViewData["Error"], Is.EqualTo("Problem Updating Profile"));

            #endregion
        }
        public void Post_updates_profile_then_redirects_to_details_view()
        {
            #region Arrange

            UserProfileController.ControllerContext = TestHelper.MockControllerContext(UserProfileController)
                                                      .WithAuthenticatedUser("test");
            UserProfileController.ValueProvider = new FormCollection().ToValueProvider();

            using (Mock.Record())
            {
                Expect.Call(ProfileService.GetByName("test")).Return(Profile);
                Expect.Call(ProfileService.UpdateProfile(Profile)).Return(true);
            }

            #endregion

            #region Act

            RedirectToRouteResult redirect;
            using (Mock.Playback())
            {
                redirect = (RedirectToRouteResult)UserProfileController.Edit(null);
            }

            #endregion

            #region Assert
            redirect.AssertActionRedirect().ToAction("Details").WithParameter("id", 1);
            #endregion
        }
        public void Gets_profile_of_current_user_then_return_default_view()
        {
            #region Arrange
            UserProfileController.ControllerContext = TestHelper.MockControllerContext(UserProfileController)
                                                      .WithAuthenticatedUser("test");
            using (Mock.Record())
            {
                Expect.Call(ProfileService.GetByName("test")).Return(Profile);
            }

            #endregion

            #region Act

            ViewResult view;
            using (Mock.Playback())
            {
                view = (ViewResult)UserProfileController.Edit();
            }

            #endregion

            #region Assert
            Assert.IsEmpty(view.ViewName);
            Assert.That(view.ViewData.Model, Is.EqualTo(Profile));
            #endregion
        }
        public void Post_if_model_update_fails_then_adds_errormessage_and_returns_default_view()
        {
            #region Arrange

            UserProfileController.ControllerContext = TestHelper.MockControllerContext(UserProfileController).WithAuthenticatedUser("test");

            //Values that will fail
            UserProfileController.ValueProvider = new FormCollection
            {
                { "Email", "" }
            }
            .ToValueProvider();

            using (Mock.Record())
            {
                Expect.Call(ProfileService.GetByName("test")).Return(Profile);
                Expect.Call(ProfileService.UpdateProfile(Profile)).Repeat.Never();
            }

            #endregion

            #region Act
            ViewResult view;
            using (Mock.Playback())
            {
                view = (ViewResult)UserProfileController.Edit(null);
            }

            #endregion

            #region Assert
            Assert.IsEmpty(view.ViewName);
            Assert.That(view.ViewData.Model, Is.InstanceOf(typeof(ProfileModelDto)));
            Assert.That(view.ViewData["Error"], Is.EqualTo("Validation Error"));
            #endregion
        }