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);
        }
        public async Task GetLandmarks()
        {
            var lm = Fixture.Create<Landmark>();
            lm.Expiry = DateTimeOffset.Now.AddDays(-1);
            GoodLandmarks.Add(lm);

            lm = Fixture.Create<Landmark>();
            lm.Expiry = DateTimeOffset.Now.AddDays(1);
            GoodLandmarks.Add(lm);

            var landmarks = CreateMockLandmarkDbSet();
            var context = CreateMockLocationContext(landmarks: landmarks.Object);

            var service = new LocationService(context.Object);

            var res = await service.GetLandmarks();

            Assert.True(GoodLandmarks.Where(l => (l.Expiry - DateTimeOffset.Now).TotalSeconds > 5).OrderBy(l => l.Id).SequenceEqual(res.OrderBy(l => l.Id)));
        }
        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());
            }
        }
        private async Task RegisterLandmark(string name, decimal latitude, decimal longitude, DateTimeOffset? expiry, bool shouldStore)
        {
            var landmarks = CreateMockLandmarkDbSet();
            var context = CreateMockLocationContext(landmarks: landmarks.Object);

            var service = new LocationService(context.Object);

            await service.RegisterLandmark(name, latitude, longitude, expiry);

            if (shouldStore)
            {
                landmarks.Verify(l => l.Add(It.Is<Landmark>(lr => ValidateLandmarkRecord(lr, name, latitude, longitude, expiry))));
                context.Verify(c => c.SaveChangesAsync());
            }
        }
        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);
            }
        }
        private async Task ClearLandmark(int id, Landmark linkedObject = null)
        {
            var landmarks = CreateMockLandmarkDbSet();
            var context = CreateMockLocationContext(landmarks: landmarks.Object);

            var service = new LocationService(context.Object);

            await service.ClearLandmark(id);

            if (linkedObject != null)
            {
                Assert.True((linkedObject.Expiry - DateTimeOffset.Now).TotalSeconds < -DateTimeTolerance);
                context.Verify(c => c.SaveChangesAsync());
            }
            else
            {
                context.Verify(c => c.SaveChangesAsync(), Times.Never);
            }
        }