private void ImportRouteSegments(Wgs84GraphBuilder graphBuilder) { // Import node objects to database var segmentJsonText = File.ReadAllText(_routeSegmentFilename); var segmentsJson = JsonConvert.DeserializeObject(segmentJsonText) as JObject; var features = segmentsJson["features"]; bool firstSegment = true; bool lastSegment = false; var numberOfSegmentFeatures = features.Count(); var segmentCounter = 1; foreach (var feature in features) { var properties = feature["properties"] as JObject; var geometry = feature["geometry"]; var geometryType = geometry["type"].ToString(); var geometryCoordinates = geometry["coordinates"].ToString().Replace("\r\n", "").Replace(" ", ""); var segmentId = Guid.Parse(_segmentIdPrefix + properties["Id"].ToString().PadLeft(6, '0')); var segmentKind = properties["RouteSegmentKind"].ToString(); var assetStatus = properties["Status"].ToString(); if (properties["BuildTestData"].ToString() != "") { var buildCodes = properties["BuildTestData"].ToString().Split(';'); _segmentBuildCodes.Add(segmentId, buildCodes); } // Add link to graph var coordinates = geometry["coordinates"] as JArray; var startX = coordinates.First[0]; var startY = coordinates.First[1]; var endX = coordinates.Last[0]; var endY = coordinates.Last[1]; // Derive node and function kind RouteSegmentKindEnum?segmentKindCode = null; if (segmentKind == "buried") { segmentKindCode = RouteSegmentKindEnum.Underground; } // On the first node, we set the start marker into applicaion info, and insert data into all the other propeties as well to test if every information is captured into the generated events if (firstSegment) { RouteSegmentRecord routeSegment = new RouteSegmentRecord() { Id = segmentId, ApplicationName = _applicationName, ApplicationInfo = _applicationName, DeleteMe = false, MarkAsDeleted = false, Username = _userName, Geometry = GeographicToProjectedCoordinateConverter.ConvertLineString(GeoJsonConversionHelper.ConvertFromLineGeoJson(geometryCoordinates)), RouteSegmentInfo = new RouteSegmentInfo(RouteSegmentKindEnum.Underground, "50 cm", "90 cm"), LifecycleInfo = new LifecycleInfo(DeploymentStateEnum.InService, DateTime.Now, DateTime.Now), MappingInfo = new MappingInfo(MappingMethodEnum.LandSurveying, "10 cm", "20 cm", DateTime.Now, "Surveyed with GPS"), NamingInfo = new NamingInfo("Route segment", "I'm an underground route segment"), SafetyInfo = new SafetyInfo("no danger", "might contain gophers"), }; graphBuilder.AddEdgeToGraph(routeSegment, (double)startX, (double)startY, (double)endX, (double)endY); _routeNetworkDatestore.InsertRouteSegment(routeSegment); } else { RouteSegmentRecord routeSegment = new RouteSegmentRecord() { Id = segmentId, ApplicationName = _applicationName, ApplicationInfo = _applicationName, DeleteMe = false, MarkAsDeleted = false, Username = _userName, Geometry = GeographicToProjectedCoordinateConverter.ConvertLineString(GeoJsonConversionHelper.ConvertFromLineGeoJson(geometryCoordinates)), RouteSegmentInfo = new RouteSegmentInfo(RouteSegmentKindEnum.Underground, "50 cm", "90 cm"), }; // Mark last segment if (segmentCounter == numberOfSegmentFeatures) { routeSegment.WorkTaskMrid = _endMarker; } graphBuilder.AddEdgeToGraph(routeSegment, (double)startX, (double)startY, (double)endX, (double)endY); _routeNetworkDatestore.InsertRouteSegment(routeSegment); } firstSegment = false; segmentCounter++; } }
/// <summary> /// Returns true if test went well (no errors) /// </summary> /// <returns></returns> public bool Run() { Log.Information($"Scenario 1 test begun."); DateTime startTime = DateTime.UtcNow; Guid startMarker = Guid.NewGuid(); bool allTestsWentOk = true; RouteSegmentRecord routeSegment = new RouteSegmentRecord() { Id = Guid.NewGuid(), WorkTaskMrid = startMarker, ApplicationName = "ScenarioTester", ApplicationInfo = "Scenario 1 happy case", DeleteMe = false, MarkAsDeleted = false, Username = "******", Geometry = GeoJsonConversionHelper.ConvertFromLineGeoJson("[[539632.709067166,6177928.15],[539718.634229065,6177984.82],[539816.442658036,6178004.93]]"), RouteSegmentInfo = new RouteSegmentInfo(RouteSegmentKindEnum.Underground, "50 cm", "90 cm"), LifecycleInfo = new LifecycleInfo(DeploymentStateEnum.InService, DateTime.Now, DateTime.Now), MappingInfo = new MappingInfo(MappingMethodEnum.LandSurveying, "10 cm", "20 cm", DateTime.Now, "Surveyed with GPS"), NamingInfo = new NamingInfo("Route segment", "I'm an underground route segment"), SafetyInfo = new SafetyInfo("No real danger, unless you're afraid of gophers", "Might contain gophers"), }; _routeNetworkDatastore.InsertRouteSegment(routeSegment); var events = WaitForEvents(startMarker); if (events.Count != 3) { Log.Error($"Expected 3 events, but got {events.Count}"); return(Fail()); } // Snatch cmdId from the first event Guid cmdId = events.First().CmdId; if (allTestsWentOk) { // Event 1 must be route node added if (events[0] is RouteNodeAdded) { var routeNodeAdded = events[0] as RouteNodeAdded; // General route network event property checks allTestsWentOk = CheckApplicationName(routeNodeAdded, "GDB_INTEGRATOR") ? allTestsWentOk : false; allTestsWentOk = CheckCmdType(routeNodeAdded, "NewRouteSegmentDigitized") ? allTestsWentOk : false; allTestsWentOk = CheckEventId(routeNodeAdded) ? allTestsWentOk : false; allTestsWentOk = CheckEventType(routeNodeAdded, "RouteNodeAdded") ? allTestsWentOk : false; allTestsWentOk = CheckEventTimestamp(routeNodeAdded, startTime) ? allTestsWentOk : false; allTestsWentOk = CheckThatIsLastEventInCmdIsFalse(routeNodeAdded) ? allTestsWentOk : false; allTestsWentOk = CheckThatWorkTaskMridIsTransferedToEvent(routeNodeAdded, routeSegment.WorkTaskMrid) ? allTestsWentOk : false; allTestsWentOk = CheckThatUserNameIsTransferedToEvent(routeNodeAdded, routeSegment.Username) ? allTestsWentOk : false; // Route node added specific tests allTestsWentOk = CheckNodeId(routeNodeAdded) ? allTestsWentOk : false; } else { return(Fail($"Expected that the first event was a route node added event, but got a: {events[0].GetType().Name}")); } } if (allTestsWentOk) { Log.Information($"Scenario 1 test ended with success."); } else { return(Fail()); } return(allTestsWentOk); }
private bool CheckSegmentAddedEventProperties(RouteSegmentAdded routeSegmentAddedEvent, RouteSegmentRecord sourceSegment) { var allTestsOk = true; if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.Id, routeSegmentAddedEvent.SegmentId, "SegmentId")) { allTestsOk = false; } // Check route segment info if (!TestPropertyValueNoEquals(routeSegmentAddedEvent, sourceSegment.RouteSegmentInfo, routeSegmentAddedEvent.RouteSegmentInfo, "RouteSegmentInfo")) { allTestsOk = false; } else if (routeSegmentAddedEvent.RouteSegmentInfo != null) { if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.RouteSegmentInfo.Kind, routeSegmentAddedEvent.RouteSegmentInfo.Kind, "RouteSegmentInfo.Kind")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.RouteSegmentInfo.Width, routeSegmentAddedEvent.RouteSegmentInfo.Width, "RouteSegmentInfo.Width")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.RouteSegmentInfo.Height, routeSegmentAddedEvent.RouteSegmentInfo.Height, "RouteSegmentInfo.Height")) { allTestsOk = false; } } // Check from node id if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.StartNode.Id, routeSegmentAddedEvent.FromNodeId, "FromNodeId")) { allTestsOk = false; } // Check to node id if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.EndNode.Id, routeSegmentAddedEvent.ToNodeId, "ToNodeId")) { allTestsOk = false; } // general // Check event type if (!TestPropertyValue(routeSegmentAddedEvent, "RouteSegmentAdded", routeSegmentAddedEvent.EventType, "EventType")) { allTestsOk = false; } // Check command type if (!TestPropertyValue(routeSegmentAddedEvent, "NewRouteSegmentDigitized", routeSegmentAddedEvent.CmdType, "CmdType")) { allTestsOk = false; } // Check IsLastEventInCmd if (!TestPropertyValue(routeSegmentAddedEvent, true, routeSegmentAddedEvent.IsLastEventInCmd, "IsLastEventInCmd")) { allTestsOk = false; } // Check event id uniqueness if (!TestIfIdNotAlreadyUsed(routeSegmentAddedEvent, routeSegmentAddedEvent.EventId, _ids, "EventId")) { allTestsOk = false; } // Check cmd id uniqueness if (!TestIfIdNotAlreadyUsed(routeSegmentAddedEvent, routeSegmentAddedEvent.CmdId, _ids, "CmdId")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.ApplicationName, routeSegmentAddedEvent.ApplicationName, "ApplicationName")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.ApplicationInfo, routeSegmentAddedEvent.ApplicationInfo, "ApplicationInfo")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.Username, routeSegmentAddedEvent.UserName, "UserName")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.WorkTaskMrid, routeSegmentAddedEvent.WorkTaskMrid, "WorkTaskMrid")) { allTestsOk = false; } // Check naming info if (!TestPropertyValueNoEquals(routeSegmentAddedEvent, sourceSegment.NamingInfo, routeSegmentAddedEvent.NamingInfo, "NamingInfo")) { allTestsOk = false; } else if (routeSegmentAddedEvent.NamingInfo != null) { if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.NamingInfo.Name, routeSegmentAddedEvent.NamingInfo.Name, "NamingInfo.Name")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.NamingInfo.Description, routeSegmentAddedEvent.NamingInfo.Description, "NamingInfo.Description")) { allTestsOk = false; } } // Check mapping info if (!TestPropertyValueNoEquals(routeSegmentAddedEvent, sourceSegment.MappingInfo, routeSegmentAddedEvent.MappingInfo, "MappingInfo")) { allTestsOk = false; } else if (routeSegmentAddedEvent.MappingInfo != null) { if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.MappingInfo.Method, routeSegmentAddedEvent.MappingInfo.Method, "MappingInfo.Method")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.MappingInfo.HorizontalAccuracy, routeSegmentAddedEvent.MappingInfo.HorizontalAccuracy, "MappingInfo.HorizontalAccuracy")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.MappingInfo.VerticalAccuracy, routeSegmentAddedEvent.MappingInfo.VerticalAccuracy, "MappingInfo.VerticalAccuracy")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.MappingInfo.SurveyDate, routeSegmentAddedEvent.MappingInfo.SurveyDate, "MappingInfo.SurveyDate")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.MappingInfo.SourceInfo, routeSegmentAddedEvent.MappingInfo.SourceInfo, "MappingInfo.SourceInfo")) { allTestsOk = false; } } // Check lifecycle info if (!TestPropertyValueNoEquals(routeSegmentAddedEvent, sourceSegment.LifecycleInfo, routeSegmentAddedEvent.LifecyleInfo, "LifecycleInfo")) { allTestsOk = false; } else if (routeSegmentAddedEvent.LifecyleInfo != null) { if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.LifecycleInfo.DeploymentState, routeSegmentAddedEvent.LifecyleInfo.DeploymentState, "LifecycleInfo.DeploymentState")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.LifecycleInfo.InstallationDate, routeSegmentAddedEvent.LifecyleInfo.InstallationDate, "LifecycleInfo.InstallationDate")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.LifecycleInfo.RemovalDate, routeSegmentAddedEvent.LifecyleInfo.RemovalDate, "LifecycleInfo.RemovalDate")) { allTestsOk = false; } } // Check safety info if (!TestPropertyValueNoEquals(routeSegmentAddedEvent, sourceSegment.SafetyInfo, routeSegmentAddedEvent.SafetyInfo, "SafetyInfo")) { allTestsOk = false; } else if (routeSegmentAddedEvent.SafetyInfo != null) { if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.SafetyInfo.Classification, routeSegmentAddedEvent.SafetyInfo.Classification, "SafetyInfo.Classification")) { allTestsOk = false; } if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.SafetyInfo.Remark, routeSegmentAddedEvent.SafetyInfo.Remark, "SafetyInfo.Remark")) { allTestsOk = false; } } return(allTestsOk); }