public async Task OnPostAsync_GivenInvalidModelState_ExpectRedirectToPageResultToSelfAndNoCommandExecuted()
        {
            var mediator    = new Mock <IMediator>();
            var roleQueries = new Mock <IRoleQueries>();
            var page        = new EditRole(mediator.Object, roleQueries.Object);

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

            var result = await page.OnPostAsync();

            mediator.Verify(x => x.Send(It.IsAny <UpdateRoleCommand>(), It.IsAny <CancellationToken>()), Times.Never);
            Assert.IsType <RedirectToPageResult>(result);
        }
        public async Task OnPostAsync_GivenValidModelStateAndFailedResult_ExpectRedirectToPageResultToSelfAndPrgSet()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <UpdateRoleCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => ResultWithError.Fail(new ErrorData(ErrorCodes.SavingChanges)));
            var roleQueries = new Mock <IRoleQueries>();
            var page        = new EditRole(mediator.Object, roleQueries.Object)
            {
                PageModel = new EditRole.Model()
            };

            var result = await page.OnPostAsync();

            Assert.Equal(PrgState.Failed, page.PrgState);
            var actualResult = Assert.IsType <RedirectToPageResult>(result);

            Assert.True(string.IsNullOrWhiteSpace(actualResult.PageName));
        }
        OnPostAsync_GivenValidModelStateAndSuccessfulResult_ExpectRedirectToPageResultToViewPageAndIdSet()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <UpdateRoleCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(ResultWithError.Ok <ErrorData>());
            var roleQueries = new Mock <IRoleQueries>();
            var page        = new EditRole(mediator.Object, roleQueries.Object)
            {
                PageModel = new EditRole.Model {
                    RoleId = TestVariables.RoleId
                }
            };

            var result = await page.OnPostAsync();

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

            Assert.Equal(PageLocations.RoleView, actualResult.PageName);
            Assert.Equal(TestVariables.RoleId, actualResult.RouteValues["id"]);
        }