示例#1
0
        /// <summary>
        /// Invoke the schema to be part of the application performing final setup and configuration.
        /// </summary>
        /// <param name="appBuilder">The application builder.</param>
        public void UseSchema(IApplicationBuilder appBuilder)
        {
            this.UseSchema(appBuilder?.ApplicationServices, false);

            if (_options.Extensions != null)
            {
                foreach (var additionalOptions in _options.Extensions)
                {
                    additionalOptions.Value.UseExtension(appBuilder, appBuilder.ApplicationServices);
                }
            }

            if (!_options.QueryHandler.DisableDefaultRoute)
            {
                // when possible, create the singleton of the processor up front to avoid any
                // calls into the DI container at runtime.
                _handler = new GraphQueryHandler <TSchema>();
                appBuilder.MapWhen(
                    context => context.Request.Path == _options.QueryHandler.Route,
                    _handler.Execute);

                appBuilder?.ApplicationServices.WriteLogEntry(
                    (l) => l.SchemaRouteRegistered <TSchema>(
                        _options.QueryHandler.Route));
            }
        }
示例#2
0
        /// <summary>
        /// Uses the schema.
        /// </summary>
        /// <param name="appBuilder">The application builder.</param>
        public void UseSchema(IApplicationBuilder appBuilder)
        {
            this.UseSchema(appBuilder?.ApplicationServices);

            if (_options.QueryHandler.DisableDefaultRoute)
            {
                return;
            }

            // when possible, create the singleton of hte processor up front to avoid any
            // calls into the DI container at runtime.
            _handler = new GraphQueryHandler <TSchema>();
            appBuilder.Map(_options.QueryHandler.Route, _handler.CreateInvoker);

            this.WriteLogEntry(
                appBuilder?.ApplicationServices,
                (l) => l.SchemaRouteRegistered <TSchema>(
                    _options.QueryHandler.Route));
        }
示例#3
0
        public void Setup()
        {
            _fake = new Fake();
            var mocker = _fake.CreateMocker();

            var queryService = new Mock <IQueryService>();

            mocker.Use <IQueryService>(queryService);
            queryService.Setup(q => q.Execute(It.IsAny <InternalGraphQuery>(), It.IsAny <IQueryExecutionContext>()))
            .Returns(() =>
            {
                var graph = JsonConvert.DeserializeObject <PropertyGraphModel>(_graph);
                _graph    = JsonConvert.SerializeObject(graph);
                foreach (var vertex in graph.Vertices)
                {
                    vertex.Edges = new List <PropertyEdgeModel>();
                    if (vertex.Props == null)
                    {
                        vertex.Props = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
                    }
                    else
                    {
                        vertex.Props = new Dictionary <string, object>(vertex.Props, StringComparer.OrdinalIgnoreCase);
                    }
                }

                graph.CreateLinks();

                return(Task.FromResult(new ConcurrentGraphModel(graph)));
            });

            mocker.Use <IGraphQueryCompiler>(new GraphQueryCompiler());

            _handler = mocker.CreateInstance <GraphQueryHandler>();

            _graph = @"
                {
                   'Vertices':[
                      {
                         'Id':'00000000-0000-0000-0000-000000000001', 'Props':{ }
                      },
                      {
                         'Id':'00000000-0000-0000-0000-000000000002', 'Props':{ } 
                      },
                      {
                         'Id':'00000000-0000-0000-0000-000000000003', 'Props':{ }
                      },
                      {
                         'Id':'00000000-0000-0000-0000-000000000004', 'Props':{ }
                      },
                      {
                         'Id':'00000000-0000-0000-0000-000000000005', 'Props':{ }
                      },
                      {
                         'Id':'00000000-0000-0000-0000-000000000006', 'Props':{ }
                      },
                      {
                         'Id':'00000000-0000-0000-0000-000000000007', 'Props':{ }
                      },
                      {
                         'Id':'00000000-0000-0000-0000-000000000008', 'Props':{ }
                      },
                      {
                         'Id':'00000000-0000-0000-0000-000000000009', 'Props':{ }
                      },
                      {
                         'Id':'00000000-0000-0000-0000-000000000010', 'Props':{ }
                      }                   
                    ],
                   'Edges':[
                        { Source: 0, Target: 1 },
                        { Source: 0, Target: 6 },
                        { Source: 0, Target: 2 },
                        { Source: 0, Target: 3 },
                        { Source: 0, Target: 5 },
                        { Source: 0, Target: 4 },

                        { Source: 1, Target: 4 },
                        { Source: 1, Target: 6 },
                        { Source: 1, Target: 2 },
                        { Source: 1, Target: 0 },

                        { Source: 2, Target: 6 },
                        { Source: 2, Target: 7 },
                        { Source: 2, Target: 3 },
                        { Source: 2, Target: 0 },
                        { Source: 2, Target: 1 },

                        { Source: 3, Target: 7 },
                        { Source: 3, Target: 5 },
                        { Source: 3, Target: 4 },
                        { Source: 3, Target: 0 },
                        { Source: 3, Target: 2 },

                        { Source: 4, Target: 1 },
                        { Source: 4, Target: 0 },
                        { Source: 4, Target: 3 },
                        { Source: 4, Target: 5 },

                        { Source: 5, Target: 4 },
                        { Source: 5, Target: 0 },
                        { Source: 5, Target: 3 },

                        { Source: 6, Target: 1 },
                        { Source: 6, Target: 0 },
                        { Source: 6, Target: 2 },

                        { Source: 7, Target: 2 },
                        { Source: 7, Target: 3 },
                        { Source: 7, Target: 8 },

                        { Source: 8, Target: 7 },
                        { Source: 8, Target: 9 },

                        { Source: 9, Target: 8 }                     
                   ]
                }
            ";
        }