public async Task Test_SubtaskSearchQuery_DefaultCriteria_Should_ReturnAll() { // arrange var job = new JobFaker().Generate(); var tasks = new SubtaskFaker().SetJob(job).Generate(100); await using var dbContext = GetDbContext(); await dbContext.Setup(x => x.Jobs, job); await dbContext.Setup(x => x.Tasks, tasks); var search = new SubtaskSearchCriteria() { }; var paging = new PagingCriteria() { Page = 1, Size = 25 }; // act var results = await new SubtaskSearchQuery(dbContext).Find(search, paging); // assert results.Should().NotBeNull(); results.Page.Should().Be(1); results.Size.Should().Be(25); results.TotalItems.Should().Be(100); results.TotalPages.Should().Be(4); results.Data.Should().HaveCount(25); results.Data.Should().OnlyHaveUniqueItems(x => x.TaskId); }
public async Task <IResult <PagedResult <SubtaskSearchResult> > > ListTasks(SubtaskSearchCriteria criteria, PagingCriteria paging) { var query = new SubtaskSearchQuery(_dbContext); var results = await query.Find(criteria, paging); return(Result.Ok(results)); }
public async Task Test_SubtaskSearchQuery_TinyPageSize_Should_ReturnPagedResult() { // arrange var job = new JobFaker().Generate("default,InProgress"); var tasks = new SubtaskFaker().SetJob(job).Generate(100); await using var dbContext = GetDbContext(); await dbContext.Setup(x => x.Jobs, job); await dbContext.Setup(x => x.Tasks, tasks); var search = new SubtaskSearchCriteria(); var paging = new PagingCriteria() { Page = 1, Size = 5 }; // act var results = await new SubtaskSearchQuery(dbContext).Find(search, paging); // assert results.Should().NotBeNull(); results.Page.Should().Be(1); results.Size.Should().Be(5); results.TotalItems.Should().Be(100); results.TotalPages.Should().Be(20); results.Data.Should().HaveCount(5); }
public async Task Test_SubtaskSearchQuery_FindByJobId_None_Should_ReturnEmpty() { // arrange var job = new JobFaker().Generate("default,InProgress"); var tasks = new SubtaskFaker().SetJob(job).Generate(17); await using var dbContext = GetDbContext(); await dbContext.Setup(x => x.Jobs, job); await dbContext.Setup(x => x.Tasks, tasks); var search = new SubtaskSearchCriteria() { JobId = Guid.Empty }; var paging = new PagingCriteria() { Page = 1, Size = 25 }; // act var results = await new SubtaskSearchQuery(dbContext).Find(search, paging); // assert results.Should().NotBeNull(); results.Page.Should().Be(1); results.Size.Should().Be(25); results.TotalItems.Should().Be(0); results.TotalPages.Should().Be(0); results.Data.Should().BeNullOrEmpty(); }
public async Task Test_ListTasks_FindAll_Should_ReturnPagedList() { // arrange var job = new JobFaker().Generate("default,InProgress"); var tasks = new SubtaskFaker().SetJob(job).Generate(100); await using var context = DbContextFactory.Instance.CreateDbContext <PortAuthorityDbContext>(); await context.Setup(x => x.Jobs, job); await context.Setup(x => x.Tasks, tasks); var search = new SubtaskSearchCriteria() { }; var paging = new PagingCriteria() { Page = 1, Size = 25 }; // act var result = await _service.ListTasks(search, paging); // assert result.Should().NotBeNull(); result.IsOk().Should().BeTrue(); var payload = result.Payload; payload.TotalItems.Should().Be(100); payload.TotalPages.Should().Be(4); payload.Data.Should().HaveCount(25); }
public async Task <IActionResult> ListTasks([FromQuery] SubtaskSearchCriteria search, [FromQuery] PagingCriteria paging) { _logger.LogInformation("Finding all jobs for criteria = [{Criteria}]", search); _logger.LogInformation("Page = [{Paging}]", paging); var result = await _subtaskService.ListTasks(search, paging); return(Ok(result.Payload)); }
public async Task Test_SubtaskSearchQuery_NoData_Should_ReturnEmptyResult() { // arrange var search = new SubtaskSearchCriteria() { }; var paging = new PagingCriteria() { Page = 1, Size = 25 }; // act var dbContext = GetDbContext(); var results = await new SubtaskSearchQuery(dbContext).Find(search, paging); // assert results.Should().NotBeNull(); results.Page.Should().Be(1); results.Size.Should().Be(25); results.TotalItems.Should().Be(0); results.TotalPages.Should().Be(0); results.Data.Should().BeNullOrEmpty(); }
public async Task Test_SubtaskSearchQuery_FindByName_Should_ReturnMatching() { // arrange var expectedName = "find-by-name"; var job = new JobFaker().Generate("default,InProgress"); var tasks = new SubtaskFaker().SetJob(job).Generate(100); var tasksToFind = new SubtaskFaker().SetJob(job).SetName(expectedName).Generate(4); await using var dbContext = GetDbContext(); await dbContext.Setup(x => x.Jobs, job); await dbContext.Setup(x => x.Tasks, tasks); await dbContext.Setup(x => x.Tasks, tasksToFind); var search = new SubtaskSearchCriteria() { Name = expectedName }; var paging = new PagingCriteria() { Page = 1, Size = 25 }; // act var results = await new SubtaskSearchQuery(dbContext).Find(search, paging); // assert results.Should().NotBeNull(); results.Page.Should().Be(1); results.Size.Should().Be(25); results.TotalItems.Should().Be(4); results.TotalPages.Should().Be(1); results.Data.Should().HaveCount(4); results.Data.Should().OnlyContain(x => x.Name == expectedName); }
public async Task Test_SubtaskSearchQuery_FindByJobId_Should_ReturnMatching() { // arrange var jobA = new JobFaker().Generate("default,InProgress"); var jobB = new JobFaker().Generate("default,InProgress"); var aTasks = new SubtaskFaker().SetJob(jobA).Generate(100); var bTasks = new SubtaskFaker().SetJob(jobB).Generate(23); await using var dbContext = GetDbContext(); await dbContext.Setup(x => x.Jobs, new [] { jobA, jobB }); await dbContext.Setup(x => x.Tasks, aTasks); await dbContext.Setup(x => x.Tasks, bTasks); var search = new SubtaskSearchCriteria() { JobId = jobB.JobId }; var paging = new PagingCriteria() { Page = 1, Size = 25 }; // act var results = await new SubtaskSearchQuery(dbContext).Find(search, paging); // assert results.Should().NotBeNull(); results.Page.Should().Be(1); results.Size.Should().Be(25); results.TotalItems.Should().Be(23); results.TotalPages.Should().Be(1); results.Data.Should().HaveCount(23); results.Data.Should().OnlyContain(x => bTasks.Select(t => t.TaskId).Contains(x.TaskId)); }
public async Task Test_ListTasks_Find_ByName_Should_ReturnPagedList() { // arrange var job = new JobFaker().Generate("default,InProgress"); var fooTasks = new SubtaskFaker().SetJob(job).SetName("foo").Generate(10); var barTasks = new SubtaskFaker().SetJob(job).SetName("bar").Generate(10); await using var context = DbContextFactory.Instance.CreateDbContext <PortAuthorityDbContext>(); await context.Setup(x => x.Jobs, job); await context.Setup(x => x.Tasks, fooTasks); await context.Setup(x => x.Tasks, barTasks); var search = new SubtaskSearchCriteria() { Name = "bar" }; var paging = new PagingCriteria() { Page = 1, Size = 25 }; // act var result = await _service.ListTasks(search, paging); // assert result.Should().NotBeNull(); result.IsOk().Should().BeTrue(); var payload = result.Payload; payload.TotalItems.Should().Be(10); payload.TotalPages.Should().Be(1); payload.Data.Should().HaveCount(10); payload.Data.Should().OnlyContain(x => barTasks.Select(t => t.TaskId).Contains(x.TaskId)); }
public async Task Test_SubtaskSearchQuery_PageForward_Should_ReturnNewPage() { // arrange var job = new JobFaker().Generate("default,InProgress"); var tasks = new SubtaskFaker().SetJob(job).Generate(100); await using var dbContext = GetDbContext(); await dbContext.Setup(x => x.Jobs, job); await dbContext.Setup(x => x.Tasks, tasks); var search = new SubtaskSearchCriteria(); // act var query = new SubtaskSearchQuery(dbContext); var page1 = await query.Find(search, new PagingCriteria() { Page = 1, Size = 5 }); var page2 = await query.Find(search, new PagingCriteria() { Page = 2, Size = 5 }); var page3 = await query.Find(search, new PagingCriteria() { Page = 3, Size = 5 }); var page10 = await query.Find(search, new PagingCriteria() { Page = 10, Size = 5 }); // assert page1.Should().NotBeNull(); page1.Page.Should().Be(1); page1.TotalItems.Should().Be(100); page1.TotalPages.Should().Be(20); page1.Data.Should() .NotContain(page2.Data) .And.NotContain(page3.Data) .And.NotContain(page10.Data); page2.Should().NotBeNull(); page2.Page.Should().Be(2); page2.TotalItems.Should().Be(100); page2.TotalPages.Should().Be(20); page2.Data.Should() .NotContain(page1.Data) .And.NotContain(page3.Data) .And.NotContain(page10.Data); page3.Should().NotBeNull(); page3.Page.Should().Be(3); page3.TotalItems.Should().Be(100); page3.TotalPages.Should().Be(20); page3.Data.Should() .NotContain(page1.Data) .And.NotContain(page2.Data) .And.NotContain(page10.Data); page10.Should().NotBeNull(); page10.Page.Should().Be(10); page10.TotalItems.Should().Be(100); page10.TotalPages.Should().Be(20); page10.Data.Should() .NotContain(page1.Data) .And.NotContain(page2.Data) .And.NotContain(page3.Data); }