コード例 #1
0
        public void UpdateProjectBoundaryTest()
        {
            var customerUid = new Guid("560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97");
            //var accountTrn = "trn::profilex:us-west-2:account:{customerUid}";
            string projectUid = "560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97";
            string projectTrn = TRNHelper.MakeTRN(projectUid, TRNHelper.TRN_PROJECT);

            var projectBoundary = new ProjectBoundary()
            {
                type        = "Polygon",
                coordinates = new List <List <double[]> > {
                    new List <double[]> {
                        new [] { 151.3, 1.2 }, new[] { 151.4, 1.2 }, new[] { 151.4, 1.3 }, new[] { 151.4, 1.4 }, new[] { 151.3, 1.2 }
                    }
                }
            };

            string route       = $"/projects/{projectTrn}/boundary";
            var    expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Update a projects boundary", mockWebRequest, null, expectedUrl, HttpMethod.Post, projectBoundary, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsProjectClient>();
                await client.UpdateProjectBoundary(new Guid(projectUid), projectBoundary);

                return(true);
            });
        }
コード例 #2
0
        /// <summary>
        ///   Update a project boundary
        /// </summary>
        public async Task UpdateProjectBoundary(Guid projectUid, ProjectBoundary projectBoundary, IHeaderDictionary customHeaders = null)
        {
            log.LogDebug($"{nameof(UpdateProjectBoundary)}: projectUid {projectUid} projectBoundary {JsonConvert.SerializeObject(projectBoundary)}");

            var projectTrn = TRNHelper.MakeTRN(projectUid);

            await UpdateData($"/projects/{projectTrn}/boundary", projectBoundary, null, customHeaders);
        }
コード例 #3
0
        public async Task UpdateProjectBoundaryTest()
        {
            // test requires a user token.
            var client   = ServiceProvider.GetRequiredService <ICwsProjectClient>();
            var boundary = new ProjectBoundary
            {
                type        = "POLYGON",
                coordinates = new List <List <double[]> >
                {
                    new List <double[]>
                    {
                        new [] { 172.606, -43.574 },
                        new [] { 172.606, -43.574 },
                        new [] { 172.614, -43.578 },
                        new [] { 172.615, -43.577 },
                        new [] { 172.617, -43.573 },
                        new [] { 172.610, -43.570 },
                        new [] { 172.606, -43.574 }
                    }
                }
            };

            try
            {
                await client.UpdateProjectBoundary(new Guid(mystagingProject), boundary, CustomHeaders());
            }
            catch (Exception e)
            {
                Assert.Contains(HttpStatusCode.BadRequest.ToString(), e.Message);
                Assert.Contains(":9056,", e.Message);

                /*
                 * This call returns: (possibly because this is application context?)
                 * BadRequest {"status":400,"code":9056,"message":"Bad request","moreInfo":"Please provide this id to support, while contacting, TraceId 5e9a82a7ad9caf287518ec873da80845","timestamp":1587184295988}
                 *
                 * Postman returns:
                 * {
                 *  "status": 400,
                 *  "code": 9006,
                 *  "message": "Account not found or not active",
                 *  "moreInfo": "Please provide this id to support, while contacting, TraceId 5e9a80357074c0914b66ae9cdcf6dfa7",
                 *  "timestamp": 1587183669699,
                 *  "fieldErrors": [
                 *      {
                 *          "field": "accountId",
                 *          "attemptedValue": "trn::profilex:us-west-2:account:158ef953-4967-4af7-81cc-952d47cb6c6"
                 *      }
                 *  ]
                 * }
                 */
            }

            //Assert.NotNull(result);
            //Assert.NotNull(result.Id);
        }
コード例 #4
0
        /// <summary>
        /// Maps a CWS project boundary to a project WKT boundary
        /// </summary>
        public static string ProjectBoundaryToWKT(ProjectBoundary boundary)
        {
            //Should always be a boundary but just in case
            if (boundary == null || boundary.coordinates.Count == 0)
            {
                return(null);
            }

            // CWS boundary is always closed ?
            return(boundary.coordinates.ToPolygonWKT());
        }
コード例 #5
0
        public void UpdateProjectBoundary(string projectTrn, [Mvc.FromBody] ProjectBoundary projectBoundary)
        {
            Logger.LogInformation($"{nameof(UpdateProjectBoundary)}: projectTrn {projectTrn} projectBoundary {JsonConvert.SerializeObject(projectBoundary)}");

            foreach (var projectDict in _projects)
            {
                if (projectDict.Value.ContainsKey(projectTrn))
                {
                    projectDict.Value[projectTrn].ProjectSettings.Boundary = projectBoundary;
                    Logger.LogInformation($"{nameof(UpdateProjectBoundary)}: project found and updated {JsonConvert.SerializeObject(projectDict.Value[projectTrn])}");
                }
            }

            Logger.LogInformation($"{nameof(UpdateProjectBoundary)}: project not found");
        }
コード例 #6
0
        public void MapCWSFormatToWkt()
        {
            var cwsCoordinates = new List <List <double[]> > {
                new List <double[]> {
                    new[] { 150.3, 1.2 }, new[] { 150.4, 1.2 }, new[] { 150.4, 1.3 }, new[] { 150.4, 1.4 }, new[] { 150.3, 1.2 }
                }
            };
            var ProjectBoundary = new ProjectBoundary()
            {
                type = "Polygon", coordinates = cwsCoordinates
            };
            var expectedWktPolygon = "POLYGON((150.3 1.2,150.4 1.2,150.4 1.3,150.4 1.4,150.3 1.2))";

            var wktBoundary = GeometryConversion.ProjectBoundaryToWKT(ProjectBoundary);

            Assert.Equal(expectedWktPolygon, wktBoundary);
        }
コード例 #7
0
        public void MapWKTToCWSFormat()
        {
            var cwsCoordinates = new List <List <double[]> > {
                new List <double[]> {
                    new[] { 150.3, 1.2 }, new[] { 150.4, 1.2 }, new[] { 150.4, 1.3 }, new[] { 150.4, 1.4 }, new[] { 150.3, 1.2 }
                }
            };
            var expectedProjectBoundary = new ProjectBoundary()
            {
                type = "Polygon", coordinates = cwsCoordinates
            };
            var wktPolygon = "POLYGON((150.3 1.2,150.4 1.2,150.4 1.3,150.4 1.4,150.3 1.2))";

            var cwsBoundary = GeometryConversion.MapProjectBoundary(wktPolygon);

            Assert.Equal(expectedProjectBoundary.type, cwsBoundary.type);
            Assert.Equal(expectedProjectBoundary.coordinates, cwsBoundary.coordinates);
        }
コード例 #8
0
        public GetProjectsForDeviceExecutorTests()
        {
            var loggerFactory     = new LoggerFactory().AddSerilog(SerilogExtensions.Configure("VSS.Project.WebApi.log"));
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging();
            serviceCollection.AddSingleton(loggerFactory);
            serviceCollection
            .AddSingleton <IConfigurationStore, GenericConfiguration>()
            .AddTransient <IServiceExceptionHandler, ServiceExceptionHandler>()
            .AddTransient <IErrorCodesProvider, ProjectErrorCodesProvider>();

            IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

            _serviceExceptionHandler = serviceProvider.GetRequiredService <IServiceExceptionHandler>();
            _configStore             = serviceProvider.GetRequiredService <IConfigurationStore>();
            _logger = serviceProvider.GetRequiredService <ILoggerFactory>();
            _serviceExceptionHandler = serviceProvider.GetRequiredService <IServiceExceptionHandler>();
            _customHeaders           = new HeaderDictionary();

            _customerUid     = Guid.NewGuid().ToString();
            _deviceUid       = Guid.NewGuid().ToString();
            _projectUid      = Guid.NewGuid().ToString();
            _projectName     = "the Project Name";
            _boundaryString  = "POLYGON((172.6 -43.5,172.6 -43.5003,172.603 -43.5003,172.603 -43.5,172.6 -43.5))";
            _projectBoundary = new ProjectBoundary()
            {
                type        = "Polygon",
                coordinates = new List <List <double[]> > {
                    new List <double[]> {
                        new [] { 172.6, -43.5 }, new[] { 172.6, -43.5003 }, new[] { 172.603, -43.5003 }, new[] { 172.603, -43.5 }, new[] { 172.6, -43.5 }
                    }
                }
            };
            _timeZone = "New Zealand Standard Time";
        }
コード例 #9
0
 public Task UpdateProjectBoundary(Guid projectUid, ProjectBoundary projectBoundary, IHeaderDictionary customHeaders = null)
 {
     log.LogDebug($"{nameof(UpdateProjectBoundary)} Mock: projectUid {projectUid} projectBoundary {JsonConvert.SerializeObject(projectBoundary)}");
     return(Task.CompletedTask);
 }