public Task <IReadOnlyCollection <JobBatch> > GetJobBatchesAsync(JobBatchSearchCriteria jobBatchSearchCriteria)
        {
            if (jobBatchSearchCriteria == null)
            {
                throw new ArgumentNullException(nameof(jobBatchSearchCriteria));
            }

            IQueryable <JobBatch> jobBatchQuery = _jobBatchCache.Query();

            if (!string.IsNullOrEmpty(jobBatchSearchCriteria.JobBatchOwnerId))
            {
                jobBatchQuery = jobBatchQuery.Where(jobBatch => jobBatch.JobBatchOwnerId.Contains(jobBatchSearchCriteria.JobBatchOwnerId, StringComparison.OrdinalIgnoreCase));
            }

            jobBatchQuery = jobBatchQuery.OrderByDescending(jobBatch => jobBatch.CreatedAt);

            if (jobBatchSearchCriteria.ItemsToSkip.HasValue)
            {
                jobBatchQuery = jobBatchQuery.Skip(jobBatchSearchCriteria.ItemsToSkip.Value);
            }

            if (jobBatchSearchCriteria.MaximumItems.HasValue)
            {
                jobBatchQuery = jobBatchQuery.Take(jobBatchSearchCriteria.MaximumItems.Value);
            }

            IReadOnlyCollection <JobBatch> jobBatches = jobBatchQuery
                                                        .ToList()
                                                        .AsReadOnly();

            return(Task.FromResult(jobBatches));
        }
        public async Task GetJobBatchesAsync_returns_set_of_jobs_by_owner(string ownerId)
        {
            _testMemoryCacheJobBatchRepositoryFactory.MockJobBatchCache
            .Setup(jobBatchCache => jobBatchCache.Query())
            .Returns(() => TestMemoryCacheJobBatchRepositoryFactory.JobBatches.AsQueryable())
            .Verifiable();

            var memoryCacheJobBatchRepository = _testMemoryCacheJobBatchRepositoryFactory.CreateMemoryCacheJobBatchRepository();

            var jobSearchCriteria = new JobBatchSearchCriteria
            {
                JobBatchOwnerId = ownerId
            };

            IReadOnlyCollection <JobBatch> actualJobBatches = await memoryCacheJobBatchRepository.GetJobBatchesAsync(jobSearchCriteria);

            IReadOnlyCollection <JobBatch> expectedJobBatches = TestMemoryCacheJobBatchRepositoryFactory.JobBatches
                                                                .Where(jobBatch => jobBatch.JobBatchOwnerId.Contains(ownerId))
                                                                .OrderByDescending(jobBatch => jobBatch.CreatedAt)
                                                                .ToList()
                                                                .AsReadOnly();

            Assert.Equal(expectedJobBatches, actualJobBatches);

            _testMemoryCacheJobBatchRepositoryFactory.MockJobBatchCache
            .Verify(
                jobBatchCache => jobBatchCache.Query(),
                Times.Once);
        }
        public async Task GetJobBatchesAsync_returns_constrained_results(int?skip, int?limit)
        {
            string ownerId = TestMemoryCacheJobBatchRepositoryFactory.OwnerIds[0];

            _testMemoryCacheJobBatchRepositoryFactory.MockJobBatchCache
            .Setup(jobBatchCache => jobBatchCache.Query())
            .Returns(() => TestMemoryCacheJobBatchRepositoryFactory.JobBatches.AsQueryable())
            .Verifiable();

            var memoryCacheJobBatchRepository = _testMemoryCacheJobBatchRepositoryFactory.CreateMemoryCacheJobBatchRepository();

            var jobSearchCriteria = new JobBatchSearchCriteria
            {
                JobBatchOwnerId = ownerId,
                ItemsToSkip     = skip,
                MaximumItems    = limit
            };

            IReadOnlyCollection <JobBatch> actualJobBatches = await memoryCacheJobBatchRepository.GetJobBatchesAsync(jobSearchCriteria);

            IEnumerable <JobBatch> expectedJobBatches = TestMemoryCacheJobBatchRepositoryFactory.JobBatches
                                                        .Where(jobBatch => jobBatch.JobBatchOwnerId.Contains(ownerId))
                                                        .OrderByDescending(jobBatch => jobBatch.CreatedAt);

            if (skip != null)
            {
                expectedJobBatches = expectedJobBatches.Skip(skip.Value);
            }

            if (limit != null)
            {
                expectedJobBatches = expectedJobBatches.Take(limit.Value);
            }

            Assert.Equal(expectedJobBatches, actualJobBatches);

            _testMemoryCacheJobBatchRepositoryFactory.MockJobBatchCache
            .Verify(
                jobBatchCache => jobBatchCache.Query(),
                Times.Once);
        }