예제 #1
0
        public void CanGetToRegister()
        {
            // arrange
            Mock<IAccountServiceLayer> mockService = new Mock<IAccountServiceLayer>();
            Mock<IWebSecurityWrapper> mockSecurity = new Mock<IWebSecurityWrapper>();
            Mock<IEmailSender> mockEmail = new Mock<IEmailSender>();

            AccountController controller = new AccountController(mockService.Object, mockSecurity.Object, mockEmail.Object);

            // act
            var result = controller.Register();

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual(((ViewResult)result).ViewName, "Register");
            Assert.IsInstanceOfType(((ViewResult)result).Model, typeof(RegisterModel));
        }
예제 #2
0
        public void CanRegisterAsNewUser()
        {
            // arrange
            Mock<IAccountServiceLayer> mockService = new Mock<IAccountServiceLayer>();
            Mock<IWebSecurityWrapper> mockSecurity = new Mock<IWebSecurityWrapper>();
            Mock<IEmailSender> mockEmail = new Mock<IEmailSender>();

            //mockService.Setup(m => m.GetBusinessTypes()).Returns(new List<BusinessType> { new BusinessType { Id = 1, Name = "GC" }, new BusinessType { Id = 2, Name = "Vendor" } });

            mockSecurity.Setup(m => m.CreateUserAndAccount("*****@*****.**", "password", new
            {
                BusinessTypeId = 1,
                FirstName = "john",
                LastName = "smith",
                CompanyName = "asdf",
                PostalCode = "98074",
                Phone = "1231231234",
                OperatingDistance = 50
            }, true)).Returns("abc123");

            AccountController controller = new AccountController(mockService.Object, mockSecurity.Object, mockEmail.Object);

            // act
            var result = controller.Register(new RegisterModel
            {
                Email = "*****@*****.**",
                Password = "******",
                ConfirmPassword = "******",
                BusinessType = BusinessType.GeneralContractor,
                FirstName = "john",
                LastName = "smith",
                CompanyName = "asdf",
                PostalCode = "98074",
                Phone = "1231231234",
                OperatingDistance = 50
            }); ;

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.AreEqual("RegisterStepTwo", ((RedirectToRouteResult)result).RouteValues["action"]);
            Assert.AreEqual("Account", ((RedirectToRouteResult)result).RouteValues["controller"]);
        }
예제 #3
0
        public void CanSignIn()
        {
            // arrange
            Mock<IAccountServiceLayer> mockService = new Mock<IAccountServiceLayer>();
            Mock<IWebSecurityWrapper> mockSecurity = new Mock<IWebSecurityWrapper>();
            Mock<IEmailSender> mockEmail = new Mock<IEmailSender>();

            // security returns true when logging in a user
            mockSecurity.Setup(m => m.Login("*****@*****.**", "password", false)).Returns(true);

            AccountController controller = new AccountController(mockService.Object, mockSecurity.Object, mockEmail.Object);

            // act
            var result = controller.SignIn(new SignInModel { Email = "*****@*****.**", Password = "******", RememberMe = false }, "");

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.AreEqual("Index", ((RedirectToRouteResult)result).RouteValues["action"]);
            Assert.AreEqual("Home", ((RedirectToRouteResult)result).RouteValues["controller"]);
        }
예제 #4
0
        public void ResetPasswordWithUnknownEmailFails()
        {
            // arrange
            Mock<IAccountServiceLayer> mockService = new Mock<IAccountServiceLayer>();
            Mock<IWebSecurityWrapper> mockSecurity = new Mock<IWebSecurityWrapper>();
            Mock<IEmailSender> mockEmail = new Mock<IEmailSender>();

            mockSecurity.Setup(m => m.GetUserId("*****@*****.**")).Returns(-1);

            AccountController controller = new AccountController(mockService.Object, mockSecurity.Object, mockEmail.Object);

            // act
            var result = controller.ResetPassword(new ResetPasswordModel { ConfirmPassword = "******", NewPassword = "******", Email = "*****@*****.**", PasswordResetToken = "abc123" });

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsInstanceOfType(((ViewResult)result).Model, typeof(ResetPasswordModel));
            Assert.IsFalse(((ViewResult)result).ViewData.ModelState.IsValid);
            Assert.AreEqual("Unknown email address.", ((ViewResult)result).ViewData.ModelState["Email"].Errors[0].ErrorMessage);
        }
예제 #5
0
        public void ConfirmRegistrationCodeRedirectsToSuuccess()
        {
            // arrange
            Mock<IAccountServiceLayer> mockService = new Mock<IAccountServiceLayer>();
            Mock<IWebSecurityWrapper> mockSecurity = new Mock<IWebSecurityWrapper>();
            Mock<IEmailSender> mockEmail = new Mock<IEmailSender>();

            mockSecurity.Setup(m => m.ConfirmAccount("abcdef")).Returns(true);

            AccountController controller = new AccountController(mockService.Object, mockSecurity.Object, mockEmail.Object);

            // act
            var result = controller.RegisterConfirmation("abcdef");

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.AreEqual("ConfirmationSuccess", ((RedirectToRouteResult)result).RouteValues["action"]);
        }