コード例 #1
0
        public void Register_FailedSave_ReturnsRedirect()
        {
            // arrange
            var accountController = new AccountController(
                new Mock<IFormsAuthenticationService>().Object,
                new Mock<IDataService<Volunteer>>().Object);

            accountController.ModelState.AddModelError("testRequired", "dummy required field missing");

            var fakeVolunteer = new Volunteer
                                    {
                                        FirstName = "Firstname",
                                        LastName = "LNameTest",
                                        Username = "******",
                                        Password = "******"
                                    };

            ActionResult result = accountController.Register(fakeVolunteer);

            Assert.IsInstanceOf<ViewResult>(result);

            var view = (ViewResult) result;

            Assert.IsInstanceOf<Volunteer>(view.Model);
        }
コード例 #2
0
        public void Constructor_Is_Valid()
        {
            var accountController = new AccountController(
                new Mock<IFormsAuthenticationService>().Object,
                new Mock<IDataService<Volunteer>>().Object);

            Assert.IsInstanceOf<Controller>(accountController);
        }
コード例 #3
0
        public void AccountController_LogOff_Returns_View()
        {
            var accountController = new AccountController(
                new Mock<IFormsAuthenticationService>().Object,
                new Mock<IDataService<Volunteer>>().Object);

            ActionResult result = accountController.LogOff();

            Assert.IsInstanceOf<ViewResult>(result);
        }
コード例 #4
0
        public void AccountController_LogOn_Returns_View()
        {
            // TODO check the data service to see if the login is valid.
            var accountController = new AccountController(
                new Mock<IFormsAuthenticationService>().Object,
                new Mock<IDataService<Volunteer>>().Object);

            ActionResult result = accountController.LogOn();

            //Assert.IsInstanceOf<ViewResult>(result);
            Assert.Inconclusive();
        }
コード例 #5
0
        public void Register_ReturnsView()
        {
            var accountController = new AccountController(
                new Mock<IFormsAuthenticationService>().Object,
                new Mock<IDataService<Volunteer>>().Object);

            ActionResult result = accountController.Register();

            Assert.IsInstanceOf<ViewResult>(result);
            var view = (ViewResult) result;
            Assert.IsNotNull(view.ViewData.Model);
            Assert.IsInstanceOf<Volunteer>(view.ViewData.Model);
        }
コード例 #6
0
        public void AccountController_LogOn_Post_Invalid_ModelState_Returns_View()
        {
            var accountController = new AccountController(
                new Mock<IFormsAuthenticationService>().Object,
                new Mock<IDataService<Volunteer>>().Object);

            accountController.ModelState.AddModelError("test", "error");

            var model = new LogOnViewModel();

            ActionResult result = accountController.LogOn(model, "home/index");

            Assert.IsInstanceOf<ViewResult>(result);
        }
コード例 #7
0
        public void AccountController_LogOn_Post_Valid_User_Redirects()
        {
            var accountController = new AccountController(
                new Mock<IFormsAuthenticationService>().Object,
                new Mock<IDataService<Volunteer>>().Object);

            var model = new LogOnViewModel
                            {
                                Username = "******",
                                Password = "******",
                                RememberMe = false,
                            };

            ActionResult result = accountController.LogOn(model, "home/index");

            Assert.IsInstanceOf<RedirectResult>(result);
        }
コード例 #8
0
        public void Register_Save_ReturnsRedirect()
        {
            var fakeVolunteer = new Volunteer
                                    {
                                        FirstName = "Firstname",
                                        LastName = "LNameTest",
                                        Username = "******",
                                        Password = "******",
                                        PrimaryPhone = "3334445555",
                                        Email = "*****@*****.**"
                                    };

            var dataService = new Mock<IDataService<Volunteer>>();

            dataService.Setup(d => d.Insert(fakeVolunteer, It.IsAny<Guid>())).Verifiable("Save was not called.");

            var accountController = new AccountController(
                new Mock<IFormsAuthenticationService>().Object,
                dataService.Object);

            ActionResult result = accountController.Register(fakeVolunteer);

            dataService.VerifyAll();

            Assert.IsInstanceOf<RedirectToRouteResult>(result);
        }
コード例 #9
0
        public void SignInPost_ValidUser_Redirects()
        {
            var model = new SignInViewModel
                            {
                                Username = "******",
                                Password = "******",
                                RememberMe = false,
                            };

            var fakeVolunteer = new Volunteer
                                    {
                                        Username = model.Username,
                                        Password = model.Password,
                                        Active = true,
                                    };

            var formsAuthenticationServiceMock = new Mock<IFormsAuthenticationService>();

            formsAuthenticationServiceMock.Setup(f => f.SetAuthCookie(It.IsAny<Volunteer>(), It.IsAny<bool>()))
                .Verifiable();

            var volunteerDataServiceMock = new Mock<IDataService<Volunteer>>();

            volunteerDataServiceMock.Setup(v => v.SelectOne(It.IsAny<Expression<Func<Volunteer, bool>>>()))
                .Returns(fakeVolunteer);

            volunteerDataServiceMock.Setup(v => v.HashPassword(It.IsAny<string>()))
                .Returns(model.Password);

            volunteerDataServiceMock.Setup(v => v.VerifyPassword(It.IsAny<string>(), It.IsAny<string>()))
                .Returns(true);

            var accountController = new AccountController(
                formsAuthenticationServiceMock.Object,
                volunteerDataServiceMock.Object);

            ActionResult result = accountController.SignIn(model, "home/index");

            Assert.IsInstanceOf<RedirectResult>(result);
        }