示例#1
0
        public async Task <GeofenceDataSingleResult> UpsertBoundary(string projectUid, [FromBody] BoundaryRequest request)
        {
            Log.LogInformation(
                $"{ToString()}.{nameof(UpsertBoundary)}: CustomerUID={CustomerUid} BoundaryRequest: {JsonConvert.SerializeObject(request)}");

            var requestFull = BoundaryRequestFull.Create(
                CustomerUid,
                IsApplication,
                await GetProject(projectUid),
                GetUserId,
                request);

            requestFull.Validate(ServiceExceptionHandler);
            requestFull.Request.BoundaryPolygonWKT = GeofenceValidation.MakeGoodWkt(requestFull.Request.BoundaryPolygonWKT);

            var getResult = await BoundaryHelper.GetProjectBoundaries(
                Log, ServiceExceptionHandler,
                projectUid, _projectRepository, _geofenceRepository).ConfigureAwait(false);

            if (getResult.GeofenceData.Any(g => request.Name.Equals(g.GeofenceName, StringComparison.OrdinalIgnoreCase)))
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 62);
            }

            var executor = RequestExecutorContainer.Build <UpsertBoundaryExecutor>(ConfigStore, Logger,
                                                                                   ServiceExceptionHandler, _geofenceRepository, _projectRepository, ProjectProxy);
            var result = await executor.ProcessAsync(requestFull) as GeofenceDataSingleResult;

            Log.LogInformation(
                $"{ToString()}.UpsertBoundary Completed: resultCode: {result?.Code} result: {JsonConvert.SerializeObject(result)}");
            return(result);
        }
示例#2
0
        public async Task UpsertBoundaryExecutor()
        {
            string custUid     = Guid.NewGuid().ToString();
            string userUid     = Guid.NewGuid().ToString();
            string projectUid  = Guid.NewGuid().ToString();
            string name        = "not entry";
            string geometryWKT = "whatever";

            var configStore = serviceProvider.GetRequiredService <IConfigurationStore>();
            var logger      = serviceProvider.GetRequiredService <ILoggerFactory>();

            var geofenceRepo = new Mock <GeofenceRepository>(configStore, logger);
            var geofence     = new Geofence
            {
                CustomerUID     = custUid,
                UserUID         = userUid,
                Name            = name,
                GeometryWKT     = geometryWKT,
                GeofenceType    = GeofenceType.Filter,
                LastActionedUTC = DateTime.UtcNow
            };

            geofenceRepo.As <IGeofenceRepository>().Setup(g => g.GetGeofence(It.IsAny <string>())).ReturnsAsync(geofence);
            geofenceRepo.As <IGeofenceRepository>().Setup(g => g.StoreEvent(It.IsAny <CreateGeofenceEvent>())).ReturnsAsync(1);

            var projectRepo = new Mock <ProjectRepository>(configStore, logger);

            projectRepo.As <IProjectRepository>().Setup(p => p.GetAssociatedGeofences(It.IsAny <string>())).ReturnsAsync(new List <ProjectGeofence>());
            projectRepo.As <IProjectRepository>().Setup(p => p.StoreEvent(It.IsAny <AssociateProjectGeofence>())).ReturnsAsync(1);

            var productivity3dV2ProxyNotification = new Mock <IProductivity3dV2ProxyNotification>();

            productivity3dV2ProxyNotification.Setup(ps => ps.NotifyFilterChange(It.IsAny <Guid>(), It.IsAny <Guid>(), null)).ReturnsAsync(new BaseMasterDataResult());

            var request = BoundaryRequestFull.Create
                          (
                custUid,
                false,
                new ProjectData {
                ProjectUID = projectUid
            },
                userUid,
                new BoundaryRequest {
                BoundaryUid = null, Name = name, BoundaryPolygonWKT = geometryWKT
            }
                          );

            var executor =
                RequestExecutorContainer.Build <UpsertBoundaryExecutor>(configStore, logger, serviceExceptionHandler,
                                                                        geofenceRepo.Object, projectRepo.Object);
            var result = await executor.ProcessAsync(request) as GeofenceDataSingleResult;

            Assert.NotNull(result);
            Assert.Equal(name, result.GeofenceData.GeofenceName);
            Assert.Equal(geometryWKT, result.GeofenceData.GeometryWKT);
        }
示例#3
0
        public void BoundaryRequestValidation_MissingProjectUid()
        {
            var requestFull =
                BoundaryRequestFull.Create(custUid, false, null, userUid,
                                           new BoundaryRequest {
                BoundaryUid = boundaryUid, Name = Name, BoundaryPolygonWKT = GeometryWKT
            });
            var ex = Assert.Throws <ServiceException>(() => requestFull.Validate(serviceExceptionHandler));

            Assert.Contains("2001", ex.GetContent);
            Assert.Contains("Invalid projectUid.", ex.GetContent);
        }
示例#4
0
        public void BoundaryRequestValidation_InvalidBoundaryUid()
        {
            var requestFull =
                BoundaryRequestFull.Create(custUid, false, new ProjectData {
                ProjectUID = projectUid
            }, userUid,
                                           new BoundaryRequest {
                BoundaryUid = "this is so wrong", Name = Name, BoundaryPolygonWKT = GeometryWKT
            });
            var ex = Assert.Throws <ServiceException>(() => requestFull.Validate(serviceExceptionHandler));

            Assert.Contains("2059", ex.GetContent);
            Assert.Contains("Invalid boundaryUid.", ex.GetContent);
        }
示例#5
0
        public void BoundaryRequestValidation_BoundaryWKTInvalidFormat()
        {
            var requestFull =
                BoundaryRequestFull.Create(custUid, false, new ProjectData {
                ProjectUID = projectUid
            }, userUid,
                                           new BoundaryRequest {
                BoundaryUid = boundaryUid, Name = Name, BoundaryPolygonWKT = "Nothing here"
            });

            var ex = Assert.Throws <ServiceException>(() => requestFull.Validate(serviceExceptionHandler));

            Assert.Contains("2071", ex.GetContent);
            Assert.Contains("Invalid boundary polygon WKT. Invalid format.", ex.GetContent);
        }
示例#6
0
        public void BoundaryRequestValidation_BoundaryWKTMissing()
        {
            var requestFull =
                BoundaryRequestFull.Create(custUid, false, new ProjectData {
                ProjectUID = projectUid
            }, userUid,
                                           new BoundaryRequest {
                BoundaryUid = boundaryUid, Name = Name, BoundaryPolygonWKT = null
            });

            var ex = Assert.Throws <ServiceException>(() => requestFull.Validate(serviceExceptionHandler));

            Assert.Contains("2069", ex.GetContent);
            Assert.Contains("Invalid boundary polygon WKT. Should not be null.", ex.GetContent);
        }
示例#7
0
        public void BoundaryRequestValidation_BoundaryWKTLessThan3Points()
        {
            var requestFull =
                BoundaryRequestFull.Create(custUid, false, new ProjectData {
                ProjectUID = projectUid
            }, userUid,
                                           new BoundaryRequest
            {
                BoundaryUid        = boundaryUid,
                Name               = Name,
                BoundaryPolygonWKT = "POLYGON((172.595831670724 -43.5427038560109))"
            });

            var ex = Assert.Throws <ServiceException>(() => requestFull.Validate(serviceExceptionHandler));

            Assert.Contains("2070", ex.GetContent);
            Assert.Contains("Invalid boundary polygon WKT. Should be > 3 points.", ex.GetContent);
        }
示例#8
0
        public async Task UpsertBoundaryExecutor_BoundaryUidNotSupported()
        {
            string custUid    = Guid.NewGuid().ToString();
            string userUid    = Guid.NewGuid().ToString();
            string projectUid = Guid.NewGuid().ToString();
            string name       = "name";

            var request = BoundaryRequestFull.Create(custUid, false, new ProjectData()
            {
                ProjectUID = projectUid
            }, userUid, new BoundaryRequest {
                BoundaryUid = Guid.NewGuid().ToString(), Name = name, BoundaryPolygonWKT = geometryWKT
            });

            var executor         = RequestExecutorContainer.Build <UpsertBoundaryExecutor>(ConfigStore, Logger, ServiceExceptionHandler, GeofenceRepo, ProjectRepo, ProjectProxy);
            var serviceException = await Assert.ThrowsExceptionAsync <ServiceException>(async() => await executor.ProcessAsync(request));

            Assert.IsTrue(serviceException.GetContent.Contains("2061"));
            Assert.IsTrue(serviceException.GetContent.Contains("UpsertBoundary. Update not supported"));
        }
示例#9
0
        public async Task UpsertBoundaryExecutor_NoExistingBoundary()
        {
            string custUid    = Guid.NewGuid().ToString();
            string userUid    = Guid.NewGuid().ToString();
            string projectUid = Guid.NewGuid().ToString();
            string name       = "name";

            var request = BoundaryRequestFull.Create(custUid, false, new ProjectData()
            {
                ProjectUID = projectUid
            }, userUid, new BoundaryRequest {
                Name = name, BoundaryPolygonWKT = geometryWKT
            });

            var executor = RequestExecutorContainer.Build <UpsertBoundaryExecutor>(ConfigStore, Logger, ServiceExceptionHandler, GeofenceRepo, ProjectRepo, ProjectProxy);
            var result   = await executor.ProcessAsync(request) as GeofenceDataSingleResult;

            Assert.IsNotNull(result, "executor should always return a result");
            Assert.IsNotNull(result.GeofenceData, "executor returned null geofence");
            Assert.AreEqual(name, result.GeofenceData.GeofenceName, "executor returned incorrect GeofenceName");
            Assert.AreEqual(geometryWKT, result.GeofenceData.GeometryWKT, "executor returned incorrect geometryWKT");
        }
示例#10
0
        public void MapBoundaryRequestToUpdateFilterEvent()
        {
            var request = BoundaryRequestFull.Create
                          (
                Guid.NewGuid().ToString(),
                false,
                new ProjectData {
                ProjectUID = Guid.NewGuid().ToString()
            },
                Guid.NewGuid().ToString(),
                new BoundaryRequest {
                BoundaryUid = Guid.NewGuid().ToString(), Name = "the name", BoundaryPolygonWKT = "the WKT"
            }
                          );

            var result = AutoMapperUtility.Automapper.Map <UpdateGeofenceEvent>(request);

            Assert.Equal(request.UserUid, result.UserUID.ToString());
            Assert.Equal(request.Request.BoundaryUid, result.GeofenceUID.ToString());
            Assert.Equal(request.Request.Name, result.GeofenceName);
            Assert.Equal(request.Request.BoundaryPolygonWKT, result.GeometryWKT);
            Assert.Equal(request.GeofenceType.ToString(), result.GeofenceType);
        }