Ejemplo n.º 1
0
        public void BuildByPeriod_ShouldMapCorrectly()
        {
            var configuration = new MapperConfiguration(cfg => { cfg.AddProfile <PerPeriodProfile>(); });
            var mapper        = new Mapper(configuration);
            var mapperHelper  = new EntityMapper(mapper);

            var performanceFaker = new Faker <PerformanceEntity>()
                                   .RuleFor(p => p.Count, f => f.Random.Int(0, 10000));

            var entities     = new List <PerformanceEntity>();
            var calendarDays = new List <DateTime>();

            for (var i = -10; i < 0; i++)
            {
                var occurredDate = new DateTime(DateTime.Now.AddDays(i).Year, DateTime.Now.AddDays(i).Month, DateTime.Now.AddDays(i).Day);
                var entity       = performanceFaker.Generate();
                entity.OccurredDate = occurredDate;
                entities.Add(entity);
                calendarDays.Add(occurredDate);
            }

            var byPeriod = mapperHelper.BuildByPeriod(calendarDays, entities, new DateTime(DateTime.Now.AddDays(-5).Year, DateTime.Now.AddDays(-5).Month, DateTime.Now.AddDays(-5).Day));

            Assert.Equal(5, byPeriod.Count(c => c.IsPreviousPeriod));
            Assert.Equal(5, byPeriod.Count(c => !c.IsPreviousPeriod));
            Assert.Equal(entities[0].Count, byPeriod[0].Count);
            Assert.Equal(1, byPeriod[0].DayNumber);
        }