public async Task OnPostAsync_GivenInvalidModelState_ExpectRedirectToPageResult() { var mediator = new Mock <IMediator>(); var roleQueries = new Mock <IRoleQueries>(); var page = new CreateUser(mediator.Object, roleQueries.Object); page.ModelState.AddModelError("Error", "Error"); var result = await page.OnPostAsync(); Assert.IsType <RedirectToPageResult>(result); }
OnPostAsync_GivenValidModelStateAndCommandDoesNotExecute_ExpectRedirectToPageResultAndPrgStateSetToFailed() { var mediator = new Mock <IMediator>(); mediator.Setup(x => x.Send(It.IsAny <CreateUserCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(Result.Fail <CreateUserCommandResult, ErrorData>(new ErrorData(ErrorCodes.SavingChanges))); var roleQueries = new Mock <IRoleQueries>(); var page = new CreateUser(mediator.Object, roleQueries.Object) { PageModel = new CreateUser.Model() }; var result = await page.OnPostAsync(); Assert.IsType <RedirectToPageResult>(result); Assert.Equal(PrgState.Failed, page.PrgState); }
OnPostAsync_GivenValidModelStateAndCommandExecutes_ExpectRedirectToPageResultAndPrgStateSetToSuccess() { var mediator = new Mock <IMediator>(); mediator.Setup(x => x.Send(It.IsAny <CreateUserCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(Result.Ok <CreateUserCommandResult, ErrorData>(new CreateUserCommandResult(TestVariables.UserId))); var roleQueries = new Mock <IRoleQueries>(); var page = new CreateUser(mediator.Object, roleQueries.Object) { PageModel = new CreateUser.Model() }; var result = await page.OnPostAsync(); var pageResult = Assert.IsType <RedirectToPageResult>(result); Assert.Equal(PageLocations.UserView, pageResult.PageName); }