/// <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);
        }
Esempio n. 2
0
        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++;
            }
        }