示例#1
0
        public async Task ConfirmEmailInvokesRefreshSignInAsyncWithTheCorrectParameters_WhenUserIsSignedIn_AndUsersProfileIsComplete_AndUsersEmailIsConfirmed_AndUserAndUserIdAndTokenAreNotNull()
        {
            const string userId = "userId";
            const string token = "someToken";
            var userManager = CreateUserManagerMock();

            var user = new ApplicationUser
            {
                Id = userId,
                FirstName = "first name",
                LastName = "last name",
                PhoneNumber = "111-111-1111",
                PhoneNumberConfirmed = true,
                Email = "*****@*****.**",
                EmailConfirmed = true
            };
            userManager.Setup(x => x.FindByIdAsync(userId)).Returns(() => Task.FromResult(user));
            userManager.Setup(x => x.ConfirmEmailAsync(user, token)).Returns(() => Task.FromResult(IdentityResult.Success));

            var signInManager = CreateSignInManagerMock(userManager);
            signInManager.Setup(x => x.RefreshSignInAsync(user)).Returns(() => Task.FromResult(It.IsAny<Task>()));

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(new RemoveUserProfileIncompleteClaimCommand { UserId = user.Id })).Returns(() => Task.FromResult(It.IsAny<Unit>()));

            var sut = new AccountController(userManager.Object, signInManager.Object, null, mediator.Object, null);
            sut.SetFakeUserWithCookieAuthenticationType(userId);
            await sut.ConfirmEmail(userId, token);

            signInManager.Verify(x => x.RefreshSignInAsync(It.Is<ApplicationUser>(y => y.Id == user.Id)));
        }