public async Task OnPostAsync_GivenInvalidModelState_ExpectRedirectToPageResult()
        {
            var mediator = new Mock <IMediator>();

            var authServiceMock = new Mock <IAuthenticationService>();

            var page = new UserAuthentication(mediator.Object, authServiceMock.Object);

            page.ModelState.AddModelError("Error", "Error");

            var result = await page.OnPostAsync();

            Assert.IsType <RedirectToPageResult>(result);
        }
        OnPostAsync_GivenInvalidModelStateAndReturnUrlIsNotEmpty_ExpectRedirectToPageResultWithRedirectUrl()
        {
            var mediator        = new Mock <IMediator>();
            var authServiceMock = new Mock <IAuthenticationService>();

            var page = new UserAuthentication(mediator.Object, authServiceMock.Object);

            page.ModelState.AddModelError("Error", "Error");

            page.ReturnUrl = "some-url";

            var result = await page.OnPostAsync();

            var pageResult = Assert.IsType <RedirectToPageResult>(result);

            Assert.Equal("some-url", pageResult.RouteValues["ReturnUrl"]);
        }
        OnPostAsync_GivenSuccessfulExecutionAndMfaIsEmail_ExpectPartialAuthenticationAndRedirectEmailMfaPage()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <AuthenticateUserCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() =>
                          Result.Ok <AuthenticateUserCommandResult, ErrorData>(new AuthenticateUserCommandResult(TestVariables.UserId, BaseAuthenticationProcessCommandResult.AuthenticationState.AwaitingMfaEmailCode, MfaProvider.Email)));
            var authenticationService = new Mock <IAuthenticationService>();

            var page = new UserAuthentication(mediator.Object, authenticationService.Object)
            {
                PageModel = new UserAuthentication.Model(),
                ReturnUrl = "some-url",
            };

            var result = Assert.IsType <RedirectToPageResult>(await page.OnPostAsync());

            Assert.Equal(PageLocations.AuthEmailMfa, result.PageName);
        }
        public async Task OnPostAsync_GivenCommandFailure_ExpectRedirectToPageResultToSamePageAndPrgStateSet()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <AuthenticateUserCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() =>
                          Result.Fail <AuthenticateUserCommandResult, ErrorData>(new ErrorData(ErrorCodes.SavingChanges)));
            var authenticationService = new Mock <IAuthenticationService>();

            var page = new UserAuthentication(mediator.Object, authenticationService.Object)
            {
                PageModel = new UserAuthentication.Model()
            };

            var result = await page.OnPostAsync();

            Assert.IsType <RedirectToPageResult>(result);
            Assert.Equal(PrgState.Failed, page.PrgState);
        }
        OnPostAsync_GivenSuccessfulExecutionAndMfaIsDevice_ExpectPartialAuthenticationAndRedirectDeviceMfaPage()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <AuthenticateUserCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() =>
                          Result.Ok <AuthenticateUserCommandResult, ErrorData>(new AuthenticateUserCommandResult(TestVariables.UserId, MfaProvider.Device, new AssertionOptions())));
            var authenticationService = new Mock <IAuthenticationService>();

            var page = new UserAuthentication(mediator.Object, authenticationService.Object)
            {
                PageModel = new UserAuthentication.Model(),
                ReturnUrl = "some-url",
            };
            var tempDataDictionary = new Mock <ITempDataDictionary>();

            page.TempData = tempDataDictionary.Object;

            var result = Assert.IsType <RedirectToPageResult>(await page.OnPostAsync());

            Assert.Equal(PageLocations.AuthDeviceMfa, result.PageName);
        }