Ejemplo n.º 1
0
        public void CreateBoundary_HappyPath()
        {
            const string boundaryName = "Boundary Web test 3";

            this.Msg.Title(boundaryName, "Create boundary");

            var boundaryRequest = BoundaryRequest.Create(string.Empty, boundaryName, boundaryWKT);
            var boundary        = JsonConvert.SerializeObject(boundaryRequest, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });
            var responseCreate = ts.CallFilterWebApi($"api/v1/boundary/{ProjectUid}", "PUT", boundary);

            Assert.AreNotEqual(string.Empty, responseCreate, "Boundary WKT not found from PUT request");
            var boundaryResponse = JsonConvert.DeserializeObject <GeofenceDataSingleResult>(responseCreate, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });

            Assert.AreEqual(boundaryWKT, boundaryResponse.GeofenceData.GeometryWKT, "Boundary WKT doesn't match for PUT request");
            Assert.AreEqual(boundaryName, boundaryResponse.GeofenceData.GeofenceName, "Boundary name doesn't match for PUT request");
            var boundaryUid         = boundaryResponse.GeofenceData.GeofenceUID;
            var responseGet         = ts.CallFilterWebApi($"api/v1/boundary/{ProjectUid}?boundaryUid={boundaryUid}", "GET");
            var boundaryResponseGet = JsonConvert.DeserializeObject <GeofenceDataSingleResult>(responseGet, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });

            Assert.AreEqual(boundaryWKT, boundaryResponseGet.GeofenceData.GeometryWKT, "Boundary WKT doesn't match for GET request");
            Assert.AreEqual(boundaryName, boundaryResponseGet.GeofenceData.GeofenceName, "Boundary name doesn't match for GET request");
        }
Ejemplo n.º 2
0
        public void DeleteBoundary_HappyPath()
        {
            const string boundaryName = "Boundary Web test 4";

            this.Msg.Title(boundaryName, "Create then delete boundary");

            var boundaryRequest = BoundaryRequest.Create(string.Empty, boundaryName, boundaryWKT);
            var boundary        = JsonConvert.SerializeObject(boundaryRequest, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });
            var response         = ts.CallFilterWebApi($"api/v1/boundary/{ProjectUid}", "PUT", boundary);
            var boundaryResponse = JsonConvert.DeserializeObject <GeofenceDataSingleResult>(response, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });
            var boundaryUid    = boundaryResponse.GeofenceData.GeofenceUID;
            var responseDelete = ts.CallFilterWebApi($"api/v1/boundary/{ProjectUid}?boundaryUid={boundaryUid}", "DELETE");
            var responseDel    = JsonConvert.DeserializeObject <ContractExecutionResult>(responseDelete, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });

            Assert.AreEqual("success", responseDel.Message, "delete call to wep api expects success");

            var responseGet = ts.CallFilterWebApi($"api/v1/boundary/{ProjectUid}?boundaryUid={boundaryUid}", "GET");
            var respGet     = JsonConvert.DeserializeObject <GeofenceDataSingleResult>(responseGet, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });

            Assert.AreEqual("GetBoundary By BoundaryUid. The requested Boundary does not exist, or does not belong to the requesting project or filter.", respGet.Message,
                            "Expecting an error message to say the boundary does not exist.");
        }
Ejemplo n.º 3
0
        public void CreateFilterWithBoundaryThenDeleteBoundary(FilterType filterType)
        {
            ts.DeleteAllBoundariesAndAssociations();

            const string filterName = "Filter Web test 5";

            Msg.Title(filterName, $"Create {filterType} filter with boundary and delete boundary");

            var boundaryWkt     = GenerateWKTPolygon();
            var boundaryName    = filterName + " - boundary";
            var boundaryRequest = BoundaryRequest.Create(string.Empty, boundaryName, boundaryWkt);
            var boundary        = JsonConvert.SerializeObject(boundaryRequest, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });
            var responseCreate   = ts.CallFilterWebApi($"api/v1/boundary/{ProjectUid}", "PUT", boundary);
            var boundaryResponse = JsonConvert.DeserializeObject <GeofenceDataSingleResult>(responseCreate, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });
            var boundaryUid = boundaryResponse.GeofenceData.GeofenceUID;

            var filterJson    = CreateTestFilter(polygonUid: boundaryUid.ToString());
            var filterRequest = FilterRequest.Create(string.Empty, filterName, filterJson, filterType);
            var filter        = JsonConvert.SerializeObject(filterRequest, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });

            responseCreate = ts.CallFilterWebApi($"api/v1/filter/{ProjectUid}", "PUT", filter);
            var filterResponse = JsonConvert.DeserializeObject <FilterDescriptorSingleResult>(responseCreate, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });
            var filterUid          = filterResponse.FilterDescriptor.FilterUid;
            var hydratedFilterJson = CreateTestFilter(polygonUid: boundaryUid.ToString(), polygonName: boundaryName,
                                                      polygonPoints: GetPointsFromWkt(boundaryWkt), polygonType: GeofenceType.Filter);

            var responseDelete  = ts.CallFilterWebApi($"api/v1/boundary/{ProjectUid}?boundaryUid={boundaryUid}", "DELETE");
            var filterResponse1 = JsonConvert.DeserializeObject <FilterDescriptorSingleResult>(responseDelete, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });

            Assert.AreEqual(0, filterResponse1.Code, "  Expecting a sucessful result but got " + filterResponse1.Message);

            var responseGet       = ts.CallFilterWebApi($"api/v1/filter/{ProjectUid}?filterUid={filterUid}", "GET");
            var filterResponseGet = JsonConvert.DeserializeObject <FilterDescriptorSingleResult>(responseGet, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });

            Assert.AreEqual(filterRequest.Name, filterResponseGet.FilterDescriptor.Name, "Filter name doesn't match for GET request");
            Assert.AreEqual(hydratedFilterJson, filterResponseGet.FilterDescriptor.FilterJson, "JSON Filter doesn't match for GET request");
            Assert.AreEqual(filterRequest.FilterType, filterResponseGet.FilterDescriptor.FilterType, "Filter type doesn't match for GET request");
        }
Ejemplo n.º 4
0
        private static SqlGeographyBuilder GetSearchArea(BoundaryRequest data)
        {
            var searchArea = new SqlGeographyBuilder();

            searchArea.SetSrid(4326);
            searchArea.BeginGeography(OpenGisGeographyType.Polygon);
            searchArea.BeginFigure(data.NorthEast.Lat, data.NorthEast.Lng);
            searchArea.AddLine(data.NorthWest.Lat, data.NorthWest.Lng);
            searchArea.AddLine(data.SouthWest.Lat, data.SouthWest.Lng);
            searchArea.AddLine(data.SouthEast.Lat, data.SouthEast.Lng);
            searchArea.AddLine(data.NorthEast.Lat, data.NorthEast.Lng);
            searchArea.EndFigure();
            searchArea.EndGeography();
            return(searchArea);
        }
Ejemplo n.º 5
0
        public IEnumerable <dynamic> Get([FromUri] BoundaryRequest data)
        {
            using (var connection = GetConnection())
            {
                connection.Open();
                SqlGeographyBuilder searchArea = GetSearchArea(data);

                if (data.ZoomLevel >= 10 && data.ZoomLevel < 13)
                {
                    return(GetTownships(connection, searchArea, data.ZoomLevel));
                }
                if (data.ZoomLevel >= 13 && data.ZoomLevel < 15)
                {
                    return(GetSections(connection, searchArea, data.ZoomLevel));
                }
                if (data.ZoomLevel >= 15)
                {
                    return(GetLSDs(connection, searchArea, data.ZoomLevel));
                }
                return(new List <dynamic>());
            }
        }
Ejemplo n.º 6
0
        public void CreateBoundary_SameNameDifferentProject()
        {
            const string boundaryName = "Boundary Web test 2";

            this.Msg.Title(boundaryName, "Create boundary with same name in different project");

            var boundaryRequest = BoundaryRequest.Create(string.Empty, boundaryName, boundaryWKT);
            var boundary        = JsonConvert.SerializeObject(boundaryRequest, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });
            var responseCreate   = ts.CallFilterWebApi($"api/v1/boundary/{ProjectUid}", "PUT", boundary);
            var boundaryResponse = JsonConvert.DeserializeObject <GeofenceDataSingleResult>(responseCreate, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });

            Assert.AreEqual("success", boundaryResponse.Message, "Expecting success (1)");
            //Now create in another project
            responseCreate   = ts.CallFilterWebApi($"api/v1/boundary/{ProjectUid2}", "PUT", boundary);
            boundaryResponse = JsonConvert.DeserializeObject <GeofenceDataSingleResult>(responseCreate, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });
            Assert.AreEqual("success", boundaryResponse.Message, "Expecting success (2)");
        }
Ejemplo n.º 7
0
        public void CreateBoundary_DuplicateNameNotValid()
        {
            const string boundaryName = "Boundary Web test 1";

            this.Msg.Title(boundaryName, "Create boundary with duplicate name");

            var boundaryRequest = BoundaryRequest.Create(string.Empty, boundaryName, boundaryWKT);
            var boundary        = JsonConvert.SerializeObject(boundaryRequest, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });
            var responseCreate   = ts.CallFilterWebApi($"api/v1/boundary/{ProjectUid}", "PUT", boundary);
            var boundaryResponse = JsonConvert.DeserializeObject <GeofenceDataSingleResult>(responseCreate, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });

            Assert.AreEqual("success", boundaryResponse.Message, "Expecting success");
            //Now duplicate
            responseCreate   = ts.CallFilterWebApi($"api/v1/boundary/{ProjectUid}", "PUT", boundary);
            boundaryResponse = JsonConvert.DeserializeObject <GeofenceDataSingleResult>(responseCreate, new JsonSerializerSettings {
                DateTimeZoneHandling = DateTimeZoneHandling.Unspecified
            });
            Assert.AreEqual("Duplicate boundary name", boundaryResponse.Message, "Expecting duplicate boundary name");
            Assert.AreEqual(2062, boundaryResponse.Code, "Wrong error code");
        }
Ejemplo n.º 8
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);
        }