public async Task OnPostAsync_GivenInvalidModelState_ExpectRedirectToPageResult() { var mediator = new Mock <IMediator>(); var userQueries = new Mock <IUserQueries>(); var roleQueries = new Mock <IRoleQueries>(); var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>(); var page = new EditUser(userQueries.Object, mediator.Object, roleQueries.Object, currentAuthenticatedUserProvider.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 <UpdateUserCoreDetailsCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(ResultWithError.Fail(new ErrorData(ErrorCodes.SavingChanges))); var userQueries = new Mock <IUserQueries>(); var roleQueries = new Mock <IRoleQueries>(); var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>(); var page = new EditUser(userQueries.Object, mediator.Object, roleQueries.Object, currentAuthenticatedUserProvider.Object) { PageModel = new EditUser.Model() }; var result = await page.OnPostAsync(); Assert.IsType <RedirectToPageResult>(result); Assert.Equal(PrgState.Failed, page.PrgState); }
OnPostAsync_GivenValidModelStateAndCommandDoesExecute_ExpectRedirectToPageResultToViewUserPage() { var mediator = new Mock <IMediator>(); mediator.Setup(x => x.Send(It.IsAny <UpdateUserCoreDetailsCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(ResultWithError.Ok <ErrorData>()); var userQueries = new Mock <IUserQueries>(); var roleQueries = new Mock <IRoleQueries>(); var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>(); var page = new EditUser(userQueries.Object, mediator.Object, roleQueries.Object, currentAuthenticatedUserProvider.Object) { PageModel = new EditUser.Model() }; var result = await page.OnPostAsync(); var pageResult = Assert.IsType <RedirectToPageResult>(result); Assert.Equal(PageLocations.UserView, pageResult.PageName); }