public async Task ResetPasswordInvokesUrlActionWithCorrectParametersWhenUserIsNotNull() { const string requestScheme = "requestScheme"; var mediator = new Mock<IMediator>(); var userManager = CreateApplicationUserMock(); var user = new ApplicationUser() { Id = "1234", Email = "*****@*****.**" }; mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id))) .Returns(user); string code = "passcode"; userManager.Setup(u => u.GeneratePasswordResetTokenAsync(user)).ReturnsAsync(code); var controller = new SiteController(userManager.Object, null, mediator.Object); var urlHelper = new Mock<IUrlHelper>(); controller.Url = urlHelper.Object; controller.SetFakeHttpRequestSchemeTo(requestScheme); var result = await controller.ResetPassword(user.Id); urlHelper.Verify(mock => mock.Action(It.Is<UrlActionContext>(uac => uac.Action == "ResetPassword" && uac.Controller == "Admin" && uac.Protocol == requestScheme)), Times.Once); }
public async Task EditUserPostInvokesUrlActionWithCorrectParametersWhenModelsIsOrganizationAdminIsTrueAndOrganizationAdminClaimWasAddedSuccessfully() { const string requestScheme = "requestScheme"; var mediator = new Mock<IMediator>(); var userManager = CreateApplicationUserMock(); EditUserViewModel model = new EditUserViewModel() { IsOrganizationAdmin = true, UserId = It.IsAny<string>() }; var user = new ApplicationUser() { Id = model.UserId, Email = "*****@*****.**" }; mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId))) .Returns(user); userManager.Setup(x => x.AddClaimAsync(It.IsAny<ApplicationUser>(), It.IsAny<Claim>())) .Returns(() => Task.FromResult(IdentityResult.Success)); var controller = new SiteController(userManager.Object, null, mediator.Object); controller.SetFakeHttpRequestSchemeTo(requestScheme); var urlHelper = new Mock<IUrlHelper>(); controller.Url = urlHelper.Object; await controller.EditUser(model); urlHelper.Verify(mock => mock.Action(It.Is<UrlActionContext>(uac => uac.Action == "Login" && uac.Controller == "Admin" && uac.Protocol == requestScheme)), Times.Once); }