Esempio n. 1
0
        public void ARBTypes_ARandRBSelectors()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var pattern = builder.Pattern <MovieNode, MovieActorRelationship, ActorNode>("Lagos").Pattern as Pattern;

            var arSelector = pattern.ARSelector;

            Assert.NotNull(arSelector);
            Assert.Equal("Lagos", arSelector.Parameters[0].Name);

            var rPropInfo =
                Utils.Utilities.GetPropertyInfoFrom(arSelector.Body, typeof(MovieNode), typeof(MovieActorRelationship));

            Assert.NotNull(rPropInfo);
            Assert.Equal(typeof(ICollection <MovieActorRelationship>), rPropInfo.PropertyType);
            Assert.Equal("Actors", rPropInfo.Name);

            var rbSelector = pattern.RBSelector;

            Assert.NotNull(rbSelector);

            var bPropInfo =
                Utils.Utilities.GetPropertyInfoFrom(rbSelector.Body, typeof(MovieActorRelationship), typeof(ActorNode));

            Assert.NotNull(bPropInfo);
            Assert.Equal(typeof(ActorNode), bPropInfo.PropertyType);
            Assert.Equal("Actor", bPropInfo.Name);
        }
Esempio n. 2
0
        public void EntityRead(string testContextName, TestContext testContext)
        {
            var actorTokens = new Dictionary <string, dynamic>
            {
                { "Name", "Ellen Pompeo" },
                { "Born", 1969 },
                { "Roles", new[] { "Meredith Grey" } },
                //{ "NewAddressName_AddressLine", null },
                { "NewAddressName_City", "Los Angeles" },
                { "NewAddressName_State", "California" },
                { "NewAddressName_Country", "US" },
                { "NewAddressName_Location_Latitude", 34.0522 },
                { "NewAddressName_Location_Longitude", -118.2437 },
                { "NewAddressName_ComplexProperty_Property", 14859 },
                { "NewAddressName_SomeOtherProperty", "something" },
                { "TestForeignKeyId", 0 },
                { "TestMarkedFK", 0 },
                { "TestGenericForeignKeyId", null },
                {
                    "__ncdannotationsmeta__",
                    "{\"null_props\":[\"NewAddressName_AddressLine\",\"NewAddressName_City\",\"NewAddressName_State\",\"NewAddressName_Country\"]}"
                }
            };

            var actorJObject = JObject.FromObject(actorTokens);

            var serializer = JsonSerializer.CreateDefault(testContext.DeserializerSettings);

            var actor = actorJObject.ToObject <ActorNode <int> >(serializer);

            Assert.NotNull(actor);

            Assert.Equal(typeof(ActorNode <int>), actor.GetType());

            var resolverTestContext = new ResolverTestContext();
            var actorContract       = resolverTestContext.AnnotationsContext.EntityResolver.ResolveContract(actor.GetType());

            var jsonProperties = (actorContract as JsonObjectContract)?.Properties;

            Assert.NotNull(jsonProperties);
            Assert.InRange(jsonProperties.Count, actorTokens.Count,
                           int.MaxValue); //the amount of properties returned can't be less than the token sent in

            foreach (var token in actorTokens)
            {
                if (token.Key == Defaults.MetadataPropertyName)
                {
                    continue;
                }

                var jsonProp =
                    jsonProperties.Where(jp => jp.PropertyName == token.Key).SingleOrDefault(); //has to be just one

                Assert.NotNull(jsonProp);

                var jsonPropValue = jsonProp.ValueProvider.GetValue(actor);

                Assert.Equal(token.Value, jsonPropValue);
            }
        }
Esempio n. 3
0
        public void RBTypes_AType()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var pattern = builder.Pattern <WriterNode, MovieNode>("Tinubu", "Lagos")
                          .Extend <MovieActorRelationship, ActorNode>("Ambode", RelationshipDirection.Incoming)
                          .Pattern as Pattern;

            var aType = pattern.AType;

            Assert.NotNull(aType);
            Assert.Equal(typeof(MovieNode), aType);

            var dir = pattern.Direction;

            Assert.NotNull(dir);
            Assert.Equal(RelationshipDirection.Incoming, dir.Value);

            //******

            var arSelector = pattern.ARSelector;

            Assert.NotNull(arSelector);
            Assert.Equal("Lagos", arSelector.Parameters[0].Name);
        }
Esempio n. 4
0
        public void ARTypes_BType()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var pattern =
                builder.Pattern <MovieNode, MovieActorRelationship, CypherObject>("Lagos", "rel", null)
                .Pattern as Pattern;

            var bType = pattern.BType;

            Assert.NotNull(bType);
            Assert.Equal(typeof(ActorNode), bType);

            var dir = pattern.Direction;

            Assert.NotNull(dir);
            Assert.Equal(RelationshipDirection.Incoming, dir.Value);

            //******

            var rbSelector = pattern.RBSelector;

            Assert.NotNull(rbSelector);
            Assert.Equal("rel", rbSelector.Parameters[0].Name);
        }
Esempio n. 5
0
        public void ARBAreAllNull_InvalidOperationException()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var ex = Assert.Throws <InvalidOperationException>(() => builder.Pattern(null, null, null));

            Assert.Equal(Messages.NullARBVariablesError, ex.Message);
        }
Esempio n. 6
0
        public void BeginRelationshipIsNull_ArgumentNullException()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var ex = Assert.Throws <ArgumentNullException>(() =>
                                                           builder.Pattern((Expression <Func <ActorNode, MovieActorRelationship> >)null, r => r.Movie));

            Assert.Equal("beginRelationship", ex.ParamName);
        }
Esempio n. 7
0
        public void ExtensionRBAreBothNull_NoInvalidOperationException()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var path = builder.Pattern((ActorNode actor) => actor.Movies, r => r.Movie)
                       .Extend(null, null, RelationshipDirection.Incoming);

            //if we reached this point, test passed.
        }
Esempio n. 8
0
        public void BothConstraintsAndPropsAreSet_InvalidOperationException()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var ex = Assert.Throws <InvalidOperationException>(() => builder
                                                               .Pattern((ActorNode actor) => actor.Movies, r => r.Movie)
                                                               .Constrain(actor => actor.Name == "Ellen Pompeo" && actor.Born == 1969)
                                                               .Prop(() => new { Name = "Ellen Pompeo", Born = 1969 }));

            Assert.Equal(string.Format(Messages.PropsAndConstraintsClashError, "A"), ex.Message);
        }
Esempio n. 9
0
        public void ForeignKeyAttribute_RTypes()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var pattern = builder.Pattern <MovieNode, WriterNode>("Lagos").Pattern as Pattern;

            var rTypes = pattern.RTypes;

            Assert.NotNull(rTypes);
            Assert.Single(rTypes);
            Assert.Equal("WROTE", rTypes.Single());
        }
Esempio n. 10
0
        public void ColumnAttributeWithName_RTypes()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var pattern = builder.Pattern <MovieNode, DirectorNode>("Lagos").Pattern as Pattern;

            var rTypes = pattern.RTypes;

            Assert.NotNull(rTypes);
            Assert.Single(rTypes);
            Assert.Equal("DIRECTED", rTypes.Single());
        }
Esempio n. 11
0
        public void NewTypeIsNotAssignableToOldType_InvalidOperationException()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var ex = Assert.Throws <InvalidOperationException>(() => builder
                                                               .Pattern((ActorNode actor) => actor.Movies, r => r.Movie)
                                                               .Constrain(actor => actor.Name == "Ellen Pompeo" && actor.Born == 1969)
                                                               .Type(typeof(MovieNode), null, null));

            Assert.Equal(string.Format(Messages.UnassignableTypeError, typeof(MovieNode), typeof(ActorNode)),
                         ex.Message);
        }
Esempio n. 12
0
        public void NoNameAttributes_RTypes()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var pattern =
                builder.Pattern <MovieNode, MovieExtraNode>("Lagos", RelationshipDirection.Incoming).Pattern as Pattern;

            var rTypes = pattern.RTypes;

            Assert.NotNull(rTypes);
            Assert.Single(rTypes);
            Assert.Equal("Movies", rTypes.Single());
        }
Esempio n. 13
0
        public void NewTypeIsAssignableToOldType()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var path = builder.Pattern <PersonNode>("actor")
                       .Constrain(actor => actor.Name == "Ellen Pompeo" && actor.Born == 1969);

            Assert.Equal(typeof(PersonNode), path.Pattern.AType);

            path = path.Type(typeof(ActorNode));

            Assert.Equal(typeof(ActorNode), path.Pattern.AType);
        }
Esempio n. 14
0
        public void TableAttribute_RTypes()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var pattern =
                builder.Pattern <MovieNode, MovieActorRelationship, CypherObject>("Lagos", "rel", null)
                .Pattern as Pattern;

            var rTypes = pattern.RTypes;

            Assert.NotNull(rTypes);
            Assert.Single(rTypes);
            Assert.Equal("ACTED_IN", rTypes.Single());
        }
Esempio n. 15
0
        public void ABTypes_RType()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var pattern = builder.Pattern <ActorNode, MovieNode>("Ambode", "Lagos").Pattern as Pattern;

            var rType = pattern.RType;

            Assert.NotNull(rType);
            Assert.Equal(typeof(MovieActorRelationship), rType);

            var dir = pattern.Direction;

            Assert.NotNull(dir);
            Assert.Equal(RelationshipDirection.Outgoing, dir.Value);

            //******

            var arSelector = pattern.ARSelector;

            Assert.NotNull(arSelector);
            Assert.Equal("Ambode", arSelector.Parameters[0].Name);

            var rPropInfo =
                Utils.Utilities.GetPropertyInfoFrom(arSelector.Body, typeof(ActorNode), typeof(MovieActorRelationship));

            Assert.NotNull(rPropInfo);
            Assert.Equal(typeof(ICollection <MovieActorRelationship>), rPropInfo.PropertyType);
            Assert.Equal("Movies", rPropInfo.Name);

            var rbSelector = pattern.RBSelector;

            Assert.NotNull(rbSelector);

            var bPropInfo =
                Utils.Utilities.GetPropertyInfoFrom(rbSelector.Body, typeof(MovieActorRelationship), typeof(MovieNode));

            Assert.NotNull(bPropInfo);
            Assert.Equal(typeof(MovieNode), bPropInfo.PropertyType);
            Assert.Equal("Movie", bPropInfo.Name);
        }
Esempio n. 16
0
        public void ExtensionPattern_TrueIsExtensionProperty()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var path = builder.Pattern((ActorNode actor) => actor.Movies, r => r.Movie)
                       .Extend("R2", "C", RelationshipDirection.Incoming);

            var pattern = path.Pattern as Pattern;

            Assert.NotNull(pattern);

            Assert.NotNull(pattern.AVariable);
            Assert.True(pattern.AVarIsAuto);
            Assert.Equal("R2",
                         pattern.RVariable); //test this to make sure we are interacting with the right pattern here, and not a previous one.
            Assert.Equal("C", pattern.BVariable);
            Assert.True(pattern.IsExtension);
        }
Esempio n. 17
0
        public void ARSelector_RBSelector()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var pattern =
                builder.Pattern <MovieNode, MovieActorRelationship, ActorNode>(A => A.Actors).Pattern as Pattern;

            var rbSelector = pattern.RBSelector;

            Assert.NotNull(rbSelector);

            var propInfo =
                Utils.Utilities.GetPropertyInfoFrom(rbSelector.Body, typeof(MovieActorRelationship), typeof(ActorNode));

            Assert.NotNull(propInfo);
            Assert.Equal(typeof(ActorNode), propInfo.PropertyType);
            Assert.Equal("Actor", propInfo.Name);
        }
Esempio n. 18
0
        public void UserSetExactRTypes_RTypes()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var testTypes = new List <string> {
                "Test", "Relationship"
            };

            var pattern = builder.Pattern <MovieNode, MovieExtraNode>("Lagos", RelationshipDirection.Incoming)
                          .Label(null, testTypes, null, false, true,
                                 false) //replaceR ensures that no other values except the ones supplied is used.
                          .Pattern as Pattern;

            var rTypes = pattern.RTypes;

            Assert.NotNull(rTypes);
            Assert.Equal(2, rTypes.Count());
            Assert.Equal(testTypes, rTypes);
        }
Esempio n. 19
0
        public void ABTypes_ABSelector()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            //(A:Movie)-[r]-(B:Director)
            var pattern = builder.Pattern <MovieNode, DirectorNode>("A", "B").Pattern as Pattern;

            var abSelector = pattern.ABSelector;

            Assert.NotNull(abSelector);
            Assert.Equal("A", abSelector.Parameters[0].Name);

            var propInfo =
                Utils.Utilities.GetPropertyInfoFrom(abSelector.Body, typeof(MovieNode), typeof(DirectorNode));

            Assert.NotNull(propInfo);
            Assert.Equal(typeof(DirectorNode), propInfo.PropertyType);
            Assert.Equal("Director", propInfo.Name);
        }
Esempio n. 20
0
        public void UserSetRTypes_RTypes()
        {
            var testContext = new ResolverTestContext();
            var query       = testContext.Query;

            var builder = new PathBuilder(query);

            var testTypes = new List <string> {
                "Test", "Relationship"
            };

            var pattern = builder.Pattern <MovieNode, MovieExtraNode>("Lagos", RelationshipDirection.Incoming)
                          .Label(null, testTypes, null)
                          .Pattern as Pattern;

            var rTypes = pattern.RTypes;

            Assert.NotNull(rTypes);
            Assert.Equal(3, rTypes.Count());

            testTypes.Add("Movies");
            Assert.Equal(testTypes, rTypes);
        }