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); }
public void AddItemToEndedPath() { IWeaverPath p = NewPath(); p.AddItem(new PathEnder()); WeaverTestUtil.CheckThrows <WeaverPathException>(true, () => p.AddItem(new Candy())); }
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); }
public void TypeGroupOfErrId() { Exception e = WeaverTestUtil.CheckThrows <WeaverException>(true, () => vGraph.TypeGroupOf <TestVertex>(1)); Assert.True(e.Message.Contains("greater than"), "Incorrect exception."); }
public void FinalizeQueryTwiceFail() { var q = new WeaverQuery(); q.FinalizeQuery("1"); WeaverTestUtil.CheckThrows <WeaverException>(true, () => q.FinalizeQuery("2")); }
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); }
public void MakeVertexPropertyErrType() { Exception e = WeaverTestUtil.CheckThrows <WeaverException>(true, () => vGraph.MakeVertexPropertyKey <NullableProp>(x => x.NonTitanAttribute)); Assert.AreEqual(0, e.Message.IndexOf("Property"), "Incorrect exception."); }
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); }
public void TypeGroupOfErrType() { Exception e = WeaverTestUtil.CheckThrows <WeaverException>(true, () => vGraph.TypeGroupOf <TestVertex>(2)); Assert.AreEqual(0, e.Message.IndexOf("Type"), "Incorrect exception."); }
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); }
public void BuildParameterizedStringInvalid() { var remProp = new WeaverStatementRemoveProperty <Person>(x => (x.PersonId == 99)); WeaverTestUtil.CheckThrows <WeaverStatementException <Person> >( true, () => remProp.BuildParameterizedString(vMockPath.Object) ); }
public void ConnectionAlreadSet() { var r = new RootHasCandy(WeaverEdgeConn.OutOne); WeaverTestUtil.CheckThrows <WeaverEdgeException>(true, () => { r.Connection = WeaverEdgeConn.OutOneOrMore; }); }
public void ConnectionNotSet() { var r = new RootHasCandy(); WeaverTestUtil.CheckThrows <WeaverEdgeException>(true, () => { var c = r.Connection; }); }
public void PathIndexFail() { var candy = new Candy(); WeaverTestUtil.CheckThrows <WeaverException>(true, () => { var i = candy.PathIndex; }); }
public void ItemAtIndexBounds(int pIndex) { IWeaverPath p = NewPath(3); WeaverTestUtil.CheckThrows <WeaverPathException>(true, () => p.ItemAtIndex(pIndex) ); }
public void PathFromIndexBounds(int pIndex, bool pInclusive, bool pThrows) { IWeaverPath p = NewPath(3); WeaverTestUtil.CheckThrows <WeaverPathException>(pThrows, () => p.PathFromIndex(pIndex, pInclusive) ); }
public void InVertexConnFail() { var rs = new WeaverEdgeSchema(null, "TestDoesPass", "TDP", "Does", null); WeaverTestUtil.CheckThrows <WeaverException>(true, () => rs.InVertexConn = WeaverEdgeConn.OutOne ); }
public void PropertyNameInvalid() { vFuncProp = new WeaverStepProp <Person>(n => (n.PersonId == 99)); vFuncProp.Path = vMockPath.Object; WeaverTestUtil.CheckThrows <WeaverStepException>(true, () => { var p = vFuncProp.PropertyName; }); }
public void IndexNameInvalid() { vKeyIndex = new WeaverStepExactIndex <Person>(n => (n.PersonId == 99), 1); vKeyIndex.Path = vMockPath.Object; WeaverTestUtil.CheckThrows <WeaverStepException>(true, () => { var p = vKeyIndex.IndexName; }); }
public void StoreResultAsVarNotFinalized() { var q = new WeaverQuery(); IWeaverVarAlias alias; WeaverTestUtil.CheckThrows <WeaverException>( true, () => WeaverQuery.StoreResultAsVar("x", q, out alias) ); }
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); }
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); }
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); }
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); }
public void AddQueryFinished() { IWeaverQuery wq = GetBasicQuery(); var tx = new WeaverTransaction(); tx.AddQuery(wq); tx.Finish(); WeaverTestUtil.CheckThrows <WeaverException>(true, () => tx.AddQuery(wq)); }
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); }); }
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; }); }
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); }
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); }
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); }