public async Task OnGetAsync_GivenRoleIsInSystemAndPageModelIsNotNull_ExpectPageModelSetAndPageResultReturned() { var mediator = new Mock <IMediator>(); var roleQueries = new Mock <IRoleQueries>(); roleQueries.Setup(x => x.GetDetailsOfRoleById(It.IsAny <Guid>())) .ReturnsAsync(() => Maybe.From(new DetailedRoleModel( TestVariables.RoleId, "old-name", new List <Guid> { TestVariables.ResourceId }))); var page = new EditRole(mediator.Object, roleQueries.Object) { PageModel = new EditRole.Model { RoleId = TestVariables.RoleId, Name = "name", Resources = new List <Guid> { TestVariables.ResourceId }, }, }; var result = await page.OnGetAsync(); Assert.IsType <PageResult>(result); Assert.Equal(TestVariables.RoleId, page.PageModel.RoleId); Assert.Equal("name", page.PageModel.Name); Assert.Equal("old-name", page.Name); Assert.Single(page.PageModel.Resources); }
public async Task OnGetAsync_GivenRoleIsNotInSystem_ExpectNotFoundResultReturned() { var mediator = new Mock <IMediator>(); var roleQueries = new Mock <IRoleQueries>(); roleQueries.Setup(x => x.GetDetailsOfRoleById(It.IsAny <Guid>())) .ReturnsAsync(() => Maybe <DetailedRoleModel> .Nothing); var page = new EditRole(mediator.Object, roleQueries.Object); var result = await page.OnGetAsync(); Assert.IsType <NotFoundResult>(result); }