Exemple #1
0
        public static void CreateData(TestContext testContext)
        {
            _startDate = new DateTime(2019, 1, 1);
            _days      = 1;
            List <DateTime> dates = new List <DateTime>();

            for (DateTime date = _startDate; date <= _startDate.AddDays(_days - 1); date = date.AddDays(1))
            {
                dates.Add(date);
            }

            _startDates = new List <DateTime>();
            for (int d = 0; d < _days; ++d)
            {
                _startDates.Add(_startDate.AddDays(d));
            }

            _months      = 1;
            _startMonths = new List <DateTime>();
            for (int m = 0; m < _months; ++m)
            {
                _startMonths.Add(TimePointConvert.CurrentTimePoint(DateTimeLevel.Month, _startDate).AddMonths(m));
            }

            _devices = FlowDbSimulator.CreateFlowDevice(TestInit.ServiceProvider, 1, 1, 2, true);
            TestInit.RefreshFlowCache(_devices);

            _datas = FlowDbSimulator.CreateData(TestInit.ServiceProvider, _devices, DataCreateMode.Fixed, dates, true);
        }
        public async Task AddToCourseShouldAddStudentToCourse()
        {
            // Arrange
            var db = TestInit.InitializeInmemoryDatabase();
            var teacherCoursesService  = new TeacherCoursesService(db);
            var teacherStudentsService = new TeacherStudentsService(db);
            var userManager            = testHelpers.GetUserManagerMock();
            var roleManager            = testHelpers.GetRoleManagerMock();
            var usersController        = new StudentsController(teacherStudentsService, teacherCoursesService, userManager, roleManager);

            usersController.TempData = new TempDataDictionary(Mock.Of <HttpContext>(), Mock.Of <ITempDataProvider>());

            string studentId = "1";
            int    courseId  = 1;

            db.Courses.Add(new Course {
                Id = courseId, Name = "Course"
            });
            db.Students.Add(new Student {
                UserId = studentId
            });
            await db.SaveChangesAsync();

            // Act
            var result = await usersController.AddToCourse(studentId, courseId.ToString());

            // Assert
            Assert.Contains(db.StudentCourses, sc => sc.StudentId == studentId && sc.CourseId == courseId);
        }
Exemple #3
0
        public void Statistics(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);
            int                  days      = Convert.ToInt32((endDate - startDate).TotalDays + 1);
            List <DensityDevice> devices   = DensityDbSimulator.CreateDensityDevice(TestInit.ServiceProvider, 1, 6, 6, "", true);

            //创建每小时两条条数据
            EventDbSimulator.CreateData(TestInit.ServiceProvider, devices, startDate, endDate, DataCreateMode.Fixed, true);
            TestInit.RefreshDensityCache(devices);
            EventsController service = new EventsController(TestInit.ServiceProvider.GetRequiredService <DensityContext>(),
                                                            TestInit.ServiceProvider.GetRequiredService <IMemoryCache>());

            foreach (DensityDevice device in devices)
            {
                foreach (var relation in device.DensityDevice_DensityChannels)
                {
                    var roadList = service.StatisticsByRoad(relation.Channel.CrossingId.Value, startDate, endDate.AddDays(1));
                    //验证按路口按小时分组统计次数
                    Assert.AreEqual(days * 24, roadList.Count);

                    //验证按区域按小时分组统计次数
                    foreach (TrafficRegion region in relation.Channel.Regions)
                    {
                        var regionList = service.StatisticsByRegion(region.DataId, startDate, endDate.AddDays(1));
                        Assert.AreEqual(days * 24, regionList.Count);
                    }
                }
            }
        }
Exemple #4
0
        public async Task FindAsyncShouldReturnCorrectResultSearchCount()
        {
            // Arrange
            var db    = TestInit.InitializeInmemoryDatabase();
            var user1 = new User()
            {
                Id = "1", FirstName = "user1f", Surname = "user1s", Email = "*****@*****.**"
            };
            var user2 = new User()
            {
                Id = "2", FirstName = "user2f", Surname = "user2s", Email = "*****@*****.**"
            };
            var user3 = new User()
            {
                Id = "3", FirstName = "user3f", Surname = "user3s", Email = "*****@*****.**"
            };

            db.AddRange(user1, user2, user3);
            await db.SaveChangesAsync();

            var adminUserService = new AdminUserService(db);

            // Act
            var result = await adminUserService.AllAsync("user2");

            // Assert
            Assert.True(result.Count() == 1);
        }
 public static Order CreateOrder_FedEx()
 {
     return(new Order()
     {
         ShippingMethod = Order.ShippingOptions.FedEx,
         Destination = TestInit.CreateAddress_Destination(),
         Origin = TestInit.CreateAddress_Origin()
     });
 }
Exemple #6
0
        public void Last10()
        {
            List <DensityDevice> devices = DensityDbSimulator.CreateDensityDevice(TestInit.ServiceProvider, 1, 1, 10, "", true);

            TestInit.RefreshDensityCache(devices);
            EventDbSimulator.CreateData(TestInit.ServiceProvider, devices, DateTime.Today, true);
            EventsController service = new EventsController(TestInit.ServiceProvider.GetRequiredService <DensityContext>(),
                                                            TestInit.ServiceProvider.GetRequiredService <IMemoryCache>());
            var v         = service.QueryLast10();
            int itemCount = devices[0].DensityDevice_DensityChannels[0].Channel.Regions.Count;

            for (int i = 0; i < 10; ++i)
            {
                Assert.AreEqual(v[i].DataId, devices[0].DensityDevice_DensityChannels[0].Channel.Regions[itemCount - 1 - i].DataId);
            }
        }
        public void setup()
        {
            var directoryName = TestContext.CurrentContext.Test.Name.ToString();

            //Open Browser
            dr = BrowserFactory.getBrowser(dr);
            //start Extent Test
            ExtentReportClass.StartExtentTest();
            test = ExtentReportClass.test;
            //Create folder for screenshots
            SeleniumScreenshot.CreateDirectoryForScreenshots(directoryName);
            //Login to stating portal
            TestInit.ManageLogin(dr);
            //Explicit wait
            Thread.Sleep(1000);
            ExplicitWaits.ElementExists(By.ClassName("entry-title"));
        }
Exemple #8
0
        public void QueryChannelMinuteStatus()
        {
            List <FlowDevice> devices = FlowDbSimulator.CreateFlowDevice(TestInit.ServiceProvider, 1, 1, 2, true);

            TestInit.RefreshFlowCache(devices);

            FlowDbSimulator.CreateData(TestInit.ServiceProvider, devices, DataCreateMode.Fixed, DateTime.Today, true);


            ChannelFlowsManager service = TestInit.ServiceProvider.GetRequiredService <ChannelFlowsManager>();

            foreach (FlowDevice device in devices)
            {
                foreach (var relation in device.FlowDevice_FlowChannels)
                {
                    int laneCount = relation.Channel.Lanes.Count;

                    var hourStatus = service.QueryChannelHourStatus(relation.ChannelId);

                    //本小时列表

                    Assert.AreEqual(30, hourStatus.TodayHourLanes[0].Occupancy);

                    Assert.AreEqual(40, hourStatus.TodayHourLanes[0].TimeOccupancy);

                    for (int i = 1; i < hourStatus.TodayHourLanes.Count; ++i)
                    {
                        Assert.AreEqual(30, hourStatus.TodayHourLanes[i].Occupancy);

                        Assert.AreEqual(40, hourStatus.TodayHourLanes[i].TimeOccupancy);
                    }

                    //本小时图表
                    for (int i = 0; i < 55; ++i)
                    {
                        Assert.AreEqual(8 * laneCount, hourStatus.TodayHourCharts[0][i].Value);

                        for (int j = 1; j < hourStatus.TodayHourCharts.Count; ++j)
                        {
                            Assert.AreEqual(8, hourStatus.TodayHourCharts[j][i].Value);
                        }
                    }
                }
            }
        }
Exemple #9
0
        static void TestInitiation()
        {
            using (var sim = new QuantumSimulator())
            {
                var initedQubitsValues = Enumerable.Range(0, 5)
                                         .ToDictionary(qubitIndex => qubitIndex, oneMesaured => 0);


                for (int i = 0; i < 1000; i++)
                {
                    (Result, Result, Result, Result, Result)result = TestInit.Run(sim).Result;
                    if (result.Item1 == Result.One)
                    {
                        initedQubitsValues[0]++;
                    }
                    if (result.Item2 == Result.One)
                    {
                        initedQubitsValues[1]++;
                    }
                    if (result.Item3 == Result.One)
                    {
                        initedQubitsValues[2]++;
                    }
                    if (result.Item4 == Result.One)
                    {
                        initedQubitsValues[3]++;
                    }
                    if (result.Item5 == Result.One)
                    {
                        initedQubitsValues[4]++;
                    }
                }

                Console.WriteLine($"Qubit-0 initiations: {initedQubitsValues[0]}");
                Console.WriteLine($"Qubit-1 initiations: {initedQubitsValues[1]}");
                Console.WriteLine($"Qubit-2 initiations: {initedQubitsValues[2]}");
                Console.WriteLine($"Qubit-3 initiations: {initedQubitsValues[3]}");
                Console.WriteLine($"Qubit-4 initiations: {initedQubitsValues[4]}");
            }
        }
Exemple #10
0
        public void Test_Init()
        {
            Stopwatch time = new Stopwatch();

            time.Start();
            TestInit.Init().Wait();
            LoginUtil.Instance.ValidateUserLogin(TestHelper.TestUsers[0].UserName, TestHelper.TestUsers[0].Password, TestHelper.TestUsers[0].CountryCode).Wait();
            DlBook dlBook = new DlBook
            {
                BookId                = 111,
                InitVector            = "QDFCMmMzRDRlNUY2ZzdIOA==",
                K2Key                 = "MXdi9JQDDUY1hf5TZCEHjeBtjKL605dInVG3xYTF76U=",
                HmacKey               = "9jU0MAYPOPufUZoZJCW7qhsQe20=",
                LastDownloadedVersion = 1,
                ServiceCode           = GlobalAccess.Instance.CurrentUserInfo.Country.CountryCode,
                Email                 = GlobalAccess.Instance.CurrentUserInfo.Email
            };
            var contentKey = dlBook.GetContentKey(GlobalAccess.Instance.CurrentUserInfo.SymmetricKey).Result;

            GlobalAccess.Instance.CurrentPublication = new PublicationContent(dlBook, contentKey);
            time.Stop();
            Console.Out.WriteLine("Time : " + time.ElapsedMilliseconds);
        }
Exemple #11
0
        public void Test_Init()
        {
            Stopwatch time = new Stopwatch();

            time.Start();
            TestInit.Init().Wait();
            LoginUtil.Instance.ValidateUserLogin(TestHelper.TestUsers[0].UserName, TestHelper.TestUsers[0].Password, TestHelper.TestUsers[0].CountryCode).Wait();
            DlBook dlBook = new DlBook
            {
                BookId                = 41,
                InitVector            = "QDFCMmMzRDRlNUY2ZzdIOA==",
                K2Key                 = "PhlFIzSW3nR9Vq6wg1g3bwqN9uAz0IqBdlJDobzzEUI=",
                HmacKey               = "+wlxbpoqFZ1h0dMv9p/mmqAdJ9Y=",
                LastDownloadedVersion = 1,
                ServiceCode           = GlobalAccess.Instance.CurrentUserInfo.Country.CountryCode,
                Email                 = GlobalAccess.Instance.CurrentUserInfo.Email
            };
            var contentKey = dlBook.GetContentKey(GlobalAccess.Instance.CurrentUserInfo.SymmetricKey).Result;

            GlobalAccess.Instance.CurrentPublication = new PublicationContent(dlBook, contentKey);
            time.Stop();
            Console.Out.WriteLine("Time : " + time.ElapsedMilliseconds);
        }
Exemple #12
0
        public void Test_Init()
        {
            Stopwatch time = new Stopwatch();

            time.Start();
            TestInit.Init().Wait();
            LoginUtil.Instance.ValidateUserLogin(TestHelper.TestUsers[0].UserName, TestHelper.TestUsers[0].Password, TestHelper.TestUsers[0].CountryCode).Wait();
            DlBook dlBook = new DlBook
            {
                BookId                = 26,
                InitVector            = "QDFCMmMzRDRlNUY2ZzdIOA==",
                K2Key                 = "Kd7qQHCj9qT05gDAAAgXsj74kxQpHA2r2Flf3FH7XLQ=",
                HmacKey               = "7PPPQbvLEVsMRwpXJJqQv49fU7c=",
                LastDownloadedVersion = 18,
                ServiceCode           = GlobalAccess.Instance.CurrentUserInfo.Country.ServiceCode,
                // CountryCode = GlobalAccess.Instance.CurrentUserInfo.Country.CountryCode,
                Email = GlobalAccess.Instance.CurrentUserInfo.Email
            };
            var contentKey = dlBook.GetContentKey(GlobalAccess.Instance.CurrentUserInfo.SymmetricKey).Result;

            GlobalAccess.Instance.CurrentPublication = new PublicationContent(dlBook, contentKey);
            time.Stop();
            Console.Out.WriteLine("Time : " + time.ElapsedMilliseconds);
        }
Exemple #13
0
        public void Incidence(int startYear, int startMonth, int startDay)
        {
            DateTime             startDate = new DateTime(startYear, startMonth, startDay);
            List <DensityDevice> devices   = DensityDbSimulator.CreateDensityDevice(TestInit.ServiceProvider, 1, 1, 1, "", true);

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

            EventDbSimulator.ResetDatabase(TestInit.ServiceProvider);


            using (DensityContext context = TestInit.ServiceProvider.GetRequiredService <DensityContext>())
            {
                foreach (DensityDevice device in devices)
                {
                    foreach (var relation in device.DensityDevice_DensityChannels)
                    {
                        foreach (TrafficRegion region in relation.Channel.Regions)
                        {
                            DateTime time = startDate;
                            //添加一个持续长度满足10分钟
                            AddDuration(context, region, time, 10);

                            //添加连续3次 总长
                            time = startDate.AddHours(1);
                            AddInterval(context, region, time, 5, 3, 3);

                            //10分钟关联前后5分钟
                            time = startDate.AddHours(2);
                            time = AddDuration(context, region, time, 5);
                            time = time.AddMinutes(3);
                            time = AddDuration(context, region, time, 10);
                            time = time.AddMinutes(3);
                            AddDuration(context, region, time, 5);

                            //交集 5分钟持续三次+10分钟
                            time = startDate.AddHours(3);
                            time = AddInterval(context, region, time, 5, 3, 3);
                            time = time.AddMinutes(3);
                            AddDuration(context, region, time, 10);
                        }
                    }
                }
                context.BulkSaveChanges(options => options.BatchSize = 1000);
                foreach (DensityDevice device in devices)
                {
                    foreach (var relation in device.DensityDevice_DensityChannels)
                    {
                        foreach (TrafficRegion region in relation.Channel.Regions)
                        {
                            var list = service.AnalysisIncidence(region.DataId, startDate, startDate);
                            Assert.AreEqual(startDate, list[0][0].DateTime);
                            Assert.AreEqual(startDate.AddMinutes(10), list[0][0].EndTime);

                            Assert.AreEqual(startDate.AddHours(1), list[0][1].DateTime);
                            Assert.AreEqual(startDate.AddHours(1).AddMinutes(5 * 3 + 3 * 2), list[0][1].EndTime);

                            Assert.AreEqual(startDate.AddHours(2), list[0][2].DateTime);
                            Assert.AreEqual(startDate.AddHours(2).AddMinutes(5 + 3 + 10 + 3 + 5), list[0][2].EndTime);

                            Assert.AreEqual(startDate.AddHours(3), list[0][3].DateTime);
                            Assert.AreEqual(startDate.AddHours(3).AddMinutes(5 * 3 + 3 * 2 + 3 + 10), list[0][3].EndTime);
                        }
                    }
                }
            }
        }
Exemple #14
0
        public void TestMemberInitExpression()
        {
            using (var context = new TestDataContext())
            {
                var instance = new TestInit
                {
                    Id     = 2,
                    List   = { 3, 5 },
                    Member = new TestInit2 {
                        Id = 3, List = { new Tuple <int, int>(4, 5) }
                    },
                    StructMember = { Id = 3 }
                };

                var result1 = context.ADbSet.Where(i => new TestInit
                {
                    Id     = 2,
                    List   = { 3, 5 },
                    Member = new TestInit2 {
                        Id = 3, List = { new Tuple <int, int>(4, 5) }
                    },
                    StructMember = { Id = 3 }
                }.Equals(instance)).Count();

                Assert.AreEqual(1, result1);


                instance = new TestInit {
                    Member = { { 3, 4 }, { 5, 6 } }
                };
                var result2 = context.ADbSet.Where(i => new TestInit {
                    Member = { { 3, 4 }, { 5, 6 } }
                }.Equals(instance)).Count();
                Assert.AreEqual(1, result2);

                context.ADbSet.InsertOnSubmit(TestEntity);
                context.SubmitChanges();

                var id = context.ADbSet.Select(i => i.Id).Last();

                var result3 = context.ADbSet
                              .Where(i => new TestInit {
                    Member = { { 3, 4 }, { 5, i.Id } }
                }.Member.List[1].Item2 == id)
                              .Count();

                Assert.AreEqual(1, result3);

                var result4 = context.ADbSet.Where(i => new TestInit(i.Id)
                {
                    Id = i.Id,
                }.Id == id).Count();
                Assert.AreEqual(1, result4);

                var result5 = context.ADbSet.Where(i => new TestInit(i.Id)
                {
                    Id = -5
                }.Id == -5).Count();
                Assert.AreEqual(2, result5);

                var result6 = context.ADbSet.Where(i => new TestInit3 {
                    Id = i.Id
                }.Id == i.Id).Count();
                Assert.AreEqual(2, result6);

                var result7 = context.ADbSet.Where(i => new TestInit {
                    Member = { Id = i.Id }
                }.Member.Id == id).Count();
                Assert.AreEqual(1, result7);

                Assert.Throws <NullReferenceException>(() => context.ADbSet.Where(i => new TestInit {
                    NullMember = { Id = 3 }
                } != null).Count());

                context.ADbSet.DeleteAllOnSubmit(context.ADbSet);
                context.SubmitChanges();

                var result8 = context.ADbSet.Where(i => new TestInit {
                    Id = i.Id
                }.Id == i.Id).Count();
                Assert.AreEqual(0, result8);
            }
        }
Exemple #15
0
        public void QueryList_TwoMonth()
        {
            DateTime          startDate1 = new DateTime(2019, 4, 30);
            DateTime          endDate1   = new DateTime(2019, 4, 30);
            DateTime          startDate2 = new DateTime(2019, 5, 1);
            DateTime          endDate2   = new DateTime(2019, 5, 1);
            int               days       = Convert.ToInt32((endDate2 - startDate1).TotalDays + 1);
            List <FlowDevice> devices    = FlowDbSimulator.CreateFlowDevice(TestInit.ServiceProvider, 1, 1, 2, true);

            TestInit.RefreshFlowCache(devices);
            VideoStructDbSimulator.CreateData(TestInit.ServiceProvider, devices, DataCreateMode.Fixed, startDate1, endDate1, true);
            VideoStructDbSimulator.CreateData(TestInit.ServiceProvider, devices, DataCreateMode.Fixed, startDate2, endDate2);

            VideoStructsController controller = new VideoStructsController(
                TestInit.ServiceProvider.CreateScope().ServiceProvider.GetRequiredService <VideoStructManager_Alone>());

            //按路口查询
            foreach (FlowDevice device in devices)
            {
                foreach (var relation in device.FlowDevice_FlowChannels)
                {
                    int laneCount = relation.Channel.Lanes.Count;
                    var vehicles  = controller.QueryByCrossing(relation.Channel.CrossingId.Value, VideoStructType.机动车, startDate1, endDate2.AddDays(1), 0, 0, true);
                    Assert.AreEqual(days * 24 * 60 * laneCount, vehicles.Datas.Count);
                    var bikes = controller.QueryByCrossing(relation.Channel.CrossingId.Value, VideoStructType.非机动车, startDate1, endDate2.AddDays(1), 0, 0, true);
                    Assert.AreEqual(days * 24 * 60 * laneCount, bikes.Datas.Count);
                    var pedestrains = controller.QueryByCrossing(relation.Channel.CrossingId.Value, VideoStructType.行人, startDate1, endDate2.AddDays(1), 0, 0, true);
                    Assert.AreEqual(days * 24 * 60 * laneCount, pedestrains.Datas.Count);
                }
            }

            //按路口方向查询
            foreach (FlowDevice device in devices)
            {
                foreach (var relation in device.FlowDevice_FlowChannels)
                {
                    int[] directions = relation.Channel.Lanes.Select(l => l.Direction).Distinct().ToArray();
                    foreach (int direction in directions)
                    {
                        int laneCount = relation.Channel.Lanes.Count(l => l.Direction == direction);
                        var vehicles  = controller.QueryByCrossing(relation.Channel.CrossingId.Value, new[] { direction }, VideoStructType.机动车, startDate1, endDate2.AddDays(1), 0, 0, true);
                        Assert.AreEqual(days * 24 * 60 * laneCount, vehicles.Datas.Count);
                        var bikes = controller.QueryByCrossing(relation.Channel.CrossingId.Value, new[] { direction }, VideoStructType.非机动车, startDate1, endDate2.AddDays(1), 0, 0, true);
                        Assert.AreEqual(days * 24 * 60 * laneCount, bikes.Datas.Count);
                        var pedestrains = controller.QueryByCrossing(relation.Channel.CrossingId.Value, new[] { direction }, VideoStructType.行人, startDate1, endDate2.AddDays(1), 0, 0, true);
                        Assert.AreEqual(days * 24 * 60 * laneCount, pedestrains.Datas.Count);
                    }
                }
            }

            //按路段查询
            foreach (FlowDevice device in devices)
            {
                foreach (var relation in device.FlowDevice_FlowChannels)
                {
                    int laneCount = relation.Channel.Lanes.Count;
                    var vehicles  = controller.QueryBySection(relation.Channel.SectionId.Value, VideoStructType.机动车, startDate1, endDate2.AddDays(1), 0, 0, true);
                    Assert.AreEqual(days * 24 * 60 * laneCount, vehicles.Datas.Count);
                    var bikes = controller.QueryBySection(relation.Channel.SectionId.Value, VideoStructType.非机动车, startDate1, endDate2.AddDays(1), 0, 0, true);
                    Assert.AreEqual(days * 24 * 60 * laneCount, bikes.Datas.Count);
                    var pedestrains = controller.QueryBySection(relation.Channel.SectionId.Value, VideoStructType.行人, startDate1, endDate2.AddDays(1), 0, 0, true);
                    Assert.AreEqual(days * 24 * 60 * laneCount, pedestrains.Datas.Count);
                }
            }
        }
Exemple #16
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);
            }
        }
Exemple #17
0
 public void RunBeforeAnyTests()
 {
     TestInit.Init().Wait();
 }
        public void QueryDayTop10()
        {
            DateTime now   = DateTime.Now;
            DateTime today = now.Date;

            List <DensityDevice> devices = DensityDbSimulator.CreateDensityDevice(TestInit.ServiceProvider, 1, 1, 12, "", true);

            DensityDbSimulator.ResetDatabase(TestInit.ServiceProvider);
            TestInit.RefreshDensityCache(devices);
            DensitiesManager manager = TestInit.ServiceProvider.GetRequiredService <DensitiesManager>();

            var regions = DensityDbSimulator.CreateData(TestInit.ServiceProvider, devices
                                                        , new List <DataCreateMode> {
                DataCreateMode.Fixed, DataCreateMode.Fixed, DataCreateMode.Random
            }
                                                        , new List <DateTime> {
                today.AddDays(-1), now.AddHours(-2).AddMinutes(30), now.AddHours(-1).AddMinutes(30)
            }
                                                        , new List <DateTime> {
                today.AddDays(-1).AddMinutes(1), now.AddHours(-2).AddMinutes(31), now.AddHours(-1).AddMinutes(31)
            }
                                                        , true);

            var densities = regions.OrderByDescending(p => p.Value).ToList();

            var dayTop10 = manager.QueryTop10(today);

            for (int i = 0; i < dayTop10.Count; ++i)
            {
                Assert.AreEqual(densities[i].Key.DataId, dayTop10[i].DataId);
                //今天
                Assert.AreEqual(Math.Ceiling((densities[i].Value + 1) / 2.0), dayTop10[i].Value);
            }
            DateTime time = DateTime.Now.AddHours(-1);

            var hourTop10 = manager.QueryTop10(time);

            for (int i = 0; i < hourTop10.Count; ++i)
            {
                Assert.AreEqual(densities[i].Key.DataId, hourTop10[i].DataId);
                //本小时
                Assert.AreEqual(densities[i].Value, hourTop10[i].Value);
            }

            var dayChangeTop10 = manager.QueryChangeTop10(today, today.AddDays(-1), today.AddDays(-1).Add(now.TimeOfDay));

            for (int i = 0; i < dayChangeTop10.Count; ++i)
            {
                Assert.AreEqual(densities[i].Key.DataId, dayChangeTop10[i].DataId);
                //今天
                Assert.AreEqual(Math.Ceiling((densities[i].Value + 1) / 2.0), dayChangeTop10[i].Value);
                //昨天
                Assert.AreEqual(1, dayChangeTop10[i].LastValue);
            }

            var hourChangeTop10 = manager.QueryChangeTop10(now.AddHours(-1), now.AddHours(-2), now.AddHours(-1));

            for (int i = 0; i < hourChangeTop10.Count; ++i)
            {
                Assert.AreEqual(densities[i].Key.DataId, hourChangeTop10[i].DataId);
                //本小时
                Assert.AreEqual(hourTop10[i].Value, hourChangeTop10[i].Value);
                //上小时
                Assert.AreEqual(1, hourChangeTop10[i].LastValue);
            }
        }
 public void Test_Init()
 {
     TestInit.Init().Wait();
 }
        public void QueryVipRegions()
        {
            List <DensityDevice> devices = new List <DensityDevice>();
            int deviceCount       = 1;
            int channelCount      = 1;
            int regionCount       = 12;
            HashSet <string> vips = new HashSet <string>();
            //随机创建重点区域
            Random random = new Random();

            using (IServiceScope serviceScope = TestInit.ServiceProvider.CreateScope())
            {
                using (DensityContext context = serviceScope.ServiceProvider.GetRequiredService <DensityContext>())
                {
                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();

                    int deviceId   = 1;
                    int crossingId = 1;
                    int regionId   = 1;
                    int channelId  = 1;
                    for (int i = 0; i < deviceCount; ++i)
                    {
                        DensityDevice densityDevice = new DensityDevice
                        {
                            DeviceId = deviceId++,
                            Ip       = "192.168.200.204",
                            Port     = 18000 + i
                        };
                        densityDevice.DeviceName = "设备" + densityDevice.Port;
                        densityDevice.DensityDevice_DensityChannels = new List <DensityDevice_DensityChannel>();
                        for (int j = 0; j < channelCount; ++j)
                        {
                            RoadCrossing roadCrossing = new RoadCrossing
                            {
                                CrossingId   = crossingId,
                                CrossingName = "路口" + crossingId
                            };
                            DensityChannel channel = new DensityChannel()
                            {
                                ChannelId    = channelId.ToString(),
                                ChannelName  = $"通道 {densityDevice.DeviceId} {j+1}",
                                ChannelIndex = j + 1,
                                CrossingId   = crossingId,
                                Regions      = new List <TrafficRegion>(),
                                RoadCrossing = roadCrossing
                            };
                            DensityDevice_DensityChannel relation = new DensityDevice_DensityChannel
                            {
                                ChannelId = channel.ChannelId,
                                DeviceId  = densityDevice.DeviceId,
                                Channel   = channel
                            };
                            channelId++;
                            crossingId++;
                            densityDevice.DensityDevice_DensityChannels.Add(relation);

                            for (int k = 0; k < regionCount; ++k)
                            {
                                int           value  = random.Next(1, 2);
                                TrafficRegion region = new TrafficRegion
                                {
                                    ChannelId   = channel.ChannelId,
                                    Channel     = channel,
                                    Region      = "1",
                                    RegionIndex = k + 1,
                                    RegionName  = "区域" + regionId++,
                                    IsVip       = value == 1
                                };
                                if (value == 1)
                                {
                                    vips.Add(region.DataId);
                                }
                                channel.Regions.Add(region);
                            }
                        }
                        context.Devices.Add(densityDevice);
                        devices.Add(densityDevice);
                    }
                    context.SaveChanges();
                }
                DensityDbSimulator.CreateData(TestInit.ServiceProvider, devices, DataCreateMode.Fixed, DateTime.Today, DateTime.Today);
                TestInit.RefreshDensityCache(devices);
                DensitiesManager manager = TestInit.ServiceProvider.GetRequiredService <DensitiesManager>();

                var v = manager.QueryVipRegions();
                foreach (TrafficDensity density in v)
                {
                    Assert.IsTrue(vips.Contains(density.DataId));
                }
            }
        }
Exemple #21
0
 public AdminUserServiceTests()
 {
     TestInit.InitializeMapper();
 }
        private static IServiceProvider GetServices()
        {
            var services = new Mock <IServiceProvider>();

            var routeOptions = new RouteOptions();

            routeOptions.ConstraintMap.Add("exists", typeof(KnownRouteValueConstraint));

            var optionsAccessor = new Mock <IOptions <RouteOptions> >();

            optionsAccessor
            .SetupGet(o => o.Value)
            .Returns(routeOptions);
            services
            .Setup(s => s.GetService(typeof(IOptions <RouteOptions>)))
            .Returns(optionsAccessor.Object);

            services
            .Setup(s => s.GetService(typeof(IInlineConstraintResolver)))
            .Returns(new DefaultInlineConstraintResolver(optionsAccessor.Object));

            services
            .Setup(s => s.GetService(typeof(ILoggerFactory)))
            .Returns(new LoggerFactory());

            services
            .Setup(s => s.GetService(typeof(IActionContextAccessor)))
            .Returns(new ActionContextAccessor()
            {
                ActionContext = new ActionContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        RequestServices = services.Object,
                    },
                    RouteData = new RouteData(),
                },
            });

            var actionDescriptorCollectionProvider = new ActionDescriptorCollectionProvider(services.Object);

            services
            .Setup(s => s.GetService(typeof(IActionDescriptorCollectionProvider)))
            .Returns(actionDescriptorCollectionProvider);

            services
            .Setup(s => s.GetService(typeof(IEnumerable <IActionDescriptorProvider>)))
            .Returns(TestInit.GetActionDescriptorProviders());

            services
            .Setup(s => s.GetService(typeof(RoutingMarkerService)))
            .Returns(new RoutingMarkerService());

            services
            .Setup(s => s.GetService(typeof(UrlEncoder)))
            .Returns(UrlEncoder.Default);

            services
            .Setup(s => s.GetService(typeof(IExpressionRouteHelper)))
            .Returns(new ExpressionRouteHelper(actionDescriptorCollectionProvider, new UniqueRouteKeysProvider()));

            var objectPoolProvider = new DefaultObjectPoolProvider();
            var objectPolicy       = new UriBuilderContextPooledObjectPolicy(UrlEncoder.Default);
            var objectPool         = objectPoolProvider.Create(objectPolicy);

            services
            .Setup(s => s.GetService(typeof(ObjectPool <UriBuildingContext>)))
            .Returns(objectPool);

            return(services.Object);
        }
Exemple #23
0
 public UsersControllerTests()
 {
     TestInit.InitializeMapper();
     testHelpers = new TestHelpers();
 }
Exemple #24
0
 public void Init()
 {
     TestInit.SetDataDirectory();
 }
 public DataBaseParallelTest()
 {
     TestInit.Init().Wait();
 }
Exemple #26
0
        public void QueryChannelDayStatus()
        {
            DateTime          today   = DateTime.Today;
            List <FlowDevice> devices = FlowDbSimulator.CreateFlowDevice(TestInit.ServiceProvider, 1, 1, 2, true);
            List <DateTime>   dates   = new List <DateTime>
            {
                today.AddYears(-1),
                today.AddMonths(-1),
                today.AddDays(-1),
                today
            };

            TestInit.RefreshFlowCache(devices);

            FlowDbSimulator.CreateData(TestInit.ServiceProvider, devices, DataCreateMode.Fixed, dates, true);

            ChannelFlowsManager service = TestInit.ServiceProvider.GetRequiredService <ChannelFlowsManager>();

            LaneFlowManager_Alone manager = TestInit.ServiceProvider.GetRequiredService <LaneFlowManager_Alone>();

            foreach (FlowDevice device in devices)
            {
                foreach (var relation in device.FlowDevice_FlowChannels)
                {
                    int laneCount = relation.Channel.Lanes.Count;

                    var status = service.QueryChannelDayStatus(relation.ChannelId);

                    //今日列表
                    Assert.AreEqual(laneCount + 1, status.TodayDayLanes.Count);
                    int sum = 0;
                    for (int i = 0; i < relation.Channel.Lanes.Count; ++i)
                    {
                        var v     = manager.QueryList(relation.Channel.Lanes[i].DataId, DateTimeLevel.Minute, DateTime.Today, DateTime.Now);
                        int total = v.Sum(f => f.Total);
                        sum += total;
                        Assert.AreEqual(total, status.TodayDayLanes[i + 1].Total);
                        Assert.AreEqual(30, status.TodayDayLanes[i + 1].Occupancy);
                        Assert.AreEqual(40, status.TodayDayLanes[i + 1].TimeOccupancy);
                    }

                    Assert.AreEqual(sum, status.TodayDayLanes[0].Total);
                    Assert.AreEqual(30, status.TodayDayLanes[0].Occupancy);
                    Assert.AreEqual(40, status.TodayDayLanes[0].TimeOccupancy);

                    //昨天列表
                    Assert.AreEqual(laneCount + 1, status.YesterdayDayLanes.Count);
                    Assert.AreEqual(11520 * laneCount, status.YesterdayDayLanes[0].Total);
                    for (int i = 1; i < status.YesterdayDayLanes.Count; ++i)
                    {
                        Assert.AreEqual(11520, status.YesterdayDayLanes[i].Total);
                        Assert.AreEqual(30, status.YesterdayDayLanes[i].Occupancy);
                        Assert.AreEqual(40, status.YesterdayDayLanes[i].TimeOccupancy);
                    }

                    //上月列表
                    Assert.AreEqual(laneCount + 1, status.LastMonthDayLanes.Count);
                    Assert.AreEqual(11520 * laneCount, status.LastMonthDayLanes[0].Total);
                    for (int i = 1; i < status.LastMonthDayLanes.Count; ++i)
                    {
                        Assert.AreEqual(11520, status.LastMonthDayLanes[i].Total);
                        Assert.AreEqual(30, status.LastMonthDayLanes[i].Occupancy);
                        Assert.AreEqual(40, status.LastMonthDayLanes[i].TimeOccupancy);
                    }

                    //去年列表
                    Assert.AreEqual(laneCount + 1, status.LastYearDayLanes.Count);
                    Assert.AreEqual(11520 * laneCount, status.LastYearDayLanes[0].Total);
                    for (int i = 1; i < status.LastYearDayLanes.Count; ++i)
                    {
                        Assert.AreEqual(11520, status.LastYearDayLanes[i].Total);
                        Assert.AreEqual(30, status.LastYearDayLanes[i].Occupancy);
                        Assert.AreEqual(40, status.LastYearDayLanes[i].TimeOccupancy);
                    }

                    //今日图表
                    Assert.AreEqual(laneCount + 1, status.TodayDayCharts.Count);
                    Dictionary <int, int> sumValue = new Dictionary <int, int>();
                    for (int i = 0; i < relation.Channel.Lanes.Count; ++i)
                    {
                        for (int h = 0; h < DateTime.Now.Hour + 1; ++h)
                        {
                            var v     = manager.QueryList(relation.Channel.Lanes[i].DataId, DateTimeLevel.Hour, DateTime.Today.AddHours(h), DateTime.Today.AddHours(h));
                            int value = v.Sum(f => f.Total);
                            //今日每小时图表
                            Assert.AreEqual(value, status.TodayDayCharts[i + 1][h].Value);
                            if (sumValue.ContainsKey(h))
                            {
                                sumValue[h] += value;
                            }
                            else
                            {
                                sumValue.Add(h, value);
                            }
                        }
                    }
                    //今日每小时图表总和
                    for (int h = 0; h < DateTime.Now.Hour + 1; ++h)
                    {
                        Assert.AreEqual(sumValue[h], status.TodayDayCharts[0][h].Value);
                    }

                    //昨天图表
                    Assert.AreEqual(laneCount + 1, status.YesterdayDayCharts.Count);
                    //昨天总和图表横轴数量
                    Assert.AreEqual(24, status.YesterdayDayCharts[0].Count);
                    for (int h = 0; h < 24; ++h)
                    {
                        //昨天总和每个横轴的value和remart
                        Assert.AreEqual(480 * laneCount, status.YesterdayDayCharts[0][h].Value);
                        Assert.AreEqual(today.AddDays(-1).AddHours(h).ToString("yyyy-MM-dd HH"), status.YesterdayDayCharts[0][h].Remark);
                    }

                    for (int i = 1; i < status.YesterdayDayCharts.Count; ++i)
                    {
                        //各个车道图表横轴数量
                        Assert.AreEqual(24, status.YesterdayDayCharts[i].Count);
                        for (int h = 0; h < 24; ++h)
                        {
                            //每个横轴的value和remart
                            Assert.AreEqual(480, status.YesterdayDayCharts[i][h].Value);
                            Assert.AreEqual(today.AddDays(-1).AddHours(h).ToString("yyyy-MM-dd HH"), status.YesterdayDayCharts[i][h].Remark);
                        }
                    }

                    //上月图表
                    Assert.AreEqual(laneCount + 1, status.LastMonthDayCharts.Count);
                    Assert.AreEqual(24, status.LastMonthDayCharts[0].Count);
                    for (int h = 0; h < 24; ++h)
                    {
                        Assert.AreEqual(480 * laneCount, status.LastMonthDayCharts[0][h].Value);
                        Assert.AreEqual(today.AddMonths(-1).AddHours(h).ToString("yyyy-MM-dd HH"), status.LastMonthDayCharts[0][h].Remark);
                    }
                    for (int i = 1; i < status.LastMonthDayCharts.Count; ++i)
                    {
                        Assert.AreEqual(24, status.LastMonthDayCharts[i].Count);
                        for (int h = 0; h < 24; ++h)
                        {
                            Assert.AreEqual(480, status.LastMonthDayCharts[i][h].Value);
                            Assert.AreEqual(today.AddMonths(-1).AddHours(h).ToString("yyyy-MM-dd HH"), status.LastMonthDayCharts[i][h].Remark);
                        }
                    }

                    //去年图表
                    Assert.AreEqual(laneCount + 1, status.LastYearDayCharts.Count);
                    Assert.AreEqual(24, status.LastYearDayCharts[0].Count);
                    for (int h = 0; h < 24; ++h)
                    {
                        Assert.AreEqual(480 * laneCount, status.LastYearDayCharts[0][h].Value);
                        Assert.AreEqual(today.AddYears(-1).AddHours(h).ToString("yyyy-MM-dd HH"), status.LastYearDayCharts[0][h].Remark);
                    }
                    for (int i = 1; i < status.LastYearDayCharts.Count; ++i)
                    {
                        Assert.AreEqual(24, status.LastYearDayCharts[i].Count);
                        for (int h = 0; h < 24; ++h)
                        {
                            Assert.AreEqual(480, status.LastYearDayCharts[i][h].Value);
                            Assert.AreEqual(today.AddYears(-1).AddHours(h).ToString("yyyy-MM-dd HH"), status.LastYearDayCharts[i][h].Remark);
                        }
                    }
                }
            }
        }