public async Task ConfirmEmailReturnsConfirmEmailView_WhenUsersEmailCanBeConfirmed() { const string userId = "userId"; const string token = "someToken"; var userManager = CreateUserManagerMock(); var user = new ApplicationUser(); userManager.Setup(x => x.FindByIdAsync(userId)).Returns(() => Task.FromResult(user)); userManager.Setup(x => x.ConfirmEmailAsync(user, token)).Returns(() => Task.FromResult(IdentityResult.Success)); var sut = new AccountController(userManager.Object, null, null, null, null); var result = await sut.ConfirmEmail(userId, token) as ViewResult; Assert.Equal(result.ViewName, "ConfirmEmail"); }
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))); }
public async Task ConfirmEmailInvokesConfirmEmailAsyncWithTheCorrectParameters_WhenUserAndUserIdAndTokenAreNotNull() { const string userId = "userId"; const string token = "someToken"; var userManager = CreateUserManagerMock(); var user = new ApplicationUser(); userManager.Setup(x => x.FindByIdAsync(userId)).Returns(() => Task.FromResult(user)); userManager.Setup(x => x.ConfirmEmailAsync(user, token)).Returns(() => Task.FromResult(IdentityResult.Success)); var sut = new AccountController(userManager.Object, null, null, null, null); await sut.ConfirmEmail(userId, token); userManager.Verify(x => x.ConfirmEmailAsync(It.Is<ApplicationUser>(y => y == user), It.Is<string>(y => y == token)), Times.Once); }
public async Task ConfirmEmailReturnsErrorView_WhenUserIsNull_AndUserIdAndTokenAreNotNull() { const string userId = "userId"; const string token = "someToken"; var userManager = CreateUserManagerMock(); userManager.Setup(x => x.FindByIdAsync(userId)).Returns(() => Task.FromResult((ApplicationUser)null)); var sut = new AccountController(userManager.Object, null, null, null, null); var result = await sut.ConfirmEmail(userId, token) as ViewResult; Assert.Equal("Error", result.ViewName); }
public async Task ConfirmEmailInvokesFindByIdAsyncWithCorrectUserId_WhenUserIdAndTokenAreNotNull() { const string userId = "userId"; const string token = "someToken"; var userManager = CreateUserManagerMock(); var sut = new AccountController(userManager.Object, null, null, null, null); await sut.ConfirmEmail(userId, token); userManager.Verify(x => x.FindByIdAsync(It.Is<string>(y => y == userId)), Times.Once); }
public async Task ConfirmEmailInvokesSendAsyncWithTheCorrectParametersWhenUsersProfileIsCompleteAndUsersEmailIsConfirmedAndUserAndUserIdAndTokenAreNotNull() { var userId = "userId"; var token = "someToken"; var userManager = CreateUserManagerMock(); var user = new ApplicationUser { Id = userId, FirstName = "first name", LastName = "last name", PhoneNumber = "test", 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 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, null, null, null, mediator.Object); sut.SetFakeUser(userId); await sut.ConfirmEmail(userId, token); mediator.Verify(x => x.SendAsync(It.Is<RemoveUserProfileIncompleteClaimCommand>(y => y.UserId == userId)), Times.Once); }