示例#1
0
 public LoginPageViewModel(LoginRegistrationPage currentPage, string returnUrl)
 {
     CurrentPage    = currentPage;
     LoginViewModel = new InternalLoginViewModel()
     {
         ReturnUrl = returnUrl
     };
     RegisterAccountViewModel = new RegisterAccountViewModel
     {
         Address = new AddressModel()
     };
 }
        public void RegisterAccount_WhenRegisterSuccessful_ShouldReturnJsonReturnUrl()
        {
            var identityResult = new IdentityResult();
            typeof(IdentityResult).GetProperty("Succeeded").SetValue(identityResult, true, null);

            _userServiceMock.Setup(
                x => x.RegisterAccount(It.IsAny<ApplicationUser>()))
                .Returns(Task.FromResult(new ContactIdentityResult
                (
                    identityResult,
                    CustomerContact.CreateInstance()
                )));

            var model = new RegisterAccountViewModel
            {
                Email = "*****@*****.**",
                Newsletter = true,
                Password = "******",
                Password2 = "Passwors@124#212",
            };

            model.Address = new Address
            {
                Line1 = "Address",
                City = "City",
                CountryName = "Country",
                FirstName = "Fisrt Name",
                LastName = "Last Name",
                PostalCode = "952595",
                Email = "*****@*****.**"
            };

            var result = _subject.RegisterAccount(model).Result as JsonResult;

            var expectedResult = new JsonResult
            {
                Data = new { ReturnUrl = "/" },
                JsonRequestBehavior = JsonRequestBehavior.DenyGet
            };

            result.ShouldBeEquivalentTo(expectedResult);
        }
        public void RegisterAccount_WhenRegisterFails_ShouldReturnModelErrorState()
        {
            _userServiceMock.Setup(
                x => x.RegisterAccount(It.IsAny<ApplicationUser>()))
                .Returns(Task.FromResult(new ContactIdentityResult
                (
                    new IdentityResult("We have an error"),
                    CustomerContact.CreateInstance()
                )));

            var model = new RegisterAccountViewModel
            {
                Email = "*****@*****.**",
                Newsletter = true,
                Password = "******",
                Password2 = "Passwors@124#212",
            };

            model.Address = new Address
            {
                Line1 = "Address",
                City = "City",
                CountryName = "Country",
                FirstName = "Fisrt Name",
                LastName = "Last Name",
                PostalCode = "952595",
                HtmlFieldPrefix = "Address"
            };

            var result = _subject.RegisterAccount(model);

            _subject.ModelState.Values.First().Errors.First().ErrorMessage.Should().Be("We have an error");
        }