public async Task OnPostAsync_GivenCommandSucceedsWithReturnUrl_ExpectUserToBeAuthenticatedAndRedirectedToUrl() { var mediator = new Mock <IMediator>(); mediator .Setup(x => x.Send( It.IsAny <ValidateAppMfaCodeAgainstCurrentUserCommand>(), It.IsAny <CancellationToken>())).ReturnsAsync(() => Result.Ok <ValidateAppMfaCodeAgainstCurrentUserCommandResult, ErrorData>( new ValidateAppMfaCodeAgainstCurrentUserCommandResult(TestVariables.UserId))); var authenticationService = new Mock <IAuthenticationService>(); authenticationService.Setup(x => x.SignInUserFromPartialStateAsync(It.IsAny <Guid>())) .ReturnsAsync("/some-page"); var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>(); var page = new ValidateAppMfaCode(mediator.Object, authenticationService.Object, currentAuthenticatedUserProvider.Object) { PageModel = new ValidateAppMfaCode.Model() }; Assert.IsType <LocalRedirectResult>(await page.OnPostAsync()); }
OnPostAsync_GivenCommandSucceedsWithNoReturnUrl_ExpectUserToBeAuthenticatedAndRedirectedToDashboard() { var mediator = new Mock <IMediator>(); mediator .Setup(x => x.Send( It.IsAny <ValidateAppMfaCodeAgainstCurrentUserCommand>(), It.IsAny <CancellationToken>())).ReturnsAsync(() => Result.Ok <ValidateAppMfaCodeAgainstCurrentUserCommandResult, ErrorData>( new ValidateAppMfaCodeAgainstCurrentUserCommandResult(TestVariables.UserId))); var authenticationService = new Mock <IAuthenticationService>(); authenticationService.Setup(x => x.SignInUserFromPartialStateAsync(It.IsAny <Guid>())) .ReturnsAsync(string.Empty); var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>(); var page = new ValidateAppMfaCode(mediator.Object, authenticationService.Object, currentAuthenticatedUserProvider.Object) { PageModel = new ValidateAppMfaCode.Model() }; var result = Assert.IsType <RedirectToPageResult>(await page.OnPostAsync()); Assert.Equal(PageLocations.AppDashboard, result.PageName); }
public async Task OnPostAsync_GivenInvalidModelState_ExpectRedirectToPageResult() { var mediator = new Mock <IMediator>(); var authenticationService = new Mock <IAuthenticationService>(); var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>(); var page = new ValidateAppMfaCode(mediator.Object, authenticationService.Object, currentAuthenticatedUserProvider.Object); page.ModelState.AddModelError("Error", "Error"); var result = await page.OnPostAsync(); Assert.IsType <RedirectToPageResult>(result); }
public async Task OnPostAsync_GivenCommandFails_ExpectRedirectToPageResultToSamePageAndPrgStateSet() { var mediator = new Mock <IMediator>(); mediator .Setup(x => x.Send( It.IsAny <ValidateAppMfaCodeAgainstCurrentUserCommand>(), It.IsAny <CancellationToken>())).ReturnsAsync(() => Result.Fail <ValidateAppMfaCodeAgainstCurrentUserCommandResult, ErrorData>( new ErrorData(ErrorCodes.SavingChanges))); var authenticationService = new Mock <IAuthenticationService>(); var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>(); var page = new ValidateAppMfaCode(mediator.Object, authenticationService.Object, currentAuthenticatedUserProvider.Object) { PageModel = new ValidateAppMfaCode.Model() }; var result = await page.OnPostAsync(); Assert.IsType <RedirectToPageResult>(result); Assert.Equal(PrgState.Failed, page.PrgState); }