public async Task Test_ListJobs_Find_ByCorrelationId_Should_ReturnPagedList()
        {
            // arrange
            var correlationId = Guid.NewGuid();
            var bulkJobs      = new JobFaker().Generate(100);
            var relatedJobs   = new JobFaker().SetCorrelationId(correlationId).Generate(10);

            await using var context = DbContextFactory.Instance.CreateDbContext <PortAuthorityDbContext>();
            await context.Setup(x => x.Jobs, bulkJobs);

            await context.Setup(x => x.Jobs, relatedJobs);

            var search = new JobSearchCriteria()
            {
                CorrelationId = correlationId
            };
            var paging = new PagingCriteria()
            {
                Page = 1, Size = 25
            };

            // act
            var result = await _service.ListJobs(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 => relatedJobs.Select(j => j.JobId).Contains(x.JobId));
        }
Exemple #2
0
        public async Task Test_JobSearchQuery_FindByCorrelationId_Should_ReturnMatching()
        {
            // arrange
            var correlationId = Guid.NewGuid();
            var bulkJobs      = new JobFaker().Generate(100);
            var relatedJobs   = new JobFaker().SetCorrelationId(correlationId).Generate(13);

            await using var dbContext = GetDbContext();
            await dbContext.Setup(x => x.Jobs, bulkJobs);

            await dbContext.Setup(x => x.Jobs, relatedJobs);

            var search = new JobSearchCriteria()
            {
                CorrelationId = correlationId
            };
            var paging = new PagingCriteria()
            {
                Page = 1, Size = 25
            };

            // act
            var results = await new JobSearchQuery(dbContext).Find(search, paging);

            // assert
            results.Should().NotBeNull();
            results.Page.Should().Be(1);
            results.Size.Should().Be(25);
            results.TotalItems.Should().Be(13);
            results.TotalPages.Should().Be(1);
            results.Data.Should().HaveCount(13);
            results.Data.Should().OnlyContain(x => relatedJobs.Select(j => j.JobId).Contains(x.JobId));
        }