public void GetDirectDependencies_Empty() { var conceptInfo = new SimpleConceptInfo("s", "d"); var dependencies = conceptInfo.GetDirectDependencies(); Assert.AreEqual("()", Dump(dependencies)); }
public void ParseTest() { var simpleParser = new GenericParserHelper <SimpleConceptInfo>("module"); SimpleConceptInfo ci = simpleParser.QuickParse("module Wholesale"); Assert.AreEqual("Wholesale", ci.Name); }
public void GetErrorDescription() { var simpleConceptInfo = new SimpleConceptInfo { Name = "s", Data = "d" }; var refConceptInfo = new RefConceptInfo { Name = "r", Reference = simpleConceptInfo }; var refRefConceptInfo = new RefRefConceptInfo { Name = "rr", Reference = refConceptInfo }; Assert.AreEqual("Rhetos.Dsl.Test.ConceptInfoHelperTest+RefRefConceptInfo Name=rr Reference=r.s", refRefConceptInfo.GetErrorDescription()); refRefConceptInfo.Name = null; Assert.AreEqual("Rhetos.Dsl.Test.ConceptInfoHelperTest+RefRefConceptInfo Name=<null> Reference=r.s", refRefConceptInfo.GetErrorDescription()); refRefConceptInfo.Name = "rr"; refRefConceptInfo.Reference = null; Assert.AreEqual("Rhetos.Dsl.Test.ConceptInfoHelperTest+RefRefConceptInfo Name=rr Reference=<null>", refRefConceptInfo.GetErrorDescription()); refRefConceptInfo.Reference = refConceptInfo; simpleConceptInfo.Name = null; TestUtility.AssertContains(refRefConceptInfo.GetErrorDescription(), new[] { refRefConceptInfo.GetType().FullName, "Name=rr", "Reference=", "null" }); simpleConceptInfo.Name = "s"; Assert.AreEqual("<null>", ConceptInfoHelper.GetErrorDescription(null)); Assert.AreEqual(typeof(SimpleConceptInfo).FullName + " Name=s Data=<null>", new SimpleConceptInfo { Name = "s", Data = null }.GetErrorDescription()); }
public void ParseKeywordCaseInsensitive() { var simpleParser = new GenericParserHelper <SimpleConceptInfo>("simple"); SimpleConceptInfo ci = simpleParser.QuickParse("SIMple abc"); Assert.AreEqual("abc", ci.Name); }
public void ParsePosition() { var simpleParser = new GenericParserHelper <SimpleConceptInfo>("abc"); var tokenReader = TestTokenReader("simple abc def", 1); SimpleConceptInfo ci = (SimpleConceptInfo)simpleParser.Parse(tokenReader, new Stack <IConceptInfo>()).Value; Assert.AreEqual("def", ci.Name); TestUtility.AssertContains(tokenReader.ReportPosition(), "column 15,"); }
public void GetDirectDependencies_NotRecursive() { var simpleConceptInfo = new SimpleConceptInfo("s", "d"); var refConceptInfo = new RefConceptInfo("r", simpleConceptInfo); var refRefConceptInfo = new RefRefConceptInfo("rr", refConceptInfo); var dependencies = refRefConceptInfo.GetDirectDependencies(); Assert.AreEqual(Dump(new IConceptInfo[] { refConceptInfo }), Dump(dependencies)); }
public void ParsePosition() { var simpleParser = new GenericParserHelper <SimpleConceptInfo>("abc"); var tokenReader = TestTokenReader("simple abc def", 1); var node = simpleParser.GenericParser.Parse(tokenReader, new Stack <ConceptSyntaxNode>(), out var warnings).Value; SimpleConceptInfo ci = (SimpleConceptInfo)ConceptInfoHelper.ConvertNodeToConceptInfo(node); Assert.AreEqual("def", ci.Name); TestUtility.AssertContains(tokenReader.ReportPosition(), "column 15,"); }
public void GetAllDependencies_Recursive() { var simpleConceptInfo = new SimpleConceptInfo("s", "d"); var refConceptInfo = new RefConceptInfo("r", simpleConceptInfo); var refRefConceptInfo = new RefRefConceptInfo("rr", refConceptInfo); var dependencies = refRefConceptInfo.GetAllDependencies(); Assert.AreEqual(Dump(new IConceptInfo[] { simpleConceptInfo, refConceptInfo }), Dump(dependencies)); }
public void ParseEnclosedInlineError() { var enclosedParser = new GenericParserHelper <EnclosedConceptInfoLevel2>("enclosedlevel2"); var root = new SimpleConceptInfo { Name = "a" }; TestUtility.ShouldFail <InvalidOperationException>( () => enclosedParser.QuickParse("enclosedlevel2 a b c"), "\".\""); }
public void ParseEnclosedPartiallyInline() { var enclosedParser = new GenericParserHelper <EnclosedConceptInfoLevel2>("enclosedlevel2"); var root = new SimpleConceptInfo { Name = "a" }; EnclosedConceptInfoLevel2 ci = enclosedParser.QuickParse("enclosedlevel2 b.c", root); Assert.AreEqual("a", ci.Parent.Parent.Name); Assert.AreEqual("b", ci.Parent.Name); Assert.AreEqual("c", ci.Name); }
public void InterfaceReference_Enclosed() { var parent = new SimpleConceptInfo { Name = "parent" }; string dsl = "intref data"; var parsedConcept = new GenericParserHelper <InterfaceReferenceConceptInfo>("intref").QuickParse(dsl, parent); Assert.AreEqual(typeof(SimpleConceptInfo), parsedConcept.Referece.GetType()); Assert.AreEqual("parent", ((SimpleConceptInfo)parsedConcept.Referece).Name); Assert.AreEqual("data", parsedConcept.Data); }
public void ParseEnclosedSinglePropertyConcept() { var parent = new SimpleConceptInfo { Name = "parent" }; var enclosed1 = new EnclosedSingleProperty1 { Parent = parent }; var enclosed2 = new EnclosedSingleProperty2 { Parent = enclosed1 }; { // simple parent { enclosed1; } var context = new Stack <IConceptInfo>(new[] { parent }); var parser = new GenericParserHelper <EnclosedSingleProperty1>("enclosed1"); var ci = parser.QuickParse("enclosed1", context); Assert.AreEqual("parent", ci.Parent.Name); } { // simple parent; enclosed1 parent; var context = new Stack <IConceptInfo>(); var parser = new GenericParserHelper <EnclosedSingleProperty1>("enclosed1"); var ci = parser.QuickParse("enclosed1 parent", context); Assert.AreEqual("parent", ci.Parent.Name); } { // simple parent { enclosed1 { enclosed2; } } var context = new Stack <IConceptInfo>(new IConceptInfo[] { parent, enclosed1 }); var parser = new GenericParserHelper <EnclosedSingleProperty2>("enclosed2"); var ci = parser.QuickParse("enclosed2", context); Assert.AreEqual("parent", ci.Parent.Parent.Name); } { // simple parent { enclosed1; enclosed2; } var context = new Stack <IConceptInfo>(new[] { parent }); var parser = new GenericParserHelper <EnclosedSingleProperty2>("enclosed2"); TestUtility.ShouldFail(() => parser.QuickParse("enclosed2", context), "EnclosedSingleProperty2 must be enclosed within the referenced parent concept EnclosedSingleProperty1"); } { // simple parent { enclosed1; } enclosed2 parent; var context = new Stack <IConceptInfo>(); var parser = new GenericParserHelper <EnclosedSingleProperty2>("enclosed2"); TestUtility.ShouldFail(() => parser.QuickParse("enclosed2 parent", context), "EnclosedSingleProperty2 must be enclosed within the referenced parent concept EnclosedSingleProperty1"); } }
public void GenerateDependenciesTest() { var dependent = new SimpleConceptInfo("dd"); dependent.GetKeyProperties(); var existingConcepts = new DslModelMock { new EntityInfo { Module = new ModuleInfo { Name = "a" }, Name = "b" }, new DataStructureInfo { Module = new ModuleInfo { Name = "c" }, Name = "d" }, new SqlViewInfo { Module = new ModuleInfo { Name = "e" }, Name = "f" }, new SqlFunctionInfo { Module = new ModuleInfo { Name = "g" }, Name = "h" }, }; var tests = new Dictionary <string, string> { { "select a.b from c.d, x.y", "SqlDependsOnDataStructureInfo c.d" }, { "select * from a.b, c.d, e.f, g.h", "SqlDependsOnDataStructureInfo a.b, SqlDependsOnDataStructureInfo c.d, " + "SqlDependsOnSqlViewInfo e.f, SqlDependsOnSqlFunctionInfo g.h" }, { "with x.y as (select * from a.b) select * from x.y", "SqlDependsOnDataStructureInfo a.b" } }; foreach (var test in tests) { Console.WriteLine("Test: " + test.Key); var dependencies = SqlAnalysis.GenerateDependencies(dependent, existingConcepts, test.Key); foreach (dynamic dependency in dependencies) { Assert.AreEqual("dd", dependency.Dependent.ToString()); } var actual = TestUtility.Dump(dependencies, dep => dep.GetType().Name + " " + ConceptInfoHelper.GetKeyProperties(((dynamic)dep).DependsOn)); Assert.AreEqual(test.Value, actual, "Input: " + test.Key); } }
public void ParseNotEnoughParametersInSingleConceptDescription() { try { var simpleParser = new GenericParserHelper <SimpleConceptInfo>("module"); SimpleConceptInfo ci = simpleParser.QuickParse("module { entiti e }"); } catch (Exception ex) { Console.WriteLine(ex.Message); Assert.IsTrue(ex.Message.Contains("SimpleConceptInfo"), "Concept type."); Assert.IsTrue(ex.Message.Contains("Special"), "Unexpected special token while reading text."); Assert.IsTrue(ex.Message.Contains("{"), "Unexpected special token '{' while reading text."); Assert.IsTrue(ex.Message.Contains("quotes"), "Use quotes to specify text (e.g. '{')"); throw; } }
public void SortReferencesBeforeUsingConceptTest() { var c1 = new SimpleConceptInfo { Name = "n1", Data = "" }; var c2 = new RefConceptInfo { Name = "n2", Reference = c1 }; List <IConceptInfo> concepts = new List <IConceptInfo>() { c2, c1 }; concepts = DslModelFromConcepts(concepts); Assert.AreEqual(2, concepts.Count); Assert.AreEqual(c1, concepts[0]); Assert.AreEqual(c2, concepts[1]); }
public void SortReferencesBeforeUsingConceptTest() { var c2 = new SimpleConceptInfo { Name = "n1", Data = "" }; var c1 = new RefConceptInfo { Name = "n2", Reference = c2 }; var concepts = new List <IConceptInfo>() { c1, c2 }; var concepts2 = DslModelFromConcepts(concepts); Assert.AreEqual( "REF n2.n1, SIMPLE n1", TestUtility.Dump(concepts, c => c is InitializationConcept ? "InitializationConcept" : c.GetUserDescription())); Assert.AreEqual( "InitializationConcept, SIMPLE n1, REF n2.n1", TestUtility.Dump(concepts2, c => c is InitializationConcept ? "InitializationConcept" : c.GetUserDescription())); }
public void GenerateDependenciesTestToObject() { var dependent = new SimpleConceptInfo("dd"); dependent.GetKeyProperties(); var existingConcepts = new DslModelMock { new EntityInfo { Module = new ModuleInfo { Name = "a" }, Name = "b" }, new DataStructureInfo { Module = new ModuleInfo { Name = "c" }, Name = "d" }, new SqlViewInfo { Module = new ModuleInfo { Name = "e" }, Name = "f" }, new SqlFunctionInfo { Module = new ModuleInfo { Name = "g" }, Name = "h" }, new EntityInfo { Module = new ModuleInfo { Name = "x" }, Name = "y" }, new SqlViewInfo { Module = new ModuleInfo { Name = "x" }, Name = "y" }, new SqlFunctionInfo { Module = new ModuleInfo { Name = "x" }, Name = "y" }, }; var tests = new Dictionary <string, string> { { "a.a", "" }, { "b.b", "" }, { "a.b.a", "" }, { "a.a.b", "" }, { "a", "" }, { "b", "" }, { "a.b", "SqlDependsOnDataStructureInfo a.b" }, { "c.d", "SqlDependsOnDataStructureInfo c.d" }, { "e.f", "SqlDependsOnSqlViewInfo e.f" }, { "g.h", "" }, { "g.h(SYSDATETIME())", "SqlDependsOnSqlFunctionInfo g.h" }, { "x.y(SYSDATETIME())", "SqlDependsOnSqlFunctionInfo x.y" }, { "x.y", "SqlDependsOnDataStructureInfo x.y, SqlDependsOnSqlViewInfo x.y" }, }; foreach (var test in tests) { Console.WriteLine("Test: " + test.Key); var dependencies = SqlAnalysis.GenerateDependenciesToObject(dependent, existingConcepts, test.Key); foreach (dynamic dependency in dependencies) { Assert.AreEqual("dd", dependency.Dependent.ToString()); } var actual = TestUtility.Dump(dependencies, dep => dep.GetType().Name + " " + ConceptInfoHelper.GetKeyProperties(((dynamic)dep).DependsOn)); Assert.AreEqual(test.Value, actual, "Input: " + test.Key); } }
public void GenerateDependenciesTestToObject() { var dependent = new SimpleConceptInfo("dd"); dependent.GetKeyProperties(); var existingConcepts = new IConceptInfo[] { new EntityInfo { Module = new ModuleInfo { Name = "a" }, Name = "b" }, new DataStructureInfo { Module = new ModuleInfo { Name = "c" }, Name = "d" }, new SqlViewInfo { Module = new ModuleInfo { Name = "e" }, Name = "f" }, new SqlFunctionInfo { Module = new ModuleInfo { Name = "g" }, Name = "h" }, new EntityInfo { Module = new ModuleInfo { Name = "x" }, Name = "y" }, new SqlViewInfo { Module = new ModuleInfo { Name = "x" }, Name = "y" }, new SqlFunctionInfo { Module = new ModuleInfo { Name = "x" }, Name = "y" },}; var tests = new Dictionary<string, string> { { "a.a", "" }, { "b.b", "" }, { "a.b.a", "" }, { "a.a.b", "" }, { "a", "" }, { "b", "" }, { "a.b", "SqlDependsOnDataStructureInfo a.b" }, { "c.d", "SqlDependsOnDataStructureInfo c.d" }, { "e.f", "SqlDependsOnSqlViewInfo e.f" }, { "g.h", "" }, { "g.h(GETDATE())", "SqlDependsOnSqlFunctionInfo g.h" }, { "x.y(GETDATE())", "SqlDependsOnSqlFunctionInfo x.y" }, { "x.y", "SqlDependsOnDataStructureInfo x.y, SqlDependsOnSqlViewInfo x.y" }, }; foreach (var test in tests) { Console.WriteLine("Test: " + test.Key); var dependencies = SqlAnalysis.GenerateDependenciesToObject(dependent, existingConcepts, test.Key); foreach (dynamic dependency in dependencies) Assert.AreEqual("dd", dependency.Dependent.ToString()); var actual = TestUtility.Dump(dependencies, dep => dep.GetType().Name + " " + ConceptInfoHelper.GetKeyProperties(((dynamic)dep).DependsOn)); Assert.AreEqual(test.Value, actual, "Input: " + test.Key); } }
public RefConceptInfo(string name, SimpleConceptInfo reference) { Name = name; Reference = reference; }
public void SortReferencesBeforeUsingConceptTest() { var c1 = new SimpleConceptInfo { Name = "n1", Data = "" }; var c2 = new RefConceptInfo { Name = "n2", Reference = c1 }; List<IConceptInfo> concepts = new List<IConceptInfo>() { c2, c1 }; concepts = DslModelFromConcepts(concepts); Assert.AreEqual(2, concepts.Count); Assert.AreEqual(c1, concepts[0]); Assert.AreEqual(c2, concepts[1]); }
public void GenerateDependenciesTest() { var dependent = new SimpleConceptInfo("dd"); dependent.GetKeyProperties(); var existingConcepts = new DslModelMock { new EntityInfo { Module = new ModuleInfo { Name = "a" }, Name = "b" }, new DataStructureInfo { Module = new ModuleInfo { Name = "c" }, Name = "d" }, new SqlViewInfo { Module = new ModuleInfo { Name = "e" }, Name = "f" }, new SqlFunctionInfo { Module = new ModuleInfo { Name = "g" }, Name = "h" }, }; var tests = new Dictionary<string, string> { { "select a.b from c.d, x.y", "SqlDependsOnDataStructureInfo c.d" }, { "select * from a.b, c.d, e.f, g.h", "SqlDependsOnDataStructureInfo a.b, SqlDependsOnDataStructureInfo c.d, " + "SqlDependsOnSqlViewInfo e.f, SqlDependsOnSqlFunctionInfo g.h" } }; foreach (var test in tests) { Console.WriteLine("Test: " + test.Key); var dependencies = SqlAnalysis.GenerateDependencies(dependent, existingConcepts, test.Key); foreach (dynamic dependency in dependencies) Assert.AreEqual("dd", dependency.Dependent.ToString()); var actual = TestUtility.Dump(dependencies, dep => dep.GetType().Name + " " + ConceptInfoHelper.GetKeyProperties(((dynamic)dep).DependsOn)); Assert.AreEqual(test.Value, actual, "Input: " + test.Key); } }