public void V_ofType_values_of_one_property()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Values(x => x.Name)
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(_P1).values(_P2)");

            query.parameters
            .Should()
            .Contain("_P1", "User").And
            .Contain("_P2", "Name");
        }
Exemple #2
0
        public void V_ofType_Optional_one_out_traversal()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V()
                        .Optional(
                __ => __.Out <Knows>())
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().optional(__.out(_P1))");

            query.parameters
            .Should()
            .Contain("_P1", "Knows");
        }
        public void V_ofType_order_ByLambda()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Order()
                        .ByLambda("it.property('str').value().length()")
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(_P1).order().by({it.property('str').value().length()})");

            query.parameters
            .Should()
            .Contain("_P1", "User");
        }
        public void Out()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Out <Knows>()
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(_P1).out(_P2)");

            query.parameters
            .Should()
            .Contain("_P1", "User").And
            .Contain("_P2", "Knows");
        }
Exemple #5
0
        public void V_ofType_string_property_exists()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Where(t => t.Name != null)
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(_P1).has(_P2)");

            query.parameters
            .Should()
            .Contain("_P1", "User").And
            .Contain("_P2", "Name");
        }
Exemple #6
0
        public void V_as_not_inlined()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .As(new StepLabel <User>("a"))
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(_P1).as(_P2)");

            query.parameters
            .Should()
            .Contain("_P1", "User").And
            .Contain("_P2", "a");
        }
Exemple #7
0
        public void V_ofType_Optional_one_out_traversal_2()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V()
                        .Not(__ => __.OfType <Authority>())
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().not(__.hasLabel(_P1, _P2))");

            query.parameters
            .Should()
            .Contain("_P1", "Company").And
            .Contain("_P2", "User");
        }
        public void V_OfType_with_inheritance()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V()
                        .OfType <Authority>()
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(_P1, _P2)");

            query.parameters
            .Should()
            .Contain("_P1", "Company").And
            .Contain("_P2", "User");
        }
Exemple #9
0
        public void V_ofType_Repeat_out_traversal()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Repeat(__ => __.Out <Knows>())
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(_P1).repeat(__.out(_P2))");

            query.parameters
            .Should()
            .Contain("_P1", "User").And
            .Contain("_P2", "Knows");
        }
        public void V_ofType_order_ByMember()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Order()
                        .ByMember(x => x.Name)
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(_P1).order().by(_P2, incr)");

            query.parameters
            .Should()
            .Contain("_P1", "User").And
            .Contain("_P2", "Name");
        }
        public async Task DateTime_is_UTC()
        {
            var queryProviderMock = new Mock <INativeGremlinQueryProvider <string> >();

            queryProviderMock
            .Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <IDictionary <string, object> >()))
            .Returns(AsyncEnumerable.Return(SingleCompanyJson));

            var user = await queryProviderMock.Object
                       .Select(JToken.Parse)
                       .WithModel(GraphModel.FromAssembly(Assembly.GetExecutingAssembly(), typeof(Vertex), typeof(Edge), GraphElementNamingStrategy.Simple))
                       .WithJsonSupport()
                       .Execute(GremlinQuery <Company> .Create())
                       .First();

            user.Should().NotBeNull();
            user.Id.Should().Be("d13ef3f51c86496eb2c22823601446ad");
            user.FoundingDate.Kind.Should().Be(DateTimeKind.Utc);
        }
        public async Task Mixed_Ids()
        {
            var queryProviderMock = new Mock <INativeGremlinQueryProvider <string> >();

            queryProviderMock
            .Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <IDictionary <string, object> >()))
            .Returns(AsyncEnumerable.Return("[ 1, \"id2\" ]"));

            var ids = await queryProviderMock.Object
                      .Select(JToken.Parse)
                      .WithModel(GraphModel.FromAssembly(Assembly.GetExecutingAssembly(), typeof(Vertex), typeof(Edge), GraphElementNamingStrategy.Simple))
                      .WithJsonSupport()
                      .Execute(GremlinQuery.Create().V().Id())
                      .ToArray();

            ids.Should().HaveCount(2);
            ids[0].Should().Be(1);
            ids[1].Should().Be("id2");
        }
        public void V_ofType_contains_specific_phoneNumber()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Where(t => t.PhoneNumbers.Contains("+4912345"))
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(_P1).has(_P2, eq(_P3))");

            query.parameters
            .Should()
            .Contain("_P1", "User").And
            .Contain("_P2", "PhoneNumbers").And
            .Contain("_P3", "+4912345");
        }
Exemple #14
0
        public void Set_Property()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Property(x => x.Age, 36)
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(P1).property(P2, P3)");

            query.parameters
            .Should()
            .Contain("P1", "User").And
            .Contain("P2", "Age").And
            .Contain("P3", 36);
        }
Exemple #15
0
        public void V_ofType_values_of_two_properties()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Values(x => x.Name, x => x.Id)
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(P1).values(P2, P3)");

            query.parameters
            .Should()
            .Contain("P1", "User").And
            .Contain("P2", "Name").And
            .Contain("P3", "Id");
        }
Exemple #16
0
        public void V_ofType_order_ByTraversal()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Order()
                        .ByTraversal(__ => __.Values(x => x.Name))
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(P1).order().by(__.values(P2), incr)");

            query.parameters
            .Should()
            .Contain("P1", "User").And
            .Contain("P2", "Name");
        }
Exemple #17
0
        public void V_ofType_has_string_property()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <Language>()
                        .Where(t => t.Id == "languageId")
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(P1).has(P2, eq(P3))");

            query.parameters
            .Should()
            .Contain("P1", "Language").And
            .Contain("P2", "Id").And
            .Contain("P3", "languageId");
        }
Exemple #18
0
        public void V_ofType_has_bool_property_with_implicit_comparison2()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <TimeFrame>()
                        .Where(t => !t.Enabled)
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(P1).has(P2, eq(P3))");

            query.parameters
            .Should()
            .Contain("P1", "TimeFrame").And
            .Contain("P2", "Enabled").And
            .Contain("P3", false);
        }
Exemple #19
0
        public void V_ofType_has_greater_or_equal_int_property()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Where(t => t.Age >= 36)
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(P1).has(P2, gte(P3))");

            query.parameters
            .Should()
            .Contain("P1", "User").And
            .Contain("P2", "Age").And
            .Contain("P3", 36);
        }
        public void V_ofType_has_converted_int_property()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Where(t => (object)t.Age == (object)36)
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(_P1).has(_P2, eq(_P3))");

            query.parameters
            .Should()
            .Contain("_P1", "User").And
            .Contain("_P2", "Age").And
            .Contain("_P3", 36);
        }
Exemple #21
0
        public async Task TimeFrame_strongly_typed()
        {
            var queryProviderMock = new Mock <INativeGremlinQueryProvider>();

            queryProviderMock
            .Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <IDictionary <string, object> >()))
            .Returns(AsyncEnumerable.Return(SingleTimeFrameJson));

            var timeFrame = await queryProviderMock.Object
                            .WithModel(GraphModel.FromAssembly(Assembly.GetExecutingAssembly(), typeof(Vertex), typeof(Edge), GraphElementNamingStrategy.Simple))
                            .WithJsonSupport()
                            .Execute(GremlinQuery.Create("g").Cast <TimeFrame>())
                            .First();

            timeFrame.Should().NotBeNull();
            timeFrame.Id.Should().Be("15da4cea93114bfc8c6b23847487d97b");
            timeFrame.StartTime.Should().Be(new TimeSpan(6, 0, 0));
            timeFrame.Duration.Should().Be(new TimeSpan(16, 0, 0));
        }
        public async Task Language_by_vertex_inheritance()
        {
            var queryProviderMock = new Mock <INativeGremlinQueryProvider <string> >();

            queryProviderMock
            .Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <IDictionary <string, object> >()))
            .Returns(AsyncEnumerable.Return(SingleLanguageJson));

            var language = await queryProviderMock.Object
                           .Select(JToken.Parse)
                           .WithModel(GraphModel.FromAssembly(Assembly.GetExecutingAssembly(), typeof(Vertex), typeof(Edge), GraphElementNamingStrategy.Simple))
                           .WithJsonSupport()
                           .Execute(GremlinQuery <Vertex> .Create())
                           .First() as Language;

            language.Should().NotBeNull();
            language?.Id.Should().Be("be66544bcdaa4ee9990eaf006585153b");
            language?.IetfLanguageTag.Should().Be("de");
        }
Exemple #23
0
        public void AddV_with_nulls()
        {
            var query = GremlinQuery
                        .Create("g")
                        .AddV(new Language {
                Id = "id"
            })
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.addV(P1).property(P2, P3)");

            query.parameters
            .Should()
            .Contain("P1", "Language").And
            .Contain("P2", "Id").And
            .Contain("P3", "id");
        }
Exemple #24
0
        public void V_ofType_has_disjunction()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Where(t => t.Age == 36 || t.Age == 42)
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(P1).or(__.has(P2, eq(P3)), __.has(P2, eq(P4)))");

            query.parameters
            .Should()
            .Contain("P1", "User").And
            .Contain("P2", "Age").And
            .Contain("P3", 36).And
            .Contain("P4", 42);
        }
Exemple #25
0
        public void V_ofType_has_bool_property_with_explicit_comparison1()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <TimeFrame>()
                        // ReSharper disable once RedundantBoolCompare
                        .Where(t => t.Enabled == true)
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(P1).has(P2, eq(P3))");

            query.parameters
            .Should()
            .Contain("P1", "TimeFrame").And
            .Contain("P2", "Enabled").And
            .Contain("P3", true);
        }
Exemple #26
0
        public void BranchOnIdentity()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .BranchOnIdentity(
                _ => _.Out <Knows>(),
                _ => _.In <Knows>())
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(P1).branch(__.identity()).option(__.out(P2)).option(__.in(P2))");

            query.parameters
            .Should()
            .Contain("P1", "User").And
            .Contain("P2", "Knows");
        }
Exemple #27
0
        public async Task User_without_PhoneNumbers_strongly_typed()
        {
            var queryProviderMock = new Mock <INativeGremlinQueryProvider>();

            queryProviderMock
            .Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <IDictionary <string, object> >()))
            .Returns(AsyncEnumerable.Return(SingleUserWithoutPhoneNumbersJson));

            var user = await queryProviderMock.Object
                       .WithModel(GraphModel.FromAssembly(Assembly.GetExecutingAssembly(), typeof(Vertex), typeof(Edge), GraphElementNamingStrategy.Simple))
                       .WithJsonSupport()
                       .Execute(GremlinQuery.Create("g").Cast <User>())
                       .First();

            user.Should().NotBeNull();
            user.Id.Should().Be("d13ef3f51c86496eb2c22823601446ad");
            user.Age.Should().Be(36);
            user.PhoneNumbers.Should().BeEmpty();
            user.RegistrationDate.Should().Be(new DateTimeOffset(2017, 12, 1, 15, 28, 24, TimeSpan.Zero));
        }
Exemple #28
0
        public DocumentClientGremlinQueryProvider(IOptions <CosmosDbGraphConfiguration> configuration)
        {
            this._client = new DocumentClient(
                new Uri(configuration.Value.EndPoint),
                configuration.Value.AuthKey,
                new ConnectionPolicy {
                ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp
            });

            this._graph = this._client.CreateDocumentCollectionIfNotExistsAsync(
                UriFactory.CreateDatabaseUri(configuration.Value.Database),
                new DocumentCollection {
                Id = configuration.Value.GraphName
            },
                new RequestOptions {
                OfferThroughput = 1000
            }).Result;                                                  //TODO: Async!

            this.TraversalSource = GremlinQuery.Create(configuration.Value.TraversalSource);
        }
Exemple #29
0
        public void RewriteStepsTest()
        {
            var queryProviderMock        = new Mock <ITypedGremlinQueryProvider>();
            var subgraphStrategyProvider = queryProviderMock.Object.RewriteSteps <AddElementPropertiesStep>(
                step =>
            {
                if (step.Element is User)
                {
                    return new[] { new ReplaceElementPropertyStep <User, int>(step, user => user.Age, 36) }
                }
                ;

                return(Option <IEnumerable <GremlinStep> > .None);
            });

            subgraphStrategyProvider
            .Execute(GremlinQuery.Create("g").AddV(new User()));

            queryProviderMock.Verify(x => x.Execute(It.Is <IGremlinQuery <User> >(query => query.Steps[1] is ReplaceElementPropertyStep <User, int>)));
        }
        public void V_ofType_not_intersects_phoneNumbers()
        {
            var query = GremlinQuery
                        .Create("g")
                        .V <User>()
                        .Where(t => !t.PhoneNumbers.Intersects(new[] { "+4912345", "+4923456" }))
                        .Resolve(this._model)
                        .Serialize();

            query.queryString
            .Should()
            .Be("g.V().hasLabel(_P1).not(__.has(_P2, within(_P3, _P4)))");

            query.parameters
            .Should()
            .Contain("_P1", "User").And
            .Contain("_P2", "PhoneNumbers").And
            .Contain("_P3", "+4912345").And
            .Contain("_P4", "+4923456");
        }