public void DeleteGeofence_HappyPath() { DateTime firstCreatedUtc = new DateTime(2017, 1, 1, 2, 30, 3); var geofenceUid = Guid.NewGuid(); var userUid = Guid.NewGuid(); var geofenceType = GeofenceType.Filter; var createGeofenceEvent = new CreateGeofenceEvent { CustomerUID = Guid.NewGuid(), UserUID = userUid, GeofenceUID = geofenceUid, GeofenceName = "Boundary one", GeofenceType = geofenceType.ToString(), GeometryWKT = "POLYGON((80.257874 12.677856,79.856873 13.039345,80.375977 13.443052,80.257874 12.677856))", ActionUTC = firstCreatedUtc }; var deleteGeofenceEvent = new DeleteGeofenceEvent { GeofenceUID = geofenceUid, UserUID = userUid, ActionUTC = firstCreatedUtc }; this.GeofenceRepo.StoreEvent(createGeofenceEvent).Wait(); WriteEventToDb(deleteGeofenceEvent, "Geofence event not deleted"); var g = this.GeofenceRepo.GetGeofence(geofenceUid.ToString()); g.Wait(); Assert.IsNull(g.Result, "Should not be able to retrieve geofence from geofenceRepo"); }
public void GetGeofences_HappyPath() { var custUid = Guid.NewGuid(); var userId = Guid.NewGuid(); DateTime firstCreatedUtc = new DateTime(2017, 1, 1, 2, 30, 3); var geofenceType = GeofenceType.Filter.ToString(); var createGeofenceEvent1 = new CreateGeofenceEvent { CustomerUID = custUid, UserUID = userId, GeofenceUID = Guid.NewGuid(), GeofenceName = "Boundary one", GeofenceType = geofenceType, GeometryWKT = "POLYGON((80.257874 12.677856,79.856873 13.039345,80.375977 13.443052,80.257874 12.677856))", ActionUTC = firstCreatedUtc }; var createGeofenceEvent2 = new CreateGeofenceEvent { CustomerUID = custUid, UserUID = userId, GeofenceUID = Guid.NewGuid(), GeofenceName = "Boundary two", GeofenceType = geofenceType, GeometryWKT = "POLYGON((81.257874 13.677856,80.856873 14.039345,81.375977 14.443052,81.257874 13.677856))", ActionUTC = firstCreatedUtc }; var createGeofenceEvent3 = new CreateGeofenceEvent { CustomerUID = custUid, UserUID = userId, GeofenceUID = Guid.NewGuid(), GeofenceName = "Boundary three", GeofenceType = geofenceType, GeometryWKT = "POLYGON((82.257874 14.677856,81.856873 15.039345,82.375977 15.443052,82.257874 14.677856))", ActionUTC = firstCreatedUtc }; var deleteGeofenceEvent = new DeleteGeofenceEvent { GeofenceUID = createGeofenceEvent1.GeofenceUID, UserUID = userId, ActionUTC = firstCreatedUtc }; this.GeofenceRepo.StoreEvent(createGeofenceEvent1).Wait(); this.GeofenceRepo.StoreEvent(createGeofenceEvent2).Wait(); this.GeofenceRepo.StoreEvent(createGeofenceEvent3).Wait(); this.GeofenceRepo.StoreEvent(deleteGeofenceEvent).Wait(); var ids = new List <string> { createGeofenceEvent1.GeofenceUID.ToString(), createGeofenceEvent2.GeofenceUID.ToString(), createGeofenceEvent3.GeofenceUID.ToString() }; var g = this.GeofenceRepo.GetGeofences(ids); g.Wait(); Assert.IsNotNull(g.Result, "Unable to retrieve geofences from geofenceRepo"); Assert.AreEqual(2, g.Result.Count(), "Wrong number of geofences retrieved"); }
/// <summary> /// Processes the Filter Boundary Request asynchronously. /// </summary> /// <param name="item"></param> /// <returns>Returns an <see cref="BoundaryRequest"/> object if successful.</returns> protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item) { var request = CastRequestObjectTo <BoundaryUidRequestFull>(item, 53); if (request == null) { return(null); } IEnumerable <ProjectGeofence> associations = null; try { //Check it belongs to the project associations = await(auxRepository as IProjectRepository).GetAssociatedGeofences(request.ProjectUid) .ConfigureAwait(false); } catch (Exception e) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 48, e.Message); } if (!associations.Any(a => string.Equals(request.BoundaryUid, a.GeofenceUID.ToString(), StringComparison.OrdinalIgnoreCase))) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 49); } Geofence boundary = null; try { boundary = await((IGeofenceRepository)Repository).GetGeofence(request.BoundaryUid).ConfigureAwait(false); } catch (Exception e) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 48, e.Message); } if (boundary == null || !string.Equals(boundary.GeofenceUID, request.BoundaryUid, StringComparison.OrdinalIgnoreCase)) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 49); } log.LogDebug($"DeleteBoundary retrieved Geofence {JsonConvert.SerializeObject(boundary)}"); DeleteGeofenceEvent deleteEvent = null; int deletedCount = 0; try { deleteEvent = AutoMapperUtility.Automapper.Map <DeleteGeofenceEvent>(request); deleteEvent.ActionUTC = DateTime.UtcNow; deletedCount = await((IGeofenceRepository)Repository).StoreEvent(deleteEvent).ConfigureAwait(false); } catch (Exception e) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 13, e.Message); } if (deletedCount == 0) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 12); } //NOTE: A gap at the moment is that we don't support deleting an association between project and boundary (geofence). //That should be done here as part of boundary deletion. return(new ContractExecutionResult()); }