Esempio n. 1
0
        public async Task <GeofenceDataListResult> GetProjectBoundaries(
            string projectUid

            /*,    [FromServices] IGeofenceProxy geofenceProxy,
             * [FromServices] IUnifiedProductivityProxy unifiedProductivityProxy*/
            )
        {
            Log.LogInformation(
                $"{ToString()}.GetProjectBoundaries: CustomerUID={CustomerUid} IsApplication={IsApplication} UserUid={GetUserId} ProjectUid: {projectUid}");

            var requestFull = BaseRequestFull.Create(
                CustomerUid,
                IsApplication,
                await GetProject(projectUid),
                GetUserId,
                Request.Headers.GetCustomHeaders());

            requestFull.Validate(ServiceExceptionHandler);

            var executor = RequestExecutorContainer.Build <GetBoundariesExecutor>(ConfigStore, Logger, ServiceExceptionHandler,
                                                                                  _geofenceRepository, _projectRepository, ProjectProxy
                                                                                  /* ,  geofenceProxy: geofenceProxy, unifiedProductivityProxy: unifiedProductivityProxy */);

            var result = await executor.ProcessAsync(requestFull);

            Log.LogInformation(
                $"{ToString()}.GetProjectBoundaries Completed: resultCode: {result?.Code} result: {JsonConvert.SerializeObject(result)}");
            return(result as GeofenceDataListResult);
        }
Esempio n. 2
0
        private BaseRequestFull CreateAndValidateRequest(Guid custUid, Guid projectUid, Guid userId, string projectGeometryWKT)
        {
            var request = BaseRequestFull.Create(
                custUid.ToString(),
                false,
                new ProjectData()
            {
                ProjectUID = projectUid.ToString(), ProjectGeofenceWKT = projectGeometryWKT
            },
                userId.ToString(), null);

            request.Validate(ServiceExceptionHandler);
            return(request);
        }
Esempio n. 3
0
        public async Task GetBoundariesExecutor_WithException()
        {
            string custUid             = Guid.NewGuid().ToString();
            string userUid             = Guid.NewGuid().ToString();
            string projectUid          = Guid.NewGuid().ToString();
            string boundaryUid         = Guid.NewGuid().ToString();
            string boundaryName        = "blah";
            string boundaryGeometryWKT = "whatever";

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

            var geofenceRepo     = new Mock <GeofenceRepository>(configStore, logger);
            var geofenceBoundary = new Geofence
            {
                CustomerUID     = custUid,
                UserUID         = userUid,
                GeofenceUID     = boundaryUid,
                Name            = boundaryName,
                GeometryWKT     = boundaryGeometryWKT,
                GeofenceType    = GeofenceType.Filter,
                LastActionedUTC = DateTime.UtcNow
            };

            geofenceRepo.As <IGeofenceRepository>().Setup(g => g.GetGeofences(It.IsAny <IEnumerable <string> >())).ReturnsAsync(new List <Geofence> {
                geofenceBoundary
            });

            //var geofenceProxy = new Mock<IGeofenceProxy>();
            //geofenceProxy.Setup(g => g.GetFavoriteGeofences(custUid, userUid, null)).ReturnsAsync(new List<GeofenceData>());

            //var upProxy = new Mock<IUnifiedProductivityProxy>();
            //upProxy.Setup(u => u.GetAssociatedGeofences(projectUid, null)).Throws(new Exception("No UserCustomerAssociation exists."));

            var projectRepo     = new Mock <ProjectRepository>(configStore, logger);
            var projectGeofence = new ProjectGeofence {
                GeofenceUID = boundaryUid, ProjectUID = projectUid
            };

            projectRepo.As <IProjectRepository>().Setup(p => p.GetAssociatedGeofences(It.IsAny <string>())).ReturnsAsync(new List <ProjectGeofence> {
                projectGeofence
            });
            //projectRepo.As<IProjectRepository>().Setup(p => p.DoPolygonsOverlap(It.IsAny<string>(), It.IsAny<IEnumerable<string>>())).ReturnsAsync(new List<bool> { true, false });

            var geofenceToTest = AutoMapperUtility.Automapper.Map <GeofenceData>(geofenceBoundary);

            var request = BaseRequestFull.Create
                          (
                custUid,
                false,
                new ProjectData {
                ProjectUID = projectUid
            },
                userUid,
                null
                          );

            var executor =
                RequestExecutorContainer.Build <GetBoundariesExecutor>(configStore, logger, serviceExceptionHandler,
                                                                       geofenceRepo.Object, projectRepo.Object
                                                                       /* , geofenceProxy: geofenceProxy.Object, unifiedProductivityProxy: upProxy.Object */);
            var result = await executor.ProcessAsync(request) as GeofenceDataListResult;

            Assert.NotNull(result);
            Assert.Single(result.GeofenceData);
            var actualBoundary = result.GeofenceData.SingleOrDefault(g => g.GeofenceUID == geofenceToTest.GeofenceUID);

            Assert.Equal(geofenceToTest.GeofenceUID, actualBoundary.GeofenceUID);
            Assert.Equal(geofenceToTest.GeofenceName, actualBoundary.GeofenceName);
            Assert.Equal(geofenceToTest.GeometryWKT, actualBoundary.GeometryWKT);
            Assert.Equal(geofenceToTest.GeofenceType, actualBoundary.GeofenceType);
        }