Ejemplo n.º 1
0
        // POST api/geomarker
        public HttpResponseMessage Post(GeoMarker value)
        {
            if (ModelState.IsValid)
            {
                // Refeactor this to use the IoC container, as soon as I fugure out how it works!
                _geoMarkerService.ProcessGeoMarker(value);

                // Created.
                var response = new HttpResponseMessage(HttpStatusCode.Created);

                // Advise where the new GeoMarker is.
                string uri = Url.Route(null, new { id = value.Id });
                response.Headers.Location = new Uri(Request.RequestUri, uri);

                return response;
            }
            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }
Ejemplo n.º 2
0
        // Returns the number of webcams that can see us at our current location.
        // Is this method doing too much?
        public int ProcessGeoMarker(IGeoMarkerDto geoMarkerDto)
        {
            IEnumerable<IDevice> devices = null;

            // Get devices or create the device if it does not exit and then get it
            devices = GetDevices(geoMarkerDto.DeviceName);
            if (!devices.Any())
            {
                var device = new Device {DeviceName = geoMarkerDto.DeviceName};
                _myBigBroRepository.Add(device);
                _myBigBroRepository.SaveChanges();
                devices = GetDevices(geoMarkerDto.DeviceName);
            }

            // Get the device ID
            var deviceId = devices.First().Id;

            // Create the GeoMarker
            var geoMarker = new GeoMarker
            {
                Id = geoMarkerDto.Id,
                DeviceId = deviceId,
                MarkerDateTime = geoMarkerDto.MarkerDateTime,
                XCoord = geoMarkerDto.XCoord,
                YCoord = geoMarkerDto.YCoord
            };

            // Process
            return ProcessGeoMarker(geoMarker);
        }
Ejemplo n.º 3
0
        public void SetUpUnitTestsWebCamService()
        {
            // arrange - setup mock services and repository
            webCamControl = new Mock<IWebCamControl>();
            location = new Mock<ILocation>();
            geoMarker = new Mock<IGeoMarker>();
            webCam1 = new Mock<IWebCam>();
            webCam2 = new Mock<IWebCam>();
            //device1 = new Mock<IDevice>();
            //device2 = new Mock<IDevice>();
            mockRepository = new Mock<IMyBigBroRepository>();

            // arrange - setup geomarkers
            var geoMarker1 = new GeoMarker
            {
                Id = 234,
                XCoord = 2,
                YCoord = 2,
                MarkerDateTime = new DateTime(2014, 01, 01, 10, 10, 00),
                DeviceId = 1
            };
            var geoMarker2 = new GeoMarker
            {
                Id = 12,
                XCoord = 4,
                YCoord = 4,
                MarkerDateTime = new DateTime(2014, 01, 01, 10, 30, 00),
                DeviceId = 1
            };
            var geoMarker3 = new GeoMarker
            {
                Id = 1,
                XCoord = 6,
                YCoord = 6,
                MarkerDateTime = new DateTime(2014, 01, 01, 10, 45, 00),
                DeviceId = 2
            };

            // arrange - setup captured images
            var capturedImage1 = new CapturedImage
            {
                Id = 345,
                WebCamId = 123,
                DateTimeCaptured = new DateTime(2014, 01, 01, 10, 10, 00),
                Url = "http://test.com/1"
            };
            var capturedImage2 = new CapturedImage
            {
                Id = 14,
                WebCamId = 345,
                DateTimeCaptured = new DateTime(2014, 01, 01, 10, 30, 00),
                Url = "http://test.com/2"
            };
            var capturedImage3 = new CapturedImage
            {
                Id = 2,
                WebCamId = 567,
                DateTimeCaptured = new DateTime(2014, 01, 01, 10, 45, 00),
                Url = "http://test.com/3"
            };

            // arrange - setup geomarkers
            var device1 = new Device
            {
                Id = 1,
                DeviceName = "test1"
            };
            var device2 = new Device
            {
                Id = 2,
                DeviceName = "test2"
            };

            // arrange setup the captured images
            var capturedImageGeoMarker = new CapturedImageGeoMarker();
            capturedImageGeoMarker.Id = 789;
            capturedImageGeoMarker.CapturedImageId = capturedImage1.Id;
            capturedImageGeoMarker.GeoMarkerId = geoMarker1.Id;
            var capturedImageGeoMarker2 = new CapturedImageGeoMarker();
            capturedImageGeoMarker2.Id = 222;
            capturedImageGeoMarker2.CapturedImageId = capturedImage2.Id;
            capturedImageGeoMarker2.GeoMarkerId = geoMarker2.Id;
            var capturedImageGeoMarker3 = new CapturedImageGeoMarker();
            capturedImageGeoMarker3.Id = 333;
            capturedImageGeoMarker3.CapturedImageId = capturedImage3.Id;
            capturedImageGeoMarker3.GeoMarkerId = geoMarker3.Id;

            // arrange - setup the mock behaviour
            mockRepository.Setup(x => x.Set<GeoMarker>()).Returns(new List<GeoMarker> { geoMarker1, geoMarker2, geoMarker3 }.AsQueryable());
            mockRepository.Setup(x => x.Set<CapturedImage>()).Returns(new List<CapturedImage> { capturedImage1, capturedImage2, capturedImage3 }.AsQueryable());
            mockRepository.Setup(x => x.Set<CapturedImageGeoMarker>()).Returns(new List<CapturedImageGeoMarker> { capturedImageGeoMarker, capturedImageGeoMarker2, capturedImageGeoMarker3 }.AsQueryable());
            mockRepository.Setup(x => x.Set<Device>()).Returns(new List<Device> { device1, device2 }.AsQueryable());

            // setup service to test
            geoMarkerService = new GeoMarkerService(webCamControl.Object, location.Object, mockRepository.Object);
        }