Exemple #1
0
        public async Task GetBoundaryExecutor()
        {
            string custUid     = Guid.NewGuid().ToString();
            string userUid     = Guid.NewGuid().ToString();
            string projectUid  = Guid.NewGuid().ToString();
            string boundaryUid = Guid.NewGuid().ToString();
            string name        = "blah";
            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,
                GeofenceUID     = boundaryUid,
                Name            = name,
                GeometryWKT     = geometryWKT,
                GeofenceType    = GeofenceType.Filter,
                LastActionedUTC = DateTime.UtcNow
            };

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

            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
            });

            var geofenceToTest = new GeofenceDataSingleResult(AutoMapperUtility.Automapper.Map <GeofenceData>(geofence));

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

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

            Assert.NotNull(result);
            Assert.Equal(geofenceToTest.GeofenceData.GeofenceUID, result.GeofenceData.GeofenceUID);
            Assert.Equal(geofenceToTest.GeofenceData.GeofenceName, result.GeofenceData.GeofenceName);
            Assert.Equal(geofenceToTest.GeofenceData.GeometryWKT, result.GeofenceData.GeometryWKT);
        }
Exemple #2
0
        public async Task Should_return_expected_boundary_When_object_exists_in_database()
        {
            var custUid     = Guid.NewGuid();
            var userId      = Guid.NewGuid();
            var projectUid  = Guid.NewGuid();
            var boundaryUid = Guid.NewGuid();
            var name        = "name";

            WriteEventToDb(new CreateGeofenceEvent
            {
                GeofenceUID  = boundaryUid,
                GeofenceType = GeofenceType.Filter.ToString(),
                CustomerUID  = custUid,
                UserUID      = userId,
                ActionUTC    = DateTime.UtcNow,
                GeometryWKT  = boundaryPolygon,
                GeofenceName = name,
                Description  = null
            });
            WriteEventToDb(new AssociateProjectGeofence
            {
                ProjectUID  = projectUid,
                GeofenceUID = boundaryUid,
                ActionUTC   = DateTime.UtcNow
            });

            var request = CreateAndValidateRequest(custUid, projectUid, userId, boundaryUid);

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

            var filterToTest = new GeofenceDataSingleResult(
                new GeofenceData
            {
                GeofenceUID   = boundaryUid,
                Description   = null,
                GeofenceName  = name,
                UserUID       = userId,
                GeometryWKT   = boundaryPolygon,
                GeofenceType  = GeofenceType.Filter.ToString(),
                CustomerUID   = custUid,
                FillColor     = 0,
                IsTransparent = false
            });

            Assert.IsNotNull(result, Responses.ShouldReturnResult);
            Assert.AreEqual(filterToTest.GeofenceData.GeofenceUID, result.GeofenceData.GeofenceUID);
            Assert.AreEqual(filterToTest.GeofenceData.Description, result.GeofenceData.Description);
            Assert.AreEqual(filterToTest.GeofenceData.GeofenceName, result.GeofenceData.GeofenceName);
            Assert.AreEqual(filterToTest.GeofenceData.UserUID, result.GeofenceData.UserUID);
            Assert.AreEqual(filterToTest.GeofenceData.GeometryWKT, result.GeofenceData.GeometryWKT);
            Assert.AreEqual(filterToTest.GeofenceData.GeofenceType, result.GeofenceData.GeofenceType);
            Assert.AreEqual(filterToTest.GeofenceData.CustomerUID, result.GeofenceData.CustomerUID);
            Assert.AreEqual(filterToTest.GeofenceData.FillColor, result.GeofenceData.FillColor);
            Assert.AreEqual(filterToTest.GeofenceData.IsTransparent, result.GeofenceData.IsTransparent);
        }
Exemple #3
0
        public async Task Should_return_all_boundaries_for_a_given_Project_when_Project_exists()
        {
            var custUid     = Guid.NewGuid();
            var userId      = Guid.NewGuid();
            var projectUid  = Guid.NewGuid();
            var boundaryUid = Guid.NewGuid();
            var name        = "name";

            WriteEventToDb(new CreateGeofenceEvent
            {
                GeofenceUID  = boundaryUid,
                GeofenceType = GeofenceType.Filter.ToString(),
                CustomerUID  = custUid,
                UserUID      = userId,
                ActionUTC    = DateTime.UtcNow,
                GeometryWKT  = boundaryPolygon,
                GeofenceName = name,
                Description  = null,
            });
            WriteEventToDb(new AssociateProjectGeofence
            {
                ProjectUID  = projectUid,
                GeofenceUID = boundaryUid,
                ActionUTC   = DateTime.UtcNow
            });

            var request = CreateAndValidateRequest(custUid, projectUid, userId, goldenDimensionsPolygon);

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

            var boundaryToTest = new GeofenceDataSingleResult(
                new GeofenceData
            {
                GeofenceUID   = boundaryUid,
                GeofenceName  = name,
                UserUID       = userId,
                GeometryWKT   = boundaryPolygon,
                GeofenceType  = GeofenceType.Filter.ToString(),
                CustomerUID   = custUid,
                FillColor     = 0,
                IsTransparent = false,
                Description   = null
            });

            Assert.IsNotNull(result, Responses.ShouldReturnResult);
            var boundaries = result.GeofenceData.Where(b => b.GeofenceType == GeofenceType.Filter.ToString()).ToList();

            Assert.AreEqual(1, boundaries.Count);
            Assert.AreEqual(boundaryToTest.GeofenceData.GeofenceUID, boundaries[0].GeofenceUID);
            Assert.AreEqual(boundaryToTest.GeofenceData.GeofenceName, boundaries[0].GeofenceName);
            Assert.AreEqual(boundaryToTest.GeofenceData.UserUID, boundaries[0].UserUID);
            Assert.AreEqual(boundaryToTest.GeofenceData.GeometryWKT, boundaries[0].GeometryWKT);
            Assert.AreEqual(boundaryToTest.GeofenceData.GeofenceType, boundaries[0].GeofenceType);
            Assert.AreEqual(boundaryToTest.GeofenceData.CustomerUID, boundaries[0].CustomerUID);
            Assert.AreEqual(boundaryToTest.GeofenceData.FillColor, boundaries[0].FillColor);
            Assert.AreEqual(boundaryToTest.GeofenceData.IsTransparent, boundaries[0].IsTransparent);
            Assert.AreEqual(boundaryToTest.GeofenceData.Description, boundaries[0].Description);
        }