コード例 #1
0
        public async void CreateValidWalkOfWithNonAjacentSegments_ShouldReturnSuccess()
        {
            // Route network subset used in this test:
            // S5-S6-S9-S11
            var interestId = Guid.NewGuid();

            var walk = new RouteNetworkElementIdList()
            {
                TestRouteNetwork.S9, TestRouteNetwork.S11, TestRouteNetwork.S6, TestRouteNetwork.S5
            };

            // Act
            var    registerWalkOfInterestCommand       = new RegisterWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId, walk);
            Result registerWalkOfInterestCommandResult = await _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> >(registerWalkOfInterestCommand);

            var routeNetworkQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.J_2
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects
            };

            Result <GetRouteNetworkDetailsResult> routeNetworkQueryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery);

            // Assert
            registerWalkOfInterestCommandResult.IsSuccess.Should().BeTrue();
            routeNetworkQueryResult.IsSuccess.Should().BeTrue();

            routeNetworkQueryResult.Value.Interests[interestId].RouteNetworkElementRefs.Count.Should().Be(9);
            //routeNetworkQueryResult.Value.Interests[interestId].RouteNetworkElementRefs.Should().Contain(TestRouteNetwork.CO_1);
        }
コード例 #2
0
        public async void QueryRouteElement_ThatExists_ShouldReturnSuccessAndAllRouteElementProperties()
        {
            // Setup
            var routeNodeQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CO_1
            });

            // Act
            var routeNodeQueryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNodeQuery);

            // Assert
            Assert.True(routeNodeQueryResult.IsSuccess);
            Assert.Single(routeNodeQueryResult.Value.RouteNetworkElements);

            var theRouteNodeObjectReturned = routeNodeQueryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1];

            Assert.Equal(TestRouteNetwork.CO_1, theRouteNodeObjectReturned.Id);
            Assert.Equal(RouteNetworkElementKindEnum.RouteNode, theRouteNodeObjectReturned.Kind);

            Assert.NotNull(theRouteNodeObjectReturned.Coordinates);
            Assert.NotNull(theRouteNodeObjectReturned.RouteNodeInfo);
            Assert.NotNull(theRouteNodeObjectReturned.NamingInfo);
            Assert.NotNull(theRouteNodeObjectReturned.MappingInfo);
            Assert.NotNull(theRouteNodeObjectReturned.LifecycleInfo);
            Assert.NotNull(theRouteNodeObjectReturned.SafetyInfo);
        }
コード例 #3
0
        public async Task QueryEquipmentDetailsOfCC_1()
        {
            var routeNetworkQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CC_1
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementOnly
            };

            // Act
            Result <GetRouteNetworkDetailsResult> routeNetworkQueryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery);

            var interestIds = new InterestIdList();

            interestIds.AddRange(routeNetworkQueryResult.Value.RouteNetworkElements[TestRouteNetwork.CC_1].InterestRelations.Select(r => r.RefId));

            var equipmentQueryResult = await _queryDispatcher.HandleAsync <GetEquipmentDetails, Result <GetEquipmentDetailsResult> >(
                new GetEquipmentDetails(interestIds)
                );

            // Assert
            equipmentQueryResult.IsSuccess.Should().BeTrue();
            equipmentQueryResult.Value.SpanEquipment.Count.Should().Be(3);
        }
        private Task <Result <GetRouteNetworkDetailsResult> > QueryByRouteElementIds(GetRouteNetworkDetails query)
        {
            var getRouteNetworkElementsResult = _routeNodeRepository.GetRouteElements(query.RouteNetworkElementIdsToQuery);

            // Here we return a error result, because we're dealing with invalid route network ids provided by the client
            if (getRouteNetworkElementsResult.IsFailed)
            {
                return(Task.FromResult(
                           Result.Fail <GetRouteNetworkDetailsResult>(new GetRouteNetworkDetailsError(GetRouteNetworkDetailsErrorCodes.INVALID_QUERY_ARGUMENT_ERROR_LOOKING_UP_SPECIFIED_ROUTE_NETWORK_ELEMENT_BY_ID, $"Error looking up route network elements: " + JsonConvert.SerializeObject(query))).
                           WithError(getRouteNetworkElementsResult.Errors.First())
                           ));
            }

            var routeNetworkElementsToReturn = MapRouteElementDomainObjectsToQueryObjects(query.RouteNetworkElementFilter, getRouteNetworkElementsResult.Value);

            var interestsToReturn = Array.Empty <RouteNetworkInterest>();

            if (query.RelatedInterestFilter == RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects)
            {
                interestsToReturn = GetInterestsRelatedToRouteNetworkElements(query.RouteNetworkElementIdsToQuery);
            }

            var queryResult = new GetRouteNetworkDetailsResult(routeNetworkElementsToReturn, interestsToReturn);

            // Add interest information
            AddInterestReferencesToRouteNetworkElements(query, queryResult);

            return(Task.FromResult(
                       Result.Ok <GetRouteNetworkDetailsResult>(
                           queryResult
                           )
                       ));
        }
コード例 #5
0
        public async Task <IActionResult> HasRelatedEquipment(string id)
        {
            if (!Guid.TryParse(id, out Guid routeNodeId))
            {
                return(BadRequest($"{id} is not a valid guid"));
            }

            var routeNodeQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                routeNodeId
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementOnly
            };

            var queryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNodeQuery);

            if (queryResult.IsFailed)
            {
                return(BadRequest("Request failed"));
            }

            var routeNetworkElement = queryResult.Value.RouteNetworkElements[routeNodeId];

            var hasRelatedEquipment = (routeNetworkElement.InterestRelations != null && routeNetworkElement.InterestRelations.Length > 0);

            return(Ok(hasRelatedEquipment));
        }
コード例 #6
0
        public async void CreateValidNodeOfInterest_ShouldReturnSuccess()
        {
            var interestId  = Guid.NewGuid();
            var routeNodeId = TestRouteNetwork.CC_1;

            // Act
            var registerNodeOfInterestCommand       = new RegisterNodeOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId, routeNodeId);
            var registerNodeOfInterestCommandResult = await _commandDispatcher.HandleAsync <RegisterNodeOfInterest, Result <RouteNetworkInterest> >(registerNodeOfInterestCommand);

            var routeNetworkQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CC_1
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects
            };

            Result <GetRouteNetworkDetailsResult> routeNetworkQueryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery);

            // Assert command result
            registerNodeOfInterestCommandResult.IsSuccess.Should().BeTrue();
            registerNodeOfInterestCommandResult.Value.Kind.Should().Be(RouteNetworkInterestKindEnum.NodeOfInterest);
            registerNodeOfInterestCommandResult.Value.RouteNetworkElementRefs.Count.Should().Be(1);
            registerNodeOfInterestCommandResult.Value.RouteNetworkElementRefs.Should().Contain(TestRouteNetwork.CC_1);

            // Assert query result
            routeNetworkQueryResult.IsSuccess.Should().BeTrue();
            routeNetworkQueryResult.Value.Interests[interestId].RouteNetworkElementRefs.Count.Should().Be(1);
            routeNetworkQueryResult.Value.Interests[interestId].RouteNetworkElementRefs.Should().Contain(TestRouteNetwork.CC_1);
            routeNetworkQueryResult.Value.RouteNetworkElements[routeNodeId].InterestRelations.Should().Contain(i => i.RefId == interestId && i.RelationKind == RouteNetworkInterestRelationKindEnum.InsideNode);
        }
 public Task <Result <GetRouteNetworkDetailsResult> > HandleAsync(GetRouteNetworkDetails query)
 {
     // Get route elements
     if (query.RouteNetworkElementIdsToQuery.Count > 0 && query.InterestIdsToQuery.Count == 0)
     {
         return(QueryByRouteElementIds(query));
     }
     else if (query.InterestIdsToQuery.Count > 0 && query.RouteNetworkElementIdsToQuery.Count == 0)
     {
         return(QueryByInterestIds(query));
     }
     else
     {
         if (query.InterestIdsToQuery.Count > 0 && query.RouteNetworkElementIdsToQuery.Count > 0)
         {
             return(Task.FromResult(Result.Fail <GetRouteNetworkDetailsResult>(new GetRouteNetworkDetailsError(GetRouteNetworkDetailsErrorCodes.INVALID_QUERY_ARGUMENT_CANT_QUERY_BY_INTEREST_AND_ROUTE_NETWORK_ELEMENT_AT_THE_SAME_TIME, "Invalid query. Cannot query by route network element ids and interest ids at the same time."))));
         }
         else if (query.InterestIdsToQuery.Count == 0 && query.RouteNetworkElementIdsToQuery.Count == 0)
         {
             return(Task.FromResult(Result.Fail <GetRouteNetworkDetailsResult>(new GetRouteNetworkDetailsError(GetRouteNetworkDetailsErrorCodes.INVALID_QUERY_ARGUMENT_NO_INTEREST_OR_ROUTE_NETWORK_IDS_SPECIFIED, "Invalid query. Neither route network element ids or interest ids specified. Therefore nothing to query."))));
         }
         else
         {
             throw new ApplicationException("Unexpected combination of query arguments in GetRouteNetworkDetailsResult:\r\n" + JsonConvert.SerializeObject(query));
         }
     }
 }
        public async void QueryByInterestId_ShouldSucced()
        {
            // Create two overlapping walk of interests that we can try to query on
            var interest1Id = Guid.NewGuid();
            var walk1       = new RouteNetworkElementIdList()
            {
                TestRouteNetwork.S1
            };
            await _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> >(new RegisterWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interest1Id, walk1));

            var interest2Id = Guid.NewGuid();
            var walk2       = new RouteNetworkElementIdList()
            {
                TestRouteNetwork.S2
            };
            await _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> >(new RegisterWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interest2Id, walk2));


            // Act
            var routeNetworkQuery = new GetRouteNetworkDetails(new InterestIdList()
            {
                interest1Id, interest2Id
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects
            };

            Result <GetRouteNetworkDetailsResult> queryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery);

            // Assert
            queryResult.Value.Interests.ContainsKey(interest1Id).Should().BeTrue();
            queryResult.Value.Interests.ContainsKey(interest2Id).Should().BeTrue();

            queryResult.Value.RouteNetworkElements.ContainsKey(TestRouteNetwork.CO_1).Should().BeTrue();
            queryResult.Value.RouteNetworkElements.ContainsKey(TestRouteNetwork.S1).Should().BeTrue();
            queryResult.Value.RouteNetworkElements.ContainsKey(TestRouteNetwork.HH_1).Should().BeTrue();
            queryResult.Value.RouteNetworkElements.ContainsKey(TestRouteNetwork.S2).Should().BeTrue();
            queryResult.Value.RouteNetworkElements.ContainsKey(TestRouteNetwork.HH_2).Should().BeTrue();

            queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].InterestRelations.Should().Contain(i => i.RefId == interest1Id && i.RelationKind == RouteNetworkInterestRelationKindEnum.Start);
            queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].InterestRelations.Should().NotContain(i => i.RefId == interest2Id);

            queryResult.Value.RouteNetworkElements[TestRouteNetwork.S1].InterestRelations.Should().Contain(i => i.RefId == interest1Id && i.RelationKind == RouteNetworkInterestRelationKindEnum.PassThrough);
            queryResult.Value.RouteNetworkElements[TestRouteNetwork.S1].InterestRelations.Should().NotContain(i => i.RefId == interest2Id);

            queryResult.Value.RouteNetworkElements[TestRouteNetwork.HH_1].InterestRelations.Should().Contain(i => i.RefId == interest1Id && i.RelationKind == RouteNetworkInterestRelationKindEnum.End);
            queryResult.Value.RouteNetworkElements[TestRouteNetwork.HH_1].InterestRelations.Should().Contain(i => i.RefId == interest2Id && i.RelationKind == RouteNetworkInterestRelationKindEnum.Start);

            queryResult.Value.RouteNetworkElements[TestRouteNetwork.S2].InterestRelations.Should().Contain(i => i.RefId == interest2Id && i.RelationKind == RouteNetworkInterestRelationKindEnum.PassThrough);
            queryResult.Value.RouteNetworkElements[TestRouteNetwork.S2].InterestRelations.Should().NotContain(i => i.RefId == interest1Id);

            queryResult.Value.RouteNetworkElements[TestRouteNetwork.HH_2].InterestRelations.Should().Contain(i => i.RefId == interest2Id && i.RelationKind == RouteNetworkInterestRelationKindEnum.End);
            queryResult.Value.RouteNetworkElements[TestRouteNetwork.HH_2].InterestRelations.Should().NotContain(i => i.RefId == interest1Id);
        }
        private Task <Result <GetRouteNetworkDetailsResult> > QueryByInterestIds(GetRouteNetworkDetails query)
        {
            RouteNetworkElementIdList routeElementsToQuery = new RouteNetworkElementIdList();

            List <RouteNetworkInterest> interestsToReturn = new List <RouteNetworkInterest>();

            // Find all interest to return and create a list of route network elements at the same time
            var interestsProjection = _eventStore.Projections.Get <InterestsProjection>();

            foreach (var interestId in query.InterestIdsToQuery)
            {
                var interestQueryResult = interestsProjection.GetInterest(interestId);

                // Here we return a error result, because we're dealing with invalid interest ids provided by the client
                if (interestQueryResult.IsFailed)
                {
                    return(Task.FromResult(
                               Result.Fail <GetRouteNetworkDetailsResult>(new GetRouteNetworkDetailsError(GetRouteNetworkDetailsErrorCodes.INVALID_QUERY_ARGUMENT_ERROR_LOOKING_UP_SPECIFIED_INTEREST_BY_ID, $"Error looking up interest by id: {interestId}")).
                               WithError(interestQueryResult.Errors.First())
                               ));
                }

                interestsToReturn.Add(interestQueryResult.Value);

                routeElementsToQuery.AddRange(interestQueryResult.Value.RouteNetworkElementRefs);
            }

            // TODO: Fix so that we don't create substitudes when something is deleted
            var getRouteNetworkElementsResult = _routeNodeRepository.GetRouteElements(routeElementsToQuery, true);

            // Here we create an exception, because this situation should not be allowed by the system
            if (getRouteNetworkElementsResult.IsFailed)
            {
                throw new ApplicationException($"Unexpected error querying route elements referenced by interests. All the interest exists and therefore the route network elements must also exists. Validation that route elements having interest cannot be deleted seems not to be working! Initial query:\r\n" + JsonConvert.SerializeObject(query));
            }

            var mappedRouteNetworkElements = MapRouteElementDomainObjectsToQueryObjects(query.RouteNetworkElementFilter, getRouteNetworkElementsResult.Value);

            var queryResult = new GetRouteNetworkDetailsResult(mappedRouteNetworkElements, interestsToReturn.ToArray());

            // Add interest reference information
            AddInterestReferencesToRouteNetworkElements(query, queryResult);

            return(Task.FromResult(
                       Result.Ok <GetRouteNetworkDetailsResult>(
                           queryResult
                           )
                       ));
        }
        public async void QueryReferencesFromRouteElementAndInterestObjects_ShouldReturnAllInterestInformation()
        {
            // Create interest (CO_1) <- (S1) -> (HH_1) that we can then try query
            var interestId = Guid.NewGuid();

            var walk = new RouteNetworkElementIdList()
            {
                TestRouteNetwork.S1
            };
            var createInterestCommand = new RegisterWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId, walk);

            await _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> >(createInterestCommand);

            // Act: Query CO_1, S1, HH_1 and HH_2
            var routeNetworkQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CO_1, TestRouteNetwork.S1, TestRouteNetwork.HH_1, TestRouteNetwork.HH_2
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects
            };

            Result <GetRouteNetworkDetailsResult> queryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery);

            // Assert that we got information back on all 4 network elements queried
            Assert.True(queryResult.IsSuccess);
            Assert.Equal(4, queryResult.Value.RouteNetworkElements.Count);

            // Assert that we got back one interest related to the 3 network elements that the walk of interest covers
            Assert.NotNull(queryResult.Value.Interests);
            Assert.Contains(queryResult.Value.Interests, i => i.Id == interestId);
            Assert.Equal(RouteNetworkInterestKindEnum.WalkOfInterest, queryResult.Value.Interests[interestId].Kind);
            Assert.Equal(3, queryResult.Value.Interests[interestId].RouteNetworkElementRefs.Count);
            Assert.Contains(TestRouteNetwork.CO_1, queryResult.Value.Interests[interestId].RouteNetworkElementRefs);
            Assert.Contains(TestRouteNetwork.S1, queryResult.Value.Interests[interestId].RouteNetworkElementRefs);
            Assert.Contains(TestRouteNetwork.HH_1, queryResult.Value.Interests[interestId].RouteNetworkElementRefs);

            // Assert that route element 1 (CO_1) has interest information with correct relation type
            Assert.NotNull(queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].InterestRelations);
            Assert.Contains(queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].InterestRelations, r => r.RefId == interestId && r.RelationKind == RouteNetworkInterestRelationKindEnum.Start);

            // Assert that route element 2 (S1) has interest information with correct relation type
            Assert.NotNull(queryResult.Value.RouteNetworkElements[TestRouteNetwork.S1].InterestRelations);
            Assert.Contains(queryResult.Value.RouteNetworkElements[TestRouteNetwork.S1].InterestRelations, r => r.RefId == interestId && r.RelationKind == RouteNetworkInterestRelationKindEnum.PassThrough);

            // Assert that route element 3 (HH_1) has interest information with correct relation type
            Assert.NotNull(queryResult.Value.RouteNetworkElements[TestRouteNetwork.HH_1].InterestRelations);
            Assert.Contains(queryResult.Value.RouteNetworkElements[TestRouteNetwork.HH_1].InterestRelations, r => r.RefId == interestId && r.RelationKind == RouteNetworkInterestRelationKindEnum.End);
        }
コード例 #11
0
        public static Result <NodeContainer> GetNodeContainerFromRouteNodeId(IQueryDispatcher queryDispatcher, Guid routeNodeId)
        {
            // Query all route node interests
            var routeNetworkInterestQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                routeNodeId
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementOnly
            };

            Result <GetRouteNetworkDetailsResult> interestsQueryResult = queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkInterestQuery).Result;

            if (interestsQueryResult.IsFailed)
            {
                return(Result.Fail(interestsQueryResult.Errors.First()));
            }

            var interestIdList = new InterestIdList();

            interestIdList.AddRange(interestsQueryResult.Value.RouteNetworkElements[routeNodeId].InterestRelations.Select(r => r.RefId));

            // Only query for equipments if interests are returned from the route network query
            if (interestIdList.Count > 0)
            {
                // Query all the equipments related to the route network element
                var equipmentQueryResult = queryDispatcher.HandleAsync <GetEquipmentDetails, Result <GetEquipmentDetailsResult> >(
                    new GetEquipmentDetails(interestIdList)
                {
                    EquipmentDetailsFilter = new EquipmentDetailsFilterOptions()
                    {
                        IncludeRouteNetworkTrace = false
                    }
                }
                    ).Result;

                if (equipmentQueryResult.IsFailed)
                {
                    return(Result.Fail(equipmentQueryResult.Errors.First()));
                }

                if (equipmentQueryResult.Value.NodeContainers != null && equipmentQueryResult.Value.NodeContainers.Count > 0)
                {
                    return(Result.Ok(equipmentQueryResult.Value.NodeContainers.First()));
                }
            }

            return(Result.Fail(new Error($"Failed to find node container in route node with id: {routeNodeId}")));
        }
        public async void QueryByNonExistingInterestId_ShouldFail()
        {
            // Act
            var routeNetworkQuery = new GetRouteNetworkDetails(new InterestIdList()
            {
                Guid.NewGuid()
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects
            };

            Result <GetRouteNetworkDetailsResult> queryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery);

            // Assert
            queryResult.IsFailed.Should().BeTrue();
            queryResult.Errors.OfType <GetRouteNetworkDetailsError>().Should().Contain(e => e.Code == GetRouteNetworkDetailsErrorCodes.INVALID_QUERY_ARGUMENT_ERROR_LOOKING_UP_SPECIFIED_INTEREST_BY_ID);
        }
コード例 #13
0
        public async void QueryRouteElement_ThatDontExists_ShouldReturnFailure()
        {
            // Setup
            var nonExistingRouteNetworkElementId = Guid.NewGuid();

            var routeNodeQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                nonExistingRouteNetworkElementId
            });

            // Act
            var routeNodeQueryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNodeQuery);

            // Assert
            Assert.True(routeNodeQueryResult.IsFailed);

            // Assert that the error msg contains the id of route network element that the service could not lookup
            //Assert.Contains(nonExistingRouteNetworkElementId.ToString(), routeNodeQueryResult.Errors);
        }
コード例 #14
0
        public async Task QueryRouteNetworkDetailsOfCC_1()
        {
            var routeNetworkQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CC_1
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects
            };

            Result <GetRouteNetworkDetailsResult> routeNetworkQueryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery);

            // Assert
            routeNetworkQueryResult.IsSuccess.Should().BeTrue();
            routeNetworkQueryResult.Value.RouteNetworkElements.Count.Should().Be(1);
            routeNetworkQueryResult.Value.Interests.Count.Should().Be(4);
            routeNetworkQueryResult.Value.RouteNetworkElements[TestRouteNetwork.CC_1].InterestRelations.Length.Should().Be(4);
            routeNetworkQueryResult.Value.RouteNetworkElements[TestRouteNetwork.CC_1].InterestRelations.Count(r => r.RelationKind == RouteNetworkInterestRelationKindEnum.PassThrough).Should().Be(2);
            routeNetworkQueryResult.Value.RouteNetworkElements[TestRouteNetwork.CC_1].InterestRelations.Count(r => r.RelationKind == RouteNetworkInterestRelationKindEnum.Start).Should().Be(1);
        }
        private void AddInterestReferencesToRouteNetworkElements(GetRouteNetworkDetails query, GetRouteNetworkDetailsResult queryResult)
        {
            if (query.RelatedInterestFilter != RelatedInterestFilterOptions.None)
            {
                var interestsProjection = _eventStore.Projections.Get <InterestsProjection>();

                foreach (var routeElement in queryResult.RouteNetworkElements)
                {
                    // Add relations to the route network element
                    var interestRelationsResult = interestsProjection.GetInterestsByRouteNetworkElementId(routeElement.Id);

                    if (interestRelationsResult.IsFailed)
                    {
                        throw new ApplicationException($"Unexpected error querying interests related to route network element with id: {routeElement.Id} {interestRelationsResult.Errors.First()}");
                    }

                    routeElement.InterestRelations = MapInterestRelationDomainObjectsToQueryObjects(interestRelationsResult.Value);
                }
            }
        }
コード例 #16
0
        public async void CreateAndRemoveWalkOfInterest_ShouldReturnSuccess()
        {
            // Route network subset used in this test:
            // (CO_1) <- (S1) -> (HH_1)
            var interestId = Guid.NewGuid();

            var walk = new RouteNetworkElementIdList()
            {
                TestRouteNetwork.S1
            };

            var routeNetworkQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CO_1
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects
            };

            // Act
            var registerWalkOfInterestCommand       = new RegisterWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId, walk);
            var registerWalkOfInterestCommandResult = await _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> > (registerWalkOfInterestCommand);

            Result <GetRouteNetworkDetailsResult> routeNetworkQueryResultBefore = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery);

            var unregisterWalkOfInterestCommand       = new UnregisterInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId);
            var unregisterWalkOfInterestCommandResult = await _commandDispatcher.HandleAsync <UnregisterInterest, Result>(unregisterWalkOfInterestCommand);

            Result <GetRouteNetworkDetailsResult> routeNetworkQueryResultAfter = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery);

            // Assert command result
            registerWalkOfInterestCommandResult.IsSuccess.Should().BeTrue();
            unregisterWalkOfInterestCommandResult.IsSuccess.Should().BeTrue();

            // Assert query result
            routeNetworkQueryResultBefore.IsSuccess.Should().BeTrue();
            routeNetworkQueryResultBefore.Value.Interests.ContainsKey(interestId).Should().BeTrue();

            routeNetworkQueryResultAfter.IsSuccess.Should().BeTrue();
            routeNetworkQueryResultAfter.Value.Interests.ContainsKey(interestId).Should().BeFalse();
        }
コード例 #17
0
        public async void CreateValidWalkOfInterestUsingOneSegmentIdOnly_ShouldReturnSuccess()
        {
            // Route network subset used in this test:
            // (CO_1) <- (S1) -> (HH_1)
            var interestId = Guid.NewGuid();

            var walk = new RouteNetworkElementIdList()
            {
                TestRouteNetwork.S1
            };

            // Act
            var registerWalkOfInterestCommand       = new RegisterWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId, walk);
            var registerWalkOfInterestCommandResult = await _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> > (registerWalkOfInterestCommand);

            var routeNetworkQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CO_1
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects
            };

            Result <GetRouteNetworkDetailsResult> routeNetworkQueryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> > (routeNetworkQuery);

            // Assert command result
            registerWalkOfInterestCommandResult.IsSuccess.Should().BeTrue();
            registerWalkOfInterestCommandResult.Value.Kind.Should().Be(RouteNetworkInterestKindEnum.WalkOfInterest);
            registerWalkOfInterestCommandResult.Value.RouteNetworkElementRefs.Count.Should().Be(3);
            registerWalkOfInterestCommandResult.Value.RouteNetworkElementRefs.Should().Contain(TestRouteNetwork.CO_1);
            registerWalkOfInterestCommandResult.Value.RouteNetworkElementRefs.Should().Contain(TestRouteNetwork.S1);
            registerWalkOfInterestCommandResult.Value.RouteNetworkElementRefs.Should().Contain(TestRouteNetwork.HH_1);

            // Assert query result
            routeNetworkQueryResult.IsSuccess.Should().BeTrue();
            routeNetworkQueryResult.Value.Interests[interestId].RouteNetworkElementRefs.Count.Should().Be(3);
            routeNetworkQueryResult.Value.Interests[interestId].RouteNetworkElementRefs.Should().Contain(TestRouteNetwork.CO_1);
            routeNetworkQueryResult.Value.Interests[interestId].RouteNetworkElementRefs.Should().Contain(TestRouteNetwork.S1);
            routeNetworkQueryResult.Value.Interests[interestId].RouteNetworkElementRefs.Should().Contain(TestRouteNetwork.HH_1);
            routeNetworkQueryResult.Value.Interests[interestId].RouteNetworkElementRefs.Should().NotContain(TestRouteNetwork.S2);
        }
コード例 #18
0
        public async void QueryWithNoInterestOrRouteElementIds_ShouldFail()
        {
            // Setup
            var routeNodeQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
            })
            {
                RouteNetworkElementFilter = new RouteNetworkElementFilterOptions()
                {
                    IncludeSafetyInfo = true
                },
                RelatedInterestFilter = RelatedInterestFilterOptions.None
            };

            // Act
            var queryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNodeQuery);

            // Assert
            queryResult.IsFailed.Should().BeTrue();
            queryResult.Errors.OfType <GetRouteNetworkDetailsError>().Should().Contain(e => e.Code == GetRouteNetworkDetailsErrorCodes.INVALID_QUERY_ARGUMENT_NO_INTEREST_OR_ROUTE_NETWORK_IDS_SPECIFIED);
        }
コード例 #19
0
        public async void ExplicitlyQueryCoordinatesOnly_ShouldReturnCoordinatesOnly()
        {
            // Setup
            var routeNodeQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CO_1, TestRouteNetwork.S13
            })
            {
                RouteNetworkElementFilter = new RouteNetworkElementFilterOptions()
                {
                    IncludeCoordinates = true
                },
                RelatedInterestFilter = RelatedInterestFilterOptions.None
            };

            // Act
            var queryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNodeQuery);

            // Assert
            Assert.True(queryResult.IsSuccess);
            Assert.Equal(2, queryResult.Value.RouteNetworkElements.Count);

            // CO_1
            Assert.Equal("[559485.6702553608,6209040.000026836]", queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].Coordinates);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].RouteNodeInfo);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].RouteSegmentInfo);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].NamingInfo);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].MappingInfo);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].LifecycleInfo);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].SafetyInfo);

            // S13
            Assert.Equal("[[559537.3506715331,6209028.300262455],[559602.7453810525,6209027.060552321]]", queryResult.Value.RouteNetworkElements[TestRouteNetwork.S13].Coordinates);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.S13].RouteNodeInfo);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.S13].RouteSegmentInfo);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.S13].NamingInfo);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.S13].MappingInfo);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.S13].LifecycleInfo);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.S13].SafetyInfo);
        }
コード例 #20
0
        public async void QueryNonExistingRouteNetworkElement_ShouldFail()
        {
            // Setup
            var routeNodeQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                Guid.NewGuid()
            })
            {
                RouteNetworkElementFilter = new RouteNetworkElementFilterOptions()
                {
                    IncludeSafetyInfo = true
                },
                RelatedInterestFilter = RelatedInterestFilterOptions.None
            };

            // Act
            var queryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNodeQuery);

            // Assert
            queryResult.IsFailed.Should().BeTrue();
            queryResult.Errors.OfType <GetRouteNetworkDetailsError>().Should().Contain(e => e.Code == GetRouteNetworkDetailsErrorCodes.INVALID_QUERY_ARGUMENT_ERROR_LOOKING_UP_SPECIFIED_ROUTE_NETWORK_ELEMENT_BY_ID);
        }
コード例 #21
0
        public async void ExplicitlyQueryNamingInfoOnly_ShouldReturnNamingInfoOnly()
        {
            // Setup
            var routeNodeQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CO_1
            })
            {
                RouteNetworkElementFilter = new RouteNetworkElementFilterOptions()
                {
                    IncludeNamingInfo = true
                },
                RelatedInterestFilter = RelatedInterestFilterOptions.None
            };

            // Act
            var queryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNodeQuery);

            // Assert
            Assert.True(queryResult.IsSuccess);
            Assert.Single(queryResult.Value.RouteNetworkElements);

            var nodeFromQueryResult = queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1];

            // Assert that route node info is returned
            Assert.NotNull(nodeFromQueryResult.NamingInfo);
            Assert.Equal("CO-1", nodeFromQueryResult.NamingInfo.Name);
            Assert.Equal("Central Office 1", nodeFromQueryResult.NamingInfo.Description);

            // Assert that the rest of the information is not set
            Assert.Null(nodeFromQueryResult.Coordinates);
            Assert.Null(nodeFromQueryResult.RouteNodeInfo);
            Assert.Null(nodeFromQueryResult.RouteSegmentInfo);
            Assert.Null(nodeFromQueryResult.MappingInfo);
            Assert.Null(nodeFromQueryResult.LifecycleInfo);
            Assert.Null(nodeFromQueryResult.SafetyInfo);
        }
        public async void QueryExplicitlyRequestingNoInterestInformation_ShouldReturnNoInterestInformation()
        {
            // Create interest (CO_1) <- (S1) -> (HH_1) that we can then try query
            var interestId = Guid.NewGuid();

            var walk = new RouteNetworkElementIdList()
            {
                TestRouteNetwork.S1
            };
            var createInterestCommand = new RegisterWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId, walk);

            await _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> >(createInterestCommand);

            // Act: Query CO_1, S1, HH_1 and HH_2
            var routeNetworkQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CO_1, TestRouteNetwork.S1, TestRouteNetwork.HH_1, TestRouteNetwork.HH_2
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.None
            };

            Result <GetRouteNetworkDetailsResult> queryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery);

            // Assert that we got information back on all 4 network elements queried
            Assert.True(queryResult.IsSuccess);
            Assert.Equal(4, queryResult.Value.RouteNetworkElements.Count);

            // Assert that we did'nt get any interest object back
            Assert.Empty(queryResult.Value.Interests);

            // Assert that no route elements got interest relations
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].InterestRelations);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.S1].InterestRelations);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.HH_1].InterestRelations);
            Assert.Null(queryResult.Value.RouteNetworkElements[TestRouteNetwork.HH_2].InterestRelations);
        }
コード例 #23
0
        public async void QueryMultiRouteElement_ShouldReturnSuccess()
        {
            // Setup
            var routeNodeQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CO_1, TestRouteNetwork.S13, TestRouteNetwork.S5
            });

            // Act
            var queryResult = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNodeQuery);

            // Assert
            Assert.True(queryResult.IsSuccess);
            Assert.Equal(3, queryResult.Value.RouteNetworkElements.Count);

            Assert.Equal(TestRouteNetwork.CO_1, queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].Id);
            Assert.Equal(RouteNetworkElementKindEnum.RouteNode, queryResult.Value.RouteNetworkElements[TestRouteNetwork.CO_1].Kind);

            Assert.Equal(TestRouteNetwork.S13, queryResult.Value.RouteNetworkElements[TestRouteNetwork.S13].Id);
            Assert.Equal(RouteNetworkElementKindEnum.RouteSegment, queryResult.Value.RouteNetworkElements[TestRouteNetwork.S13].Kind);

            Assert.Equal(TestRouteNetwork.S5, queryResult.Value.RouteNetworkElements[TestRouteNetwork.S5].Id);
            Assert.Equal(RouteNetworkElementKindEnum.RouteSegment, queryResult.Value.RouteNetworkElements[TestRouteNetwork.S5].Kind);
        }
コード例 #24
0
        public async void UpdateInterestWithInvalidWalk_ShouldFail()
        {
            // Route network subset used in this test:
            // (CO_1) <- (S1) -> (HH_1)
            var interestId = Guid.NewGuid();

            var walk = new RouteNetworkElementIdList()
            {
                TestRouteNetwork.S1
            };

            // Walk with hole
            var updatedWalk = new RouteNetworkElementIdList()
            {
                TestRouteNetwork.S2, TestRouteNetwork.S5
            };

            var routeNetworkQuery_CO1 = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.CO_1
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects
            };

            var routeNetworkQuery_HH2 = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
            {
                TestRouteNetwork.HH_2
            })
            {
                RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementAndInterestObjects
            };

            // Act
            var registerWalkOfInterestCommand       = new RegisterWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId, walk);
            var registerWalkOfInterestCommandResult = await _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> >(registerWalkOfInterestCommand);

            Result <GetRouteNetworkDetailsResult> routeNetworkQueryResultBefore = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery_CO1);

            var updateWalkOfInterestCommand       = new UpdateWalkOfInterest(Guid.NewGuid(), new UserContext("test", Guid.Empty), interestId, updatedWalk);
            var updateWalkOfInterestCommandResult = await _commandDispatcher.HandleAsync <UpdateWalkOfInterest, Result <RouteNetworkInterest> >(updateWalkOfInterestCommand);

            Result <GetRouteNetworkDetailsResult> co1_routeNetworkQueryResultAfter = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery_CO1);

            Result <GetRouteNetworkDetailsResult> hh2_routeNetworkQueryResultAfter = await _queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNetworkQuery_HH2);

            // Assert command result
            registerWalkOfInterestCommandResult.IsSuccess.Should().BeTrue();
            updateWalkOfInterestCommandResult.IsFailed.Should().BeTrue();
            routeNetworkQueryResultBefore.IsSuccess.Should().BeTrue();
            co1_routeNetworkQueryResultAfter.IsSuccess.Should().BeTrue();
            hh2_routeNetworkQueryResultAfter.IsSuccess.Should().BeTrue();

            // Assert query result
            routeNetworkQueryResultBefore.Value.Interests.ContainsKey(interestId).Should().BeTrue();
            routeNetworkQueryResultBefore.Value.Interests[interestId].RouteNetworkElementRefs.Count.Should().Be(3);

            // Make sure index is *not* updated to include new interest at HH 2
            hh2_routeNetworkQueryResultAfter.Value.Interests.ContainsKey(interestId).Should().BeFalse();

            // Make sure index is still holding interest at CO 1
            co1_routeNetworkQueryResultAfter.Value.Interests.ContainsKey(interestId).Should().BeTrue();
        }
コード例 #25
0
        public RouteNetworkServiceQueries(ILogger <RouteNetworkServiceQueries> logger, IQueryDispatcher queryDispatcher)
        {
            Description = "GraphQL API for querying data owned by route nodes and route segments";

            Field <RouteNetworkElementType>(
                "routeElement",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "Id"
            }),
                resolve: context =>
            {
                if (!Guid.TryParse(context.GetArgument <string>("id"), out Guid routeNodeId))
                {
                    context.Errors.Add(new ExecutionError("Wrong value for guid"));
                    return(null);
                }

                var routeNodeQuery = new GetRouteNetworkDetails(new RouteNetworkElementIdList()
                {
                    routeNodeId
                })
                {
                    RelatedInterestFilter = RelatedInterestFilterOptions.ReferencesFromRouteElementOnly
                };

                var queryResult = queryDispatcher.HandleAsync <GetRouteNetworkDetails, Result <GetRouteNetworkDetailsResult> >(routeNodeQuery).Result;

                if (queryResult.IsFailed)
                {
                    context.Errors.Add(new ExecutionError(queryResult.Errors.First().Message));
                    return(null);
                }

                return(queryResult.Value.RouteNetworkElements[routeNodeId]);
            }
                );


            Field <ListGraphType <RouteNetworkTraceType> >(
                "nearestNeighborNodes",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "sourceRouteNodeId"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <RouteNodeKindEnumType> > > {
                Name = "stops"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <RouteNodeKindEnumType> > > {
                Name = "interests"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "maxHits"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "maxBirdFlyDistanceMeters"
            }
                    ),
                resolve: context =>
            {
                Guid routeNodeId = context.GetArgument <Guid>("sourceRouteNodeId");
                List <RouteNodeKindEnum> stops     = context.GetArgument <List <RouteNodeKindEnum> >("stops");
                List <RouteNodeKindEnum> interests = context.GetArgument <List <RouteNodeKindEnum> >("interests");
                int maxHits = context.GetArgument <int>("maxHits");
                int maxBirdFlyDistanceMeters = context.GetArgument <int>("maxBirdFlyDistanceMeters");


                var nearestNodeQuery = new FindNearestRouteNodes(routeNodeId, maxHits, maxBirdFlyDistanceMeters, stops.ToArray(), interests.ToArray());

                var nearestNodeQueryResult = queryDispatcher.HandleAsync <FindNearestRouteNodes, Result <FindNearestRouteNodesResult> >(nearestNodeQuery).Result;

                if (nearestNodeQueryResult.IsFailed)
                {
                    context.Errors.Add(new ExecutionError(nearestNodeQueryResult.Errors.First().Message));
                    return(null);
                }

                return(nearestNodeQueryResult.Value.RouteNetworkTraces);
            }
                );
        }