Ejemplo n.º 1
0
        public void MonthSplitterTest(int months, int items, int shouldItemsPerMonth)
        {
            //Arrange
            var splitter       = new MonthSplitter();
            var timeRange      = TimeRange.Create(DateTime.UtcNow, DateTime.UtcNow.AddMonths(months));
            var testCollection = TestEntityGenerator
                                 .Generate(timeRange, i =>
            {
                if (i == 0 || items % i == 0)
                {
                    return(null);
                }

                var time   = DateTime.UtcNow.AddDays(i);
                var entity = new TestEntity();
                entity.SetCreatedAt(time);
                return(entity);
            });

            //Act
            var splitted = splitter.Split(testCollection).ToList();

            //Assert
            var timeRanges    = splitted.Select(x => x.Key);
            var itemsPerMonth = splitted.First().Value.Count();
            var daysAreEqual  = splitted.All(x => x.Value.Count() == itemsPerMonth);

            Assert.That(timeRanges.Count(), Is.EqualTo(months));
            Assert.That(itemsPerMonth, Is.EqualTo(shouldItemsPerMonth));
            Assert.That(daysAreEqual, Is.True);
        }
Ejemplo n.º 2
0
        public void DaySplitterTest(int days, int items, int shouldItemsPerDay)
        {
            //Arrange
            var splitter       = new DaySplitter();
            var testCollection = TestEntityGenerator
                                 .Generate(TimeRange.Create(DateTime.Now.Date.AddHours(12).AddDays(-days), DateTime.Now.Date.AddHours(12)), items);

            //Act
            var splitted = splitter.Split(testCollection).ToList();

            //Assert
            var timeRanges   = splitted.Select(x => x.Key);
            var itemsPerDay  = splitted.First().Value.Count();
            var daysAreEqual = splitted.All(x => x.Value.Count() == itemsPerDay);

            Assert.That(timeRanges.Count(), Is.EqualTo(days));
            Assert.That(itemsPerDay, Is.EqualTo(shouldItemsPerDay));
            Assert.That(daysAreEqual, Is.True);
        }