コード例 #1
0
        public void ShouldSplitIdsIntoChunks(IEnumerable <int> input, int chunkSize, int arrayCount, int lastArrayLength)
        {
            var result = DbHelpers.SplitIds(input, chunkSize);

            result.Length.Should().Be(arrayCount);
            result.Last().Length.Should().Be(lastArrayLength);
        }
コード例 #2
0
        public void ShouldDefaultChunkSize()
        {
            const int chunkCount = 3;

            var ids    = Enumerable.Range(0, DbHelpers.DefaultChunkSize * chunkCount);
            var result = DbHelpers.SplitIds(ids);

            result.Length.Should().Be(chunkCount);

            Assert.That(result.All(each => each.Length == DbHelpers.DefaultChunkSize));
        }
コード例 #3
0
        public void ShouldCopyOriginalIds()
        {
            const int chunkSize = 5;

            var array0 = new[] { 1, 2, 3, 4, 5 };
            var array1 = new[] { 6, 7 };

            var ids = new List <int>();

            ids.AddRange(array0);
            ids.AddRange(array1);

            var result = DbHelpers.SplitIds(ids, chunkSize);

            result.Length.Should().Be(2);

            result[0].ShouldBeEquivalentTo(array0);
            result[1].ShouldBeEquivalentTo(array1);
        }
コード例 #4
0
        public IReadOnlyDictionary <int, IEnumerable <VacancyLocation> > GetVacancyLocationsByVacancyIds(IEnumerable <int> vacancyIds)
        {
            var vacancyLocations = new Dictionary <int, IEnumerable <VacancyLocation> >();

            var splitVacancyIds = DbHelpers.SplitIds(vacancyIds);

            foreach (var vacanciesIds in splitVacancyIds)
            {
                var splitVacancyLocations =
                    _getOpenConnection.Query <VacancyLocation>(
                        @"SELECT * FROM dbo.VacancyLocation WHERE  VacancyId IN @Ids", new { Ids = vacanciesIds })
                    .GroupBy(x => x.VacancyId);
                foreach (var splitVacancyLocation in splitVacancyLocations)
                {
                    vacancyLocations[splitVacancyLocation.Key] = splitVacancyLocation;
                }
            }

            return(vacancyLocations);
        }
コード例 #5
0
        public void ShouldHandleEmptyArray()
        {
            var result = DbHelpers.SplitIds(new int[] { });

            result.Length.Should().Be(0);
        }