Esempio n. 1
0
        public void GetConceptApplicationDependencies_SimpleTest()
        {
            IConceptInfo ci1 = new SimpleCi {
                Name = "1"
            };
            IConceptInfo ci2 = new SimpleCi {
                Name = "2"
            };
            ConceptApplication ca1a = new NewConceptApplication(ci1, new SimpleConceptImplementation())
            {
                CreateQuery = "1a"
            };
            ConceptApplication ca1b = new NewConceptApplication(ci1, new SimpleConceptImplementation())
            {
                CreateQuery = "1b"
            };
            ConceptApplication ca2a = new NewConceptApplication(ci2, new SimpleConceptImplementation())
            {
                CreateQuery = "2a"
            };
            ConceptApplication ca2b = new NewConceptApplication(ci2, new SimpleConceptImplementation())
            {
                CreateQuery = "2b"
            };

            IEnumerable <Tuple <IConceptInfo, IConceptInfo, string> > conceptInfoDependencies = new[] { Tuple.Create(ci2, ci1, "") };

            IEnumerable <Dependency> actual = DatabaseGenerator_Accessor.GetConceptApplicationDependencies(conceptInfoDependencies, new[] { ca1a, ca1b, ca2a, ca2b });

            Assert.AreEqual("2a-1a, 2a-1b, 2b-1a, 2b-1b", String.Join(", ", actual.Select(Dump).OrderBy(s => s)));
        }
Esempio n. 2
0
        public void DatabaseGenerator_NoTransaction()
        {
            var oldApplications = new List <ConceptApplication> {
                BaseCi.CreateApplication("A", new SimpleConceptImplementation()),
                BaseCi.CreateApplication("B", new NoTransactionConceptImplementation()),
                BaseCi.CreateApplication("C", new SimpleConceptImplementation())
            };
            var newApplications = new List <NewConceptApplication> {
                BaseCi.CreateApplication("D", new SimpleConceptImplementation()),
                BaseCi.CreateApplication("E", new NoTransactionConceptImplementation()),
                BaseCi.CreateApplication("F", new SimpleConceptImplementation())
            };

            var sqlExecuter           = new MockSqlExecuter();
            var sqlTransactionBatches = new SqlTransactionBatches(sqlExecuter, new NullConfiguration(), new ConsoleLogProvider());
            var databaseGenerator     = new DatabaseGenerator_Accessor(sqlTransactionBatches);

            databaseGenerator.ApplyChangesToDatabase(oldApplications, newApplications, oldApplications, newApplications);

            var executedSql = TestUtility.Dump(sqlExecuter.executedScriptsWithTransaction, scripts =>
                                               (scripts.Item2 ? "TRAN" : "NOTRAN") + ": " + string.Join(", ", scripts.Item1));

            executedSql = ClearSqlForReport(executedSql);

            Assert.AreEqual(
                "TRAN: remove C, NOTRAN: remove B, TRAN: remove A, create D, NOTRAN: create E, TRAN: create F",
                executedSql);
        }
Esempio n. 3
0
        private static void TestDatabaseGenerator(
            IEnumerable <ConceptApplication> oldApplications,
            IEnumerable <NewConceptApplication> newApplications,
            out List <ConceptApplication> toBeRemoved,
            out List <NewConceptApplication> toBeInserted,
            bool computeDependencies = true)
        {
            var plugins = CreatePluginsContainer(new PluginsMetadataList <IConceptDatabaseDefinition>
            {
                new NullImplementation(),
                new SimpleConceptImplementation(),
                new DependentConceptImplementation()
            });
            var databaseGenerator = new DatabaseGenerator_Accessor(null, plugins);

            if (computeDependencies)
            {
                databaseGenerator.ComputeDependsOn(oldApplications.Cast <NewConceptApplication>());
                databaseGenerator.ComputeDependsOn(newApplications);
            }

            databaseGenerator.CalculateApplicationsToBeRemovedAndInserted(
                oldApplications, newApplications,
                out toBeRemoved, out toBeInserted);
            Graph.TopologicalSort(toBeRemoved, DatabaseGenerator_Accessor.GetDependencyPairs(oldApplications));
            toBeRemoved.Reverse();
            Graph.TopologicalSort(toBeInserted, DatabaseGenerator_Accessor.GetDependencyPairs(newApplications));
        }
Esempio n. 4
0
        public void ExtractCreateQueries_Empty1()
        {
            var sqlCodeBuilder = new CodeBuilder("/*", "*/");

            var toBeInserted = new List <ConceptApplication>();

            DatabaseGenerator_Accessor.ExtractCreateQueries(sqlCodeBuilder.GeneratedCode, toBeInserted);
        }
Esempio n. 5
0
        public void ExtractCreateQueries()
        {
            var sqlCodeBuilder = new CodeBuilder("/*", "*/");

            sqlCodeBuilder.InsertCode("before first");

            var ca1 = new NewConceptApplication(new BaseCi {
                Name = "ci1"
            }, new SimpleConceptImplementation())
            {
                Id          = Guid.NewGuid(),
                CreateQuery = "sql",
                DependsOn   = new ConceptApplicationDependency[] { }
            };

            DatabaseGenerator_Accessor.AddConceptApplicationSeparator(ca1, sqlCodeBuilder);
            const string createQuery1 = "create query 1";

            sqlCodeBuilder.InsertCode(createQuery1);

            var ca2 = new NewConceptApplication(new BaseCi {
                Name = "ci2"
            }, new SimpleConceptImplementation())
            {
                Id          = Guid.NewGuid(),
                CreateQuery = "sql",
                DependsOn   = new ConceptApplicationDependency[] { }
            };

            DatabaseGenerator_Accessor.AddConceptApplicationSeparator(ca2, sqlCodeBuilder);
            const string createQuery2 = "create query 2";

            sqlCodeBuilder.InsertCode(createQuery2);

            var toBeInserted = new List <ConceptApplication> {
                ca1, ca2
            };

            DatabaseGenerator_Accessor.ExtractCreateQueries(sqlCodeBuilder.GeneratedCode, toBeInserted);

            Assert.AreEqual(createQuery1, ca1.CreateQuery);
            Assert.AreEqual(createQuery2, ca2.CreateQuery);
        }
Esempio n. 6
0
        public void CreateNewApplications_MissingMiddleApplications()
        {
            IConceptInfo ci1 = new SimpleCi {
                Name = "1"
            };
            IConceptInfo ci2 = new SimpleCi2 {
                Name = "2"
            };
            IConceptInfo ci3 = new SimpleCi3 {
                Name = "3"
            };

            tempConceptInfoDependencies = new[] { Tuple.Create(ci2, ci1), Tuple.Create(ci3, ci2) };
            // Concept application that implements ci3 should (indirectly) depend on concept application that implements ci1.
            // This test is specific because there is no concept application for ci2, so there is possibility of error when calculating dependencies between concept applications.

            var dslModel = new MockDslModel(new[] { ci1, ci2, ci3 });

            var plugins = CreatePluginsContainer(new PluginsMetadataList <IConceptDatabaseDefinition>
            {
                new NullImplementation(),
                { new SimpleConceptImplementation(), new Dictionary <string, object> {
                      { "Implements", typeof(SimpleCi) }
                  } },
                { new ExtendingConceptImplementation(), new Dictionary <string, object> {
                      { "Implements", typeof(SimpleCi3) }
                  } }
            });

            DatabaseGenerator_Accessor databaseGenerator = new DatabaseGenerator_Accessor(dslModel, plugins);
            var createdApplications = databaseGenerator.CreateNewApplications(new List <ConceptApplication>());

            tempConceptInfoDependencies = null;

            var ca1 = createdApplications.Where(ca => ca.ConceptInfo == ci1).Single();
            var ca3 = createdApplications.Where(ca => ca.ConceptInfo == ci3).Single();

            Assert.IsTrue(DirectAndIndirectDependencies(ca1).Contains(ca3), "Concept application ca3 should be included in direct or indirect dependencies of ca1.");
        }
Esempio n. 7
0
        public void ExtractDependenciesFromConceptInfosTest()
        {
            var a  = BaseCi.CreateApplication("A");
            var b  = BaseCi.CreateApplication("B");
            var c  = BaseCi.CreateApplication("C");
            var r1 = MultipleReferencingCi.CreateApplication("1", a, b);
            var r2 = MultipleReferencingCi.CreateApplication("2", b, c);
            var r3 = MultipleReferencingCi.CreateApplication("3", r1, r2);
            var r5 = MultipleReferencingCi.CreateApplication("5", c, c);
            var r4 = MultipleReferencingCi.CreateApplication("4", c, r5);

            var all = new List <NewConceptApplication> {
                a, b, c, r1, r2, r3, r4, r5
            };
            var dependencies = new DatabaseGenerator_Accessor().ExtractDependenciesFromConceptInfos(all);

            string result = string.Join(" ", dependencies
                                        .Select(d => ((dynamic)d).DependsOn.ConceptInfo.Name + "<" + ((dynamic)d).Dependent.ConceptInfo.Name)
                                        .OrderBy(str => str));

            Console.WriteLine(result);

            Assert.AreEqual("1<3 2<3 5<4 A<1 A<3 B<1 B<2 B<3 C<2 C<3 C<4 C<5", result);
        }