示例#1
0
        public void AddEdge()
        {
            var plc = new PersonLikesCandy();

            plc.Enjoyment  = 0.84f;
            plc.TimesEaten = 54;
            plc.Notes      = "Tastes great!";

            const string perId   = "a99";
            const string candyId = "x1234";

            var person = new Person {
                Id = perId
            };
            var candy = new Candy {
                Id = candyId
            };

            IWeaverQuery q = vGraph.AddEdge(person, plc, candy);

            int bracketI      = q.Script.IndexOf('[');
            int bracketIClose = q.Script.LastIndexOf(']');

            Assert.True(q.IsFinalized, "Incorrect IsFinalized.");
            Assert.NotNull(q.Script, "Script should be filled.");
            Assert.AreEqual("g.addEdge(g.v(_P0),g.v(_P1),_P2,[",
                            q.Script.Substring(0, bracketI + 1), "Incorrect starting code.");
            Assert.AreEqual("]);", q.Script.Substring(bracketIClose), "Incorrect ending code.");

            ////

            string vals = q.Script.Substring(bracketI + 1, bracketIClose - bracketI - 1);
            Dictionary <string, string> pairMap = WeaverTestUtil.GetPropListDictionary(vals);

            Assert.AreEqual(3, pairMap.Keys.Count, "Incorrect Key count.");

            Assert.True(pairMap.ContainsKey(TestSchema.PersonLikesCandy_TimesEaten),
                        "Missing TimesEaten key.");
            Assert.True(pairMap.ContainsKey(TestSchema.PersonLikesCandy_Enjoyment),
                        "Missing Enjoyment key.");
            Assert.True(pairMap.ContainsKey(TestSchema.PersonLikesCandy_Notes),
                        "Missing Notes key.");

            Assert.AreEqual("_P3", pairMap[TestSchema.PersonLikesCandy_TimesEaten],
                            "Incorrect TimesEaten value.");
            Assert.AreEqual("_P4", pairMap[TestSchema.PersonLikesCandy_Enjoyment],
                            "Incorrect Enjoyment value.");
            Assert.AreEqual("_P5", pairMap[TestSchema.PersonLikesCandy_Notes],
                            "Incorrect Notes value.");

            var expectParams = new Dictionary <string, IWeaverQueryVal>();

            expectParams.Add("_P0", new WeaverQueryVal(person.Id));
            expectParams.Add("_P1", new WeaverQueryVal(candy.Id));
            expectParams.Add("_P2", new WeaverQueryVal(TestSchema.PersonLikesCandy));
            expectParams.Add("_P3", new WeaverQueryVal(plc.TimesEaten));
            expectParams.Add("_P4", new WeaverQueryVal(plc.Enjoyment));
            expectParams.Add("_P5", new WeaverQueryVal(plc.Notes));
            WeaverTestUtil.CheckQueryParamsOriginalVal(q, expectParams);
        }
示例#2
0
        public void AddItemToEndedPath()
        {
            IWeaverPath p = NewPath();

            p.AddItem(new PathEnder());
            WeaverTestUtil.CheckThrows <WeaverPathException>(true, () => p.AddItem(new Candy()));
        }
示例#3
0
        public void AddEdgeVciNoProps()
        {
            vMockPath.SetupGet(x => x.Query).Returns(new WeaverQuery());             //should mock this

            var ehe = new EmptyHasEmpty();
            var e1  = new Empty {
                Id = "V0"
            };
            var e2 = new Empty {
                Id = "eee99"
            };

            IWeaverQuery q = vGraph.AddEdgeVci(e1, ehe, e2);

            const string expect =
                "_A=g.v(_P0);" +
                "_B=g.v(_P1);" +
                "g.addEdge(_A,_B,_P2);";

            Assert.True(q.IsFinalized, "Incorrect IsFinalized.");
            Assert.NotNull(q.Script, "Script should be filled.");
            Assert.AreEqual(expect, q.Script, "Incorrect Script.");

            var expectParams = new Dictionary <string, IWeaverQueryVal>();

            expectParams.Add("_P0", new WeaverQueryVal(e1.Id));
            expectParams.Add("_P1", new WeaverQueryVal(e2.Id));
            expectParams.Add("_P2", new WeaverQueryVal("EHE"));
            WeaverTestUtil.CheckQueryParamsOriginalVal(q, expectParams);
        }
示例#4
0
        public void TypeGroupOfErrId()
        {
            Exception e = WeaverTestUtil.CheckThrows <WeaverException>(true,
                                                                       () => vGraph.TypeGroupOf <TestVertex>(1));

            Assert.True(e.Message.Contains("greater than"), "Incorrect exception.");
        }
示例#5
0
        public void FinalizeQueryTwiceFail()
        {
            var q = new WeaverQuery();

            q.FinalizeQuery("1");
            WeaverTestUtil.CheckThrows <WeaverException>(true, () => q.FinalizeQuery("2"));
        }
示例#6
0
        public void AddEdgeVciVarNoProps()
        {
            vMockPath.SetupGet(x => x.Query).Returns(new WeaverQuery());             //should mock this

            var          ehe        = new EmptyHasEmpty();
            const string outVarName = "_var0";
            const string inVarName  = "_var1";

            var mockOutVar = new Mock <IWeaverVarAlias>();

            mockOutVar.SetupGet(x => x.Name).Returns(outVarName);
            mockOutVar.SetupGet(x => x.VarType).Returns(typeof(Empty));

            var mockInVar = new Mock <IWeaverVarAlias>();

            mockInVar.SetupGet(x => x.Name).Returns(inVarName);
            mockInVar.SetupGet(x => x.VarType).Returns(typeof(Empty));

            IWeaverQuery q = vGraph.AddEdgeVci(mockOutVar.Object, ehe, mockInVar.Object);

            const string expect = "g.addEdge(" + outVarName + "," + inVarName + ",_P0);";

            Assert.True(q.IsFinalized, "Incorrect IsFinalized.");
            Assert.NotNull(q.Script, "Script should be filled.");
            Assert.AreEqual(expect, q.Script, "Incorrect Script.");

            var expectParams = new Dictionary <string, IWeaverQueryVal>();

            expectParams.Add("_P0", new WeaverQueryVal("EHE"));
            WeaverTestUtil.CheckQueryParamsOriginalVal(q, expectParams);
        }
示例#7
0
        public void MakeVertexPropertyErrType()
        {
            Exception e = WeaverTestUtil.CheckThrows <WeaverException>(true,
                                                                       () => vGraph.MakeVertexPropertyKey <NullableProp>(x => x.NonTitanAttribute));

            Assert.AreEqual(0, e.Message.IndexOf("Property"), "Incorrect exception.");
        }
示例#8
0
        public void ComplexPath()
        {
            IWeaverStepAs <Person> personAlias;

            IWeaverQuery q = WeavInst.Graph.V.ExactIndex <Root>(x => x.Id, 0)
                             .OutHasPerson.InVertex
                             .Has(x => x.PersonId, WeaverStepHasOp.EqualTo, 22)
                             .Has(x => x.Name, WeaverStepHasOp.EqualTo, "test")
                             .As(out personAlias)
                             .OutLikesCandy.InVertex
                             .Back(personAlias)
                             .ToQuery();

            const string expect = "g.V('id',_P0)" +
                                  ".outE('" + TestSchema.RootHasPerson + "').inV" +
                                  ".has('" + TestSchema.Person_PersonId + "',Tokens.T.eq,_P1)" +
                                  ".has('" + TestSchema.Vertex_Name + "',Tokens.T.eq,_P2)" +
                                  ".as('step7')" +
                                  ".outE('" + TestSchema.PersonLikesCandy + "').inV" +
                                  ".back('step7');";

            Assert.AreEqual(expect, q.Script, "Incorrect Query.Script.");

            var expectParams = new Dictionary <string, IWeaverQueryVal>();

            expectParams.Add("_P0", new WeaverQueryVal(0));
            expectParams.Add("_P1", new WeaverQueryVal(22));
            expectParams.Add("_P2", new WeaverQueryVal("test"));
            WeaverTestUtil.CheckQueryParamsOriginalVal(q, expectParams);
        }
示例#9
0
        public void TypeGroupOfErrType()
        {
            Exception e = WeaverTestUtil.CheckThrows <WeaverException>(true,
                                                                       () => vGraph.TypeGroupOf <TestVertex>(2));

            Assert.AreEqual(0, e.Message.IndexOf("Type"), "Incorrect exception.");
        }
示例#10
0
        public void AddEdgeVarNoProps()
        {
            var          rhp        = new RootHasPerson();
            const string outVarName = "_var0";
            const string inVarName  = "_var1";

            var mockOutVar = new Mock <IWeaverVarAlias>();

            mockOutVar.SetupGet(x => x.Name).Returns(outVarName);
            mockOutVar.SetupGet(x => x.VarType).Returns(typeof(Root));

            var mockInVar = new Mock <IWeaverVarAlias>();

            mockInVar.SetupGet(x => x.Name).Returns(inVarName);
            mockInVar.SetupGet(x => x.VarType).Returns(typeof(Person));

            IWeaverQuery q = vGraph.AddEdge(mockOutVar.Object, rhp, mockInVar.Object);

            Assert.True(q.IsFinalized, "Incorrect IsFinalized.");
            Assert.NotNull(q.Script, "Script should be filled.");
            Assert.AreEqual(q.Script, "g.addEdge(" + outVarName + "," + inVarName + ",_P0);",
                            "Incorrect Script.");

            var expectParams = new Dictionary <string, IWeaverQueryVal>();

            expectParams.Add("_P0", new WeaverQueryVal(TestSchema.RootHasPerson));
            WeaverTestUtil.CheckQueryParamsOriginalVal(q, expectParams);
        }
示例#11
0
        public void BuildParameterizedStringInvalid()
        {
            var remProp = new WeaverStatementRemoveProperty <Person>(x => (x.PersonId == 99));

            WeaverTestUtil.CheckThrows <WeaverStatementException <Person> >(
                true, () => remProp.BuildParameterizedString(vMockPath.Object)
                );
        }
示例#12
0
        public void ConnectionAlreadSet()
        {
            var r = new RootHasCandy(WeaverEdgeConn.OutOne);

            WeaverTestUtil.CheckThrows <WeaverEdgeException>(true, () => {
                r.Connection = WeaverEdgeConn.OutOneOrMore;
            });
        }
示例#13
0
        public void ConnectionNotSet()
        {
            var r = new RootHasCandy();

            WeaverTestUtil.CheckThrows <WeaverEdgeException>(true, () => {
                var c = r.Connection;
            });
        }
示例#14
0
        public void PathIndexFail()
        {
            var candy = new Candy();

            WeaverTestUtil.CheckThrows <WeaverException>(true, () => {
                var i = candy.PathIndex;
            });
        }
示例#15
0
        public void ItemAtIndexBounds(int pIndex)
        {
            IWeaverPath p = NewPath(3);

            WeaverTestUtil.CheckThrows <WeaverPathException>(true,
                                                             () => p.ItemAtIndex(pIndex)
                                                             );
        }
示例#16
0
        public void PathFromIndexBounds(int pIndex, bool pInclusive, bool pThrows)
        {
            IWeaverPath p = NewPath(3);

            WeaverTestUtil.CheckThrows <WeaverPathException>(pThrows,
                                                             () => p.PathFromIndex(pIndex, pInclusive)
                                                             );
        }
示例#17
0
        public void InVertexConnFail()
        {
            var rs = new WeaverEdgeSchema(null, "TestDoesPass", "TDP", "Does", null);

            WeaverTestUtil.CheckThrows <WeaverException>(true,
                                                         () => rs.InVertexConn = WeaverEdgeConn.OutOne
                                                         );
        }
示例#18
0
        public void PropertyNameInvalid()
        {
            vFuncProp      = new WeaverStepProp <Person>(n => (n.PersonId == 99));
            vFuncProp.Path = vMockPath.Object;

            WeaverTestUtil.CheckThrows <WeaverStepException>(true, () => {
                var p = vFuncProp.PropertyName;
            });
        }
示例#19
0
        public void IndexNameInvalid()
        {
            vKeyIndex      = new WeaverStepExactIndex <Person>(n => (n.PersonId == 99), 1);
            vKeyIndex.Path = vMockPath.Object;

            WeaverTestUtil.CheckThrows <WeaverStepException>(true, () => {
                var p = vKeyIndex.IndexName;
            });
        }
示例#20
0
        public void StoreResultAsVarNotFinalized()
        {
            var             q = new WeaverQuery();
            IWeaverVarAlias alias;

            WeaverTestUtil.CheckThrows <WeaverException>(
                true, () => WeaverQuery.StoreResultAsVar("x", q, out alias)
                );
        }
示例#21
0
        public void HasInvalidVertex(HasStepType pStepType)
        {
            Exception e = WeaverTestUtil.CheckThrows <WeaverException>(true, () =>
                                                                       DoHasStep <OneKnowsTwo, Person>(pStepType, x => x.Name));

            bool correct = (e.Message.Contains(typeof(Person).Name) &&
                            e.Message.Contains(typeof(WeaverTitanVertexAttribute).Name));

            Assert.True(correct, "Incorrect exception: " + e);
        }
示例#22
0
        public void HasNonVciProperty(HasStepType pStepType)
        {
            Exception e = WeaverTestUtil.CheckThrows <WeaverException>(true, () =>
                                                                       DoHasStep <OneKnowsTwo, One>(pStepType, x => x.B));

            bool correct = (e.Message.Contains(typeof(OneKnowsTwo).Name) &&
                            e.Message.Contains(typeof(One).Name + ".B"));

            Assert.True(correct, "Incorrect exception: " + e);
        }
示例#23
0
        public void HasInvalidVertexType(HasStepType pStepType)
        {
            Exception e = WeaverTestUtil.CheckThrows <WeaverException>(true, () =>
                                                                       DoHasStep <OneKnowsTwo, NullableProp>(pStepType, x => x.NonTitanAttribute));

            bool correct = (e.Message.Contains(typeof(NullableProp).Name) &&
                            e.Message.Contains("not valid for edge type"));

            Assert.True(correct, "Incorrect exception: " + e);
        }
示例#24
0
        public void HasInvalidProperty(HasStepType pStepType)
        {
            Exception e = WeaverTestUtil.CheckThrows <WeaverException>(true, () =>
                                                                       DoHasStep <OneKnowsThree, Three>(pStepType, x => x.B));

            bool correct = (e.Message.Contains(typeof(WeaverTitanPropertyAttribute).Name) &&
                            e.Message.Contains("B"));

            Assert.True(correct, "Incorrect exception: " + e);
        }
示例#25
0
        public void AddQueryFinished()
        {
            IWeaverQuery wq = GetBasicQuery();

            var tx = new WeaverTransaction();

            tx.AddQuery(wq);
            tx.Finish();
            WeaverTestUtil.CheckThrows <WeaverException>(true, () => tx.AddQuery(wq));
        }
示例#26
0
        public void NotInPath(int pItemIndex)
        {
            var mockAlias = new Mock <IWeaverStepAs <Person> >();

            mockAlias.SetupGet(x => x.PathIndex).Returns(pItemIndex);

            WeaverTestUtil.CheckThrows <WeaverStepException>(true, () => {
                var f = new WeaverStepBack <Person>(mockAlias.Object);
            });
        }
示例#27
0
        public void PropertyNameInvalid()
        {
            vFuncHas = new WeaverStepHas <Person>(n => (n.PersonId == 99), WeaverStepHasMode.Has,
                                                  WeaverStepHasOp.EqualTo, 1);
            vFuncHas.Path = vMockPath.Object;

            WeaverTestUtil.CheckThrows <WeaverStepException>(true, () => {
                var p = vFuncHas.PropertyName;
            });
        }
示例#28
0
        public void VertexById()
        {
            IWeaverQuery q = WeavInst.Graph.V.Id <Person>("123").ToQuery();

            var expectParams = new Dictionary <string, IWeaverQueryVal>();

            expectParams.Add("_P0", new WeaverQueryVal("123"));

            Assert.AreEqual("g.v(_P0);", q.Script, "Incorrect Script.");
            WeaverTestUtil.CheckQueryParamsOriginalVal(q, expectParams);
        }
示例#29
0
        public void ColumnOrder()
        {
            IWeaverStepAs <Person>      nullAlias;
            IWeaverStepAsColumn <Candy> candyPropAppendCol;
            IWeaverStepAsColumn <Candy> candyReplaceCol;
            IWeaverStepAsColumn <Candy> candyAppendCol;
            IWeaverVarAlias             tableAlias;

            var path = WeavInst.Graph
                       .V.ExactIndex <Person>(x => x.PersonId, 123)
                       .AsColumn("PersObj")
                       .As(out nullAlias)
                       .OutLikesCandy.InVertex
                       .AsColumn("CandyId", x => x.CandyId)
                       .AsColumn("CandyCal", x => x.Calories, out candyPropAppendCol)
                       .AsColumn("CandyReplace", out candyReplaceCol)
                       .AsColumn("CandyAppend", out candyAppendCol)
                       .Table(out tableAlias)
                       .Iterate();

            //script adjustments must occur before using ToQuery()
            candyPropAppendCol.AppendScript = ".append.script()";
            candyReplaceCol.ReplaceScript   = "123";
            candyAppendCol.AppendScript     = ".outE.inV";

            IWeaverQuery q = path.ToQuery();

            const string expect =
                "g.V('PerId',_P0)" +
                ".as('PersObj')" +
                ".as('step4')" +
                ".outE('PLC').inV" +
                ".as('CandyId')" +
                ".as('CandyCal')" +
                ".as('CandyReplace')" +
                ".as('CandyAppend')" +
                ".table(_TABLE11=new Table())" +
                "{}" +
                "{it}" +
                "{it.outE.inV}" +
                "{123}" +
                "{it.getProperty(_P1).append.script()}" +
                "{it.getProperty(_P2)}" +
                ".iterate();";

            var expectParams = new Dictionary <string, IWeaverQueryVal>();

            expectParams.Add("_P0", new WeaverQueryVal(123));
            expectParams.Add("_P1", new WeaverQueryVal(TestSchema.Candy_Calories));
            expectParams.Add("_P2", new WeaverQueryVal(TestSchema.Candy_CandyId));

            Assert.AreEqual(expect, q.Script, "Incorrect query script.");
            WeaverTestUtil.CheckQueryParamsOriginalVal(q, expectParams);
        }
示例#30
0
        public void AddVertex()
        {
            var person = new Person();

            person.Id       = "ABC98-765";
            person.PersonId = 1234;
            person.Name     = "Zach K";
            person.Age      = 27.1f;
            person.IsMale   = true;
            person.Note     = null;

            IWeaverQuery q = vGraph.AddVertex(person);

            int bracketI      = q.Script.IndexOf('[');
            int bracketIClose = q.Script.LastIndexOf(']');

            Assert.True(q.IsFinalized, "Incorrect IsFinalized.");
            Assert.NotNull(q.Script, "Script should be filled.");
            Assert.AreEqual("g.addVertex([",
                            q.Script.Substring(0, bracketI + 1), "Incorrect starting code.");
            Assert.AreEqual("]);", q.Script.Substring(bracketIClose), "Incorrect ending code.");

            ////

            string vals = q.Script.Substring(bracketI + 1, bracketIClose - bracketI - 1);
            Dictionary <string, string> pairMap = WeaverTestUtil.GetPropListDictionary(vals);

            Assert.AreEqual(4, pairMap.Keys.Count, "Incorrect Key count.");
            Assert.False(pairMap.ContainsKey("Id"), "Should not include Id key.");
            Assert.True(pairMap.ContainsKey(TestSchema.Person_PersonId), "Missing PersonId key.");
            Assert.True(pairMap.ContainsKey(TestSchema.Vertex_Name), "Missing Name key.");
            Assert.True(pairMap.ContainsKey(TestSchema.Person_Age), "Missing Age key.");
            Assert.True(pairMap.ContainsKey(TestSchema.Person_IsMale), "Missing IsMale key.");
            Assert.False(pairMap.ContainsKey(TestSchema.Person_Note), "Incorrect Note key.");

            int i = -1;

            Assert.AreEqual("_P" + (++i), pairMap[TestSchema.Person_PersonId],
                            "Incorrect PersonId value.");
            Assert.AreEqual("_P" + (++i), pairMap[TestSchema.Person_IsMale], "Incorrect IsMale value.");
            Assert.AreEqual("_P" + (++i), pairMap[TestSchema.Person_Age], "Incorrect Age value.");
            Assert.AreEqual("_P" + (++i), pairMap[TestSchema.Vertex_Name], "Incorrect Name value.");

            i = -1;
            var expectParams = new Dictionary <string, IWeaverQueryVal>();

            expectParams.Add("_P" + (++i), new WeaverQueryVal(person.PersonId));
            expectParams.Add("_P" + (++i), new WeaverQueryVal(person.IsMale));
            expectParams.Add("_P" + (++i), new WeaverQueryVal(person.Age));
            expectParams.Add("_P" + (++i), new WeaverQueryVal(person.Name));

            WeaverTestUtil.CheckQueryParamsOriginalVal(q, expectParams);
        }