Пример #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"]);
        }