Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
            }
        }