public async Task AddLandmarkEmptyName()
        {
            var locationService = CreateMockLocationService();
            var imeiService = CreateMockIMEIService();

            var controller = new MapController(locationService.Object, imeiService.Object, null);

            var res = await controller.AddLandmark(string.Empty, TestLatitude, TestLongitude);

            var view = res as HttpStatusCodeResult;

            Assert.NotNull(view);
            Assert.Equal(HttpStatusCode.BadRequest, (HttpStatusCode)view.StatusCode);
        }
        public async Task AddLandmarkGoodData()
        {
            var locationService = CreateMockLocationService();
            var imeiService = CreateMockIMEIService();

            var controller = new MapController(locationService.Object, imeiService.Object, null);

            var res = await controller.AddLandmark(TestLandmark, TestLatitude, TestLongitude);

            locationService.Verify(l => l.RegisterLandmark(It.Is<string>(s => s == TestLandmark), It.Is<decimal>(s => s == TestLatitude), It.Is<decimal>(s => s == TestLongitude), null));

            var view = res as HttpStatusCodeResult;

            Assert.NotNull(view);
            Assert.Equal(HttpStatusCode.Created, (HttpStatusCode)view.StatusCode);
        }
        public async Task RemoveLandmark()
        {
            var locationService = CreateMockLocationService();
            var imeiService = CreateMockIMEIService();

            var controller = new MapController(locationService.Object, imeiService.Object, null);

            var res = await controller.ClearLandmark(TestId);

            var view = res as HttpStatusCodeResult;

            Assert.NotNull(view);
            Assert.Equal(HttpStatusCode.OK, (HttpStatusCode)view.StatusCode);
        }
        public void Index()
        {
            var locationService = CreateMockLocationService();
            var imeiService = CreateMockIMEIService();

            var controller = new MapController(locationService.Object, imeiService.Object, null);

            var res = controller.Index();

            var view = res as ViewResult;

            Assert.NotNull(view);
        }
        public async Task GetLocations()
        {
            var locationService = CreateMockLocationService();
            var imeiService = CreateMockIMEIService();
            var logService = CreateMockLogService();

            var controller = new MapController(locationService.Object, imeiService.Object, logService.Object);

            var httpContext = CreateMockHttpContext();
            var context = new ControllerContext { HttpContext = httpContext.Object };

            controller.ControllerContext = context;

            var res = await controller.GetLocations();
            Assert.NotNull(res);

            var data = res.Data as IEnumerable<LocationViewModel>;
            Assert.NotNull(data);

            var locationViewModels = data as IList<LocationViewModel> ?? data.ToList();
            foreach (var d in locationViewModels)
            {
                var original = Locations.First(l => l.Id == d.Id);
                Assert.Equal(original.Callsign, d.Callsign);
                Assert.Equal(original.ReadingTime, d.ReadingTime);
                Assert.Equal(original.Latitude, d.Latitude);
                Assert.Equal(original.Longitude, d.Longitude);
                Assert.Equal(original.Type, d.Type);
            }

            Assert.Equal(Locations.Count(), locationViewModels.Count());

            logService.Verify(l => l.LogMapInUse(TestUsername));
        }
        public async Task GetLandmarks()
        {
            var locationService = CreateMockLocationService();
            var imeiService = CreateMockIMEIService();
            var logService = CreateMockLogService();

            var controller = new MapController(locationService.Object, imeiService.Object, logService.Object);

            var httpContext = CreateMockHttpContext();
            var context = new ControllerContext { HttpContext = httpContext.Object };

            controller.ControllerContext = context;

            var res = await controller.GetLandmarks();
            Assert.NotNull(res);

            var data = res.Data as IEnumerable<Landmark>;
            Assert.NotNull(data);

            var enumerable = data as IList<Landmark> ?? data.ToList();
            foreach (var d in enumerable)
            {
                var original = Landmarks.First(l => l.Id == d.Id);
                Assert.Equal(original.Name, d.Name);
                Assert.Equal(original.Latitude, d.Latitude);
                Assert.Equal(original.Longitude, d.Longitude);
                Assert.Equal(original.Expiry, d.Expiry);
            }

            Assert.Equal(Locations.Count(), enumerable.Count);

            logService.Verify(l => l.LogMapInUse(TestUsername));
        }
        public async Task CheckInNoTime()
        {
            var locationService = CreateMockLocationService();
            var imeiService = CreateMockIMEIService();

            var controller = new MapController(locationService.Object, imeiService.Object, null);

            var testDate = TestDate.ToString("ddMMyy");

            var res = await controller.CheckIn(TestIMEI, TestLatitude, TestLongitude, null, testDate);

            var view = res as ContentResult;

            Assert.NotNull(view);
        }
        public async Task CheckInGoodData()
        {
            var locationService = CreateMockLocationService();
            var imeiService = CreateMockIMEIService();

            var controller = new MapController(locationService.Object, imeiService.Object, null);

            var testDate = TestDate.ToString("ddMMyy");
            var testTime = TestDate.ToString("HHmmss.fff");

            var res = await controller.CheckIn(TestIMEI, TestLatitude, TestLongitude, testTime, testDate);

            locationService.Verify(LocationRegisterExpression);

            var view = res as ContentResult;

            Assert.NotNull(view);
        }