private async Task ExpireLocation(string callsign, bool shouldUpdate)
        {
            if (shouldUpdate)
            {
                var lr = Fixture.Create <LocationRecord>();
                lr.Callsign = callsign;
                lr.Expired  = false;
                GoodLocations.Add(lr);
            }

            var locations = MockHelpers.CreateMockLocationDbSet(GoodLocations);
            var context   = CreateMockLocationContext(locations.Object);

            var service = new LocationService(context.Object);

            await service.ExpireLocation(callsign);

            if (shouldUpdate)
            {
                foreach (var gl in GoodLocations.Where(l => l.Callsign == callsign))
                {
                    Assert.True(gl.Expired);
                }

                context.Verify(c => c.SaveChangesAsync());
            }
            else
            {
                context.Verify(c => c.SaveChangesAsync(), Times.Never);
            }
        }
Exemple #2
0
        public async Task GetCallsignRecordGoodData()
        {
            GoodLocations.Clear();

            var badRecord = new LocationRecord
            {
                Callsign    = "WR01",
                ReadingTime = DateTimeOffset.Now,
                Latitude    = 1
            };
            var badRecord2 = new LocationRecord
            {
                Callsign    = "WR02",
                ReadingTime = DateTimeOffset.Now.AddDays(-1),
                Latitude    = 1
            };

            GoodLocations.Add(badRecord);
            GoodLocations.Add(badRecord2);

            var goodRecords = new[]
            {
                new LocationRecord
                {
                    Callsign    = "WR02",
                    ReadingTime = DateTimeOffset.Now.AddMinutes(-1),
                    Latitude    = 1
                },
                new LocationRecord
                {
                    Callsign    = "WR02",
                    ReadingTime = DateTimeOffset.Now.AddMinutes(-2),
                    Latitude    = 1
                },
                new LocationRecord
                {
                    Callsign    = "WR02",
                    ReadingTime = DateTimeOffset.Now.AddMinutes(-3),
                    Latitude    = 1
                },
                new LocationRecord
                {
                    Callsign    = "WR02",
                    ReadingTime = DateTimeOffset.Now.AddMinutes(-4),
                    Latitude    = 1
                },
            };

            GoodLocations.AddRange(goodRecords);

            var locations = MockHelpers.CreateMockLocationDbSet(GoodLocations);
            var context   = CreateMockLocationContext(locations.Object);

            var service = new ReportService(context.Object);

            var res = await service.GetCallsignRecord("WR02", DateTimeOffset.Now.AddHours(-1), DateTimeOffset.Now);

            Assert.True(res.OrderBy(l => l.ReadingTime).SequenceEqual(goodRecords.OrderBy(l => l.ReadingTime)));
        }
Exemple #3
0
        private async Task GetCallsignRecord(string callsign)
        {
            var locations = MockHelpers.CreateMockLocationDbSet(GoodLocations);
            var context   = CreateMockLocationContext(locations.Object);

            var service = new ReportService(context.Object);

            await service.GetCallsignRecord(callsign, DateTimeOffset.Now.AddHours(-1), DateTimeOffset.Now);
        }
Exemple #4
0
        public async Task GetAllCallsigns()
        {
            var locations = MockHelpers.CreateMockLocationDbSet(GoodLocations);
            var context   = CreateMockLocationContext(locations.Object);

            var service = new ReportService(context.Object);

            var res = await service.GetAllCallsigns();

            Assert.True(GoodLocations.Select(l => l.Callsign).Distinct().OrderBy(s => s).SequenceEqual(res.OrderBy(s => s)));
        }
        private async Task RegisterLocation(IMEIToCallsign imei, DateTimeOffset readingTime, DateTimeOffset receivedTime, decimal latitude, decimal longitude, bool shouldStore = true, bool shouldUseResolver = false)
        {
            var locations   = MockHelpers.CreateMockLocationDbSet(GoodLocations);
            var context     = CreateMockLocationContext(locations.Object);
            var imeiService = CreateMockIMEIService();
            var container   = new UnityContainer();

            container.RegisterInstance(imeiService.Object);

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));

            var service = new LocationService(context.Object, shouldUseResolver ? null : imeiService.Object);

            await service.RegisterLocation(imei.IMEI, readingTime, receivedTime, latitude, longitude);

            if (shouldStore)
            {
                locations.Verify(l => l.Add(It.Is <LocationRecord>(lr => ValidateLocationRecord(lr, imei, latitude, longitude, readingTime, receivedTime))));
                context.Verify(c => c.SaveChangesAsync());
            }
        }
        public async Task GetLocations()
        {
            GoodLocations.Clear();

            GoodLocations.AddRange(new[]
            {
                new LocationRecord
                {
                    Callsign    = "WR01",
                    ReadingTime = new DateTimeOffset(2016, 1, 1, 1, 1, 1, TimeSpan.Zero),
                    Latitude    = 1,
                    Longitude   = 1
                },
                new LocationRecord
                {
                    Callsign    = "WR01",
                    ReadingTime = new DateTimeOffset(2016, 1, 1, 1, 2, 1, TimeSpan.Zero),
                    Latitude    = 2,
                    Longitude   = 2
                },
                new LocationRecord
                {
                    Callsign    = "WR02",
                    ReadingTime = new DateTimeOffset(2016, 1, 1, 3, 1, 1, TimeSpan.Zero),
                    Latitude    = 3,
                    Longitude   = 3
                },
                new LocationRecord
                {
                    Callsign    = "WR02",
                    ReadingTime = new DateTimeOffset(2016, 1, 1, 1, 1, 1, TimeSpan.Zero),
                    Latitude    = 4,
                    Longitude   = 4
                },
                new LocationRecord
                {
                    Callsign    = "WR03",
                    ReadingTime = new DateTimeOffset(2016, 1, 1, 1, 1, 1, TimeSpan.Zero),
                    Latitude    = 5,
                    Longitude   = 5
                }
            });

            var locations = MockHelpers.CreateMockLocationDbSet(GoodLocations);
            var context   = CreateMockLocationContext(locations.Object);

            var service = new LocationService(context.Object);

            var res = (await service.GetLocations()).ToList();

            var wr01 = res.Single(l => l.Callsign == "WR01");

            Assert.Equal(2, wr01.Latitude);
            Assert.Equal(2, wr01.Longitude);

            var wr02 = res.Single(l => l.Callsign == "WR02");

            Assert.Equal(3, wr02.Latitude);
            Assert.Equal(3, wr02.Longitude);

            var wr03 = res.Single(l => l.Callsign == "WR03");

            Assert.Equal(5, wr03.Latitude);
            Assert.Equal(5, wr03.Longitude);
        }