示例#1
0
        public async Task should_confirm_user_email_with_valid_token()
        {
            var user        = CreateNewUser();
            var tokenString = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            var confirmResult = await _userManager.ConfirmEmailAsync(user, tokenString);

            _app.ReloadEntity(user);
            Assert.True(confirmResult.Succeeded);
            Assert.True(user.EmailAddressConfirmed);
        }
        public async Task should_signin_user_and_redirect_when_signin_with_valid_user()
        {
            // Arrange
            ClaimsPrincipal signedInClaimsPrincipal = null;
            var             authService             = MockAuthService(principal => signedInClaimsPrincipal = principal);

            const string password = "******";

            _app.CreateUser("jim", password, "Jim Green");
            var userModel = new UserViewModel
            {
                UserName = "******",
                Password = password
            };

            // Act
            var accountCtrl = _app.CreateController <AccountController>();

            accountCtrl.TryValidateModel(userModel);
            var signinResult = await accountCtrl.DoSignin(userModel, null);

            // Assert
            Assert.True(accountCtrl.ModelState.IsValid);
            signinResult.IsType <RedirectResult>();

            authService.Verify();
            var signedInUser = signedInClaimsPrincipal.ToDiscussionUser(_app.GetService <IRepository <User> >());

            _app.ReloadEntity(signedInUser);
            Assert.Equal("jim", signedInUser.UserName);
            Assert.NotNull(signedInUser.LastSeenAt);
        }
示例#3
0
        public async Task should_update_display_name()
        {
            var user             = _theApp.MockUser();
            var settingViewModel = new UserSettingsViewModel
            {
                DisplayName = StringUtility.Random()
            };
            var userCtrl = _theApp.CreateController <UserController>();


            var result = await userCtrl.DoSettings(settingViewModel);


            ShouldBeRedirectResult(result);

            _theApp.ReloadEntity(user);
            Assert.Equal(settingViewModel.DisplayName, user.DisplayName);
            Assert.Null(user.EmailAddress);
            Assert.False(user.EmailAddressConfirmed);
        }