public void RedirectToCorrectActionResultWithCorrectRouteValues_WhenReturnUrlIsNotALocalUrl_AndUserIsOrgAdmin() { var applicationUser = new ApplicationUser(); applicationUser.MakeOrgAdmin(); //applicationUser.Claims.Add(new IdentityUserClaim<string> //{ // ClaimType = AllReady.Security.ClaimTypes.UserType, // ClaimValue = Enum.GetName(typeof(UserType), UserType.OrgAdmin) //}); var urlHelper = new Mock<IUrlHelper>(); urlHelper.Setup(x => x.IsLocalUrl(It.IsAny<string>())).Returns(false); var routeValueDictionary = new RouteValueDictionary { ["area"] = "Admin" }; var sut = new RedirectAccountControllerRequests(); var result = sut.RedirectToLocal(It.IsAny<string>(), applicationUser, urlHelper.Object) as RedirectToActionResult; Assert.Equal(result.ActionName, nameof(AllReady.Areas.Admin.Controllers.CampaignController.Index)); Assert.Equal(result.ControllerName, "Campaign"); Assert.Equal(result.RouteValues, routeValueDictionary); }
public async Task LoginPostReturnsErrorViewWithCorrectTextInViewData_WhenUserIsNotNull_AndUserIsAnOrgAdmin_AndUsersEmailIsNotConfirmed() { var applicationUser = new ApplicationUser(); applicationUser.MakeOrgAdmin(); var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<ApplicationUserQuery>())).ReturnsAsync(applicationUser); var userManager = MockHelper.CreateUserManagerMock(); userManager.Setup(x => x.IsEmailConfirmedAsync(applicationUser)).ReturnsAsync(false).Verifiable(); var signInManager = MockHelper.CreateSignInManagerMock(userManager); signInManager.Setup(x => x.PasswordSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())).ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Failed); var sut = new AccountController(userManager.Object, signInManager.Object, null, mediator.Object, null, null); var result = await sut.Login(new LoginViewModel()) as ViewResult; Assert.Equal(result.ViewData["Message"], "You must have a confirmed email to log on."); Assert.Equal(result.ViewName, "Error"); }
public async Task AssignOrganizationAdminGetRedirectsToCorrectActionWhenUserIsAnOrganizationAdmin() { var user = new ApplicationUser { Id = "1234" }; user.MakeOrgAdmin(); var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id))) .ReturnsAsync(user); var controller = new SiteController(null, null, mediator.Object); var result = (RedirectToActionResult) await controller.AssignOrganizationAdmin(user.Id); Assert.Equal("Index", result.ActionName); }
public async Task EditUserPostReturnsRedirectResultWithCorrectUrlWhenUserIsAnOrganizationAdminAndRemovClaimAsyncDoesNotSucceed() { var model = new EditUserViewModel { IsOrganizationAdmin = false, UserId = It.IsAny<string>() }; var user = new ApplicationUser { Id = model.UserId, Email = "*****@*****.**" }; user.MakeOrgAdmin(); var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId))).ReturnsAsync(user); var userManager = CreateApplicationUserMock(); userManager.Setup(x => x.RemoveClaimAsync(It.IsAny<ApplicationUser>(), It.IsAny<Claim>())).Returns(() => Task.FromResult(IdentityResult.Failed(null))); var controller = new SiteController(userManager.Object, null, mediator.Object); var result = await controller.EditUser(model); Assert.IsType<RedirectResult>(result); Assert.Equal("Error", ((RedirectResult)result).Url); }
public async Task EditUserPostInvokesRemoveClaimAsyncWithCorrectParameters_WhenUserIsAnOrganizationAdmin() { var model = new EditUserViewModel { IsOrganizationAdmin = false, UserId = It.IsAny<string>() }; var user = new ApplicationUser { Id = model.UserId, Email = "*****@*****.**" }; user.MakeOrgAdmin(); var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId))).ReturnsAsync(user); var userManager = CreateApplicationUserMock(); userManager.Setup(x => x.RemoveClaimAsync(It.IsAny<ApplicationUser>(), It.IsAny<Claim>())).Returns(() => Task.FromResult(IdentityResult.Success)); var controller = new SiteController(userManager.Object, null, mediator.Object); await controller.EditUser(model); userManager.Verify(x => x.RemoveClaimAsync(user, It.Is<Claim>(c => c.Value == "OrgAdmin")), Times.Once); }