Esempio n. 1
0
        public void Rank(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay)
        {
            DateTime             startDate = new DateTime(startYear, startMonth, startDay);
            DateTime             endDate   = new DateTime(endYear, endMonth, endDay);
            List <DensityDevice> devices   = DensityDbSimulator.CreateDensityDevice(TestInit.ServiceProvider, 1, 6, 6, "", true);
            //随机出的值表示次数,每次1分钟
            Dictionary <TrafficEvent, int> trafficEvents = EventDbSimulator.CreateData(TestInit.ServiceProvider, devices, startDate, endDate, DataCreateMode.Random, true);

            TestInit.RefreshDensityCache(devices);
            EventsController service = new EventsController(TestInit.ServiceProvider.GetRequiredService <DensityContext>(),
                                                            TestInit.ServiceProvider.GetRequiredService <IMemoryCache>());
            IMemoryCache memoryCache = TestInit.ServiceProvider.GetRequiredService <IMemoryCache>();

            //要验证的值
            var regions = trafficEvents
                          .Select(p => new KeyValuePair <string, int>(p.Key.DataId, p.Value))
                          .OrderByDescending(p => p.Value)
                          .ToList();
            var roads = trafficEvents
                        .GroupBy(p => memoryCache.GetRegion(p.Key.DataId).Channel.CrossingId)
                        .Select(g => new KeyValuePair <int, int>(g.Key.Value, g.Sum(p => p.Value)))
                        .OrderByDescending(p => p.Value)
                        .ToList();

            //区域次数
            var countRegionTop = service.CountRankByRegion(startDate, endDate.AddDays(1));

            for (int i = 0; i < countRegionTop.Count; ++i)
            {
                //验证次数和区域编号
                Assert.AreEqual(countRegionTop[i].Value, regions[i].Value);
                Assert.AreEqual(countRegionTop[i].Axis, regions[i].Key);
            }

            //路口次数
            var countRoadTop = service.CountRankByRoad(startDate, endDate.AddDays(1));

            for (int i = 0; i < countRoadTop.Count; ++i)
            {
                //验证次数和路口编号
                Assert.AreEqual(countRoadTop[i].Value, roads[i].Value);
                Assert.AreEqual(countRoadTop[i].Axis, roads[i].Key);
            }

            //区域时长
            var spanRegionTop = service.SpanRankByRegion(startDate, endDate.AddDays(1));

            for (int i = 0; i < spanRegionTop.Count; ++i)
            {
                //验证时长(秒)和区域编号
                Assert.AreEqual(spanRegionTop[i].Value, regions[i].Value);
                Assert.AreEqual(spanRegionTop[i].Axis, regions[i].Key);
            }

            //路口时长
            var spanRoadTop = service.SpanRankByRoad(startDate, endDate.AddDays(1));

            for (int i = 0; i < countRoadTop.Count; ++i)
            {
                //验证时长(秒)和路口编号
                Assert.AreEqual(spanRoadTop[i].Value, roads[i].Value);
                Assert.AreEqual(spanRoadTop[i].Axis, roads[i].Key);
            }
        }