Exemplo n.º 1
0
        public void NoTransaction()
        {
            var oldA = new SimpleConcept("A", "sqlA1");
            var newA = new SimpleConcept("A", "sqlA2");

            var oldB = new SimpleConcept("B", SqlUtility.NoTransactionTag + "sqlB1");
            var newB = new SimpleConcept("B", SqlUtility.NoTransactionTag + "sqlB2");

            var oldC = new SimpleConcept("C", "sqlC1");
            var newC = new SimpleConcept("C", "sqlC2");

            var oldApplications = CreateConceptApplications(oldA, oldB, oldC);
            var newApplications = CreateConceptApplications(newA, newB, newC);

            var dbUpdate = DatabaseGeneratorUpdateDatabase(oldApplications, newApplications);

            string executedSqlReport = string.Concat(
                dbUpdate.SqlExecuter.ExecutedScriptsWithTransaction
                .Select(scripts => (scripts.Item2 ? "TRAN" : "NOTRAN") + ": " + string.Join(", ", scripts.Item1) + ". "))
                                       .Replace(SqlUtility.NoTransactionTag, "")
                                       .Trim();

            string expected = @"
                TRAN: drop-sqlC1, del SimpleConcept C.
                NOTRAN: drop-sqlB1. TRAN: del SimpleConcept B.
                TRAN: drop-sqlA1, del SimpleConcept A,
                sqlA2, ins SimpleConcept A.
                NOTRAN: sqlB2. TRAN: ins SimpleConcept B.
                TRAN: sqlC2, ins SimpleConcept C.";

            Assert.AreEqual(FormatLines(expected), FormatLines(executedSqlReport));
        }
Exemplo n.º 2
0
        public void MustRecreateDependentConceptWhereBaseIsCreatedAndDeletedWithSameKey()
        {
            var oldSimple = new SimpleConcept("S", "sqlS");
            var newSimple = new SimpleConcept("S", "sqlS"); // S is not changed, but its implementation type will be changes later.

            var oldReferenceUnchanged = new ReferenceConcept("R", oldSimple, "sqlR");
            var newReferenceUnchanged = new ReferenceConcept("R", newSimple, "sqlR"); // R is not changed.

            Assert.AreEqual(oldReferenceUnchanged.Name, newReferenceUnchanged.Name);
            Assert.AreEqual(oldReferenceUnchanged.Sql, newReferenceUnchanged.Sql);
            var oldApplications = CreateConceptApplications(oldSimple, oldReferenceUnchanged);
            var newApplications = CreateConceptApplications(newSimple, newReferenceUnchanged);

            // Changing ConceptImplementationTypeName will affect ConceptApplication's key (see GetConceptApplicationKey), and result with dropping and creating it in database.
            // This behavior might change in future if some optimizations are implemented in DatabaseGenerator.
            oldApplications.Find <SimpleConcept>().ConceptImplementationTypeName = typeof(SimpleImplementation).AssemblyQualifiedName.Replace(nameof(SimpleImplementation), "OldImplementationThatNoLongerExists");

            var dbUpdate = DatabaseGeneratorUpdateDatabase(oldApplications, newApplications);

            string expected = "drop-sqlR, del ReferenceConcept R, drop-sqlS, del SimpleConcept S, sqlS, ins SimpleConcept S, sqlR, ins ReferenceConcept R";

            Assert.AreEqual(expected, dbUpdate.Report);

            var removedSimple     = dbUpdate.RemovedConcepts.Find <SimpleConcept>();
            var removedReference  = dbUpdate.RemovedConcepts.Find <ReferenceConcept>();
            var insertedSimple    = dbUpdate.InsertedConcepts.Find <SimpleConcept>();
            var insertedReference = dbUpdate.InsertedConcepts.Find <ReferenceConcept>();

            Assert.AreNotSame(removedSimple, insertedSimple);
            Assert.AreSame(removedSimple, removedReference.DependsOn.Single(), "Removed reference should point to old version of changed concept.");
            Assert.AreEqual(insertedSimple, insertedReference.DependsOn.Single(), "Inserted reference should point to new version of changed concept.");
        }
Exemplo n.º 3
0
        public void MustRecreateDependentConcept()
        {
            var oldSimple = new SimpleConcept("S", "sqlS1");
            var newSimple = new SimpleConcept("S", "sqlS2");

            var oldReferenceUnchanged = new ReferenceConcept("R", oldSimple, "sqlR");
            var newReferenceUnchanged = new ReferenceConcept("R", newSimple, "sqlR"); // Reference is not changed.

            Assert.AreEqual(oldReferenceUnchanged.Name, newReferenceUnchanged.Name);
            Assert.AreEqual(oldReferenceUnchanged.Sql, newReferenceUnchanged.Sql);
            var oldApplications = CreateConceptApplications(oldSimple, oldReferenceUnchanged);
            var newApplications = CreateConceptApplications(newSimple, newReferenceUnchanged);

            string expected = "drop-sqlR, del ReferenceConcept R, drop-sqlS1, del SimpleConcept S, sqlS2, ins SimpleConcept S, sqlR, ins ReferenceConcept R";

            var dbUpdate = DatabaseGeneratorUpdateDatabase(oldApplications, newApplications);

            Assert.AreEqual(expected, dbUpdate.Report);
        }
Exemplo n.º 4
0
        public void RecreatedDependentConceptReferencesNewVersion()
        {
            var oldSimple = new SimpleConcept("S", "sqlS1");
            var newSimple = new SimpleConcept("S", "sqlS2");

            var oldReferenceUnchanged = new ReferenceConcept("R", oldSimple, "sqlR");
            var newReferenceUnchanged = new ReferenceConcept("R", newSimple, "sqlR"); // Reference is not changed.

            Assert.AreEqual(oldReferenceUnchanged.Name, newReferenceUnchanged.Name);
            Assert.AreEqual(oldReferenceUnchanged.Sql, newReferenceUnchanged.Sql);
            var oldApplications = CreateConceptApplications(oldSimple, oldReferenceUnchanged);
            var newApplications = CreateConceptApplications(newSimple, newReferenceUnchanged);

            var dbUpdate = DatabaseGeneratorUpdateDatabase(oldApplications, newApplications);

            Assert.AreEqual("sqlS1", dbUpdate.RemovedConcepts.Find <ReferenceConcept>().DependsOn.Single().CreateQuery,
                            "Removed reference should point to old version of changed concept.");
            Assert.AreEqual("sqlS2", dbUpdate.InsertedConcepts.Find <ReferenceConcept>().DependsOn.Single().CreateQuery,
                            "Inserted reference should point to new version of changed concept.");
        }
Exemplo n.º 5
0
        public void UnchangedMiddleReferenceWithoutDatabaseGenerator()
        {
            // A <- B <- C;
            var oldA = new SimpleConcept("A", "sqlA1");
            var newA = new SimpleConcept("A", "sqlA2"); // Changed.

            var oldB = new NoImplementationConcept("B", oldA);
            var newB = new NoImplementationConcept("B", newA); // A and C have database generator implementations, but B doesn't.

            var oldC = new ReferenceConcept("C", oldB, "sqlC1");
            var newC = new ReferenceConcept("C", newB, "sqlC2"); // Second-level reference is changed.

            var oldApplications = CreateConceptApplications(oldA, oldB, oldC);
            var newApplications = CreateConceptApplications(newA, newB, newC);

            var dbUpdate = DatabaseGeneratorUpdateDatabase(oldApplications, newApplications);

            string expected = "drop-sqlC1, del ReferenceConcept C, del NoImplementationConcept B, drop-sqlA1, del SimpleConcept A,"
                              + " sqlA2, ins SimpleConcept A, ins NoImplementationConcept B, sqlC2, ins ReferenceConcept C";

            Assert.AreEqual(expected, dbUpdate.Report);
        }
Exemplo n.º 6
0
        public void MustRecreateDependentConceptInCorrectOrder()
        {
            // A <- B <- C;
            var oldA = new SimpleConcept("A", "sqlA1");
            var newA = new SimpleConcept("A", "sqlA2"); // Changed.

            var oldB = new ReferenceConcept("B", oldA, "sqlB");
            var newB = new ReferenceConcept("B", newA, "sqlB"); // Reference is not changed.

            var oldC = new ReferenceReferenceConcept("C", oldB, "sqlC1");
            var newC = new ReferenceReferenceConcept("C", newB, "sqlC2"); // Second-level reference is changed.

            var oldApplications = CreateConceptApplications(oldA, oldB, oldC);
            var newApplications = CreateConceptApplications(newA, newB, newC);

            var dbUpdate = DatabaseGeneratorUpdateDatabase(oldApplications, newApplications);

            string expected = "drop-sqlC1, del ReferenceReferenceConcept C, drop-sqlB, del ReferenceConcept B, drop-sqlA1, del SimpleConcept A,"
                              + " sqlA2, ins SimpleConcept A, sqlB, ins ReferenceConcept B, sqlC2, ins ReferenceReferenceConcept C";

            Assert.AreEqual(expected, dbUpdate.Report);
        }
Exemplo n.º 7
0
        public void RecreateDependentConceptWithNewConceptInfoReference()
        {
            var oldSimpleA = new SimpleConcept("A", "sqlA1");
            var newSimpleA = new SimpleConcept("A", "sqlA2"); // A has been modified.

            var oldSimpleB = new SimpleConcept("B", "sqlB");
            var newSimpleB = new SimpleConcept("B", "sqlB");

            var oldApplications = CreateConceptApplications(oldSimpleA, oldSimpleB);
            var newApplications = CreateConceptApplications(newSimpleA, newSimpleB);

            // Adding a dependency that did not exist in the version 1.
            var newSimpleAApplication = newApplications.Where(ca => ca.ConceptInfoKey == "SimpleConcept A").Single();
            var newSimpleBApplication = newApplications.Where(ca => ca.ConceptInfoKey == "SimpleConcept B").Single();

            newSimpleBApplication.DependsOn = new[] { newSimpleAApplication };

            var dbUpdate = DatabaseGeneratorUpdateDatabase(oldApplications, newApplications);

            // Event if B did not depend on A previously, it depends now, so it should be refreshed when A has been modified.
            Assert.AreEqual(2, dbUpdate.RemovedConcepts.Count);
            Assert.AreEqual(2, dbUpdate.InsertedConcepts.Count);
        }
Exemplo n.º 8
0
        public void RecreateDependentConceptWithOldConceptInfoReference()
        {
            var oldSimpleA = new SimpleConcept("A", "sqlA1");
            var newSimpleA = new SimpleConcept("A", "sqlA2"); // A has been modified.

            var oldSimpleB = new SimpleConcept("B", "sqlB");
            var newSimpleB = new SimpleConcept("B", "sqlB");

            var oldApplications = CreateConceptApplications(oldSimpleA, oldSimpleB);
            var newApplications = CreateConceptApplications(newSimpleA, newSimpleB);

            // B previously depended on A, but it does not in new version.
            var oldSimpleAApplication = oldApplications.Where(ca => ca.ConceptInfoKey == "SimpleConcept A").Single();
            var oldSimpleBApplication = oldApplications.Where(ca => ca.ConceptInfoKey == "SimpleConcept B").Single();

            oldSimpleBApplication.DependsOn = new[] { oldSimpleAApplication };

            var dbUpdate = DatabaseGeneratorUpdateDatabase(oldApplications, newApplications);

            // Event if B does no longer depend on A, it depended previously, so it should be refreshed when A has been modified.
            // **Note**: This test is just a snapshot of current DatabaseGenerator behavior. I am not sure if this behavior should be preserved.
            Assert.AreEqual(2, dbUpdate.RemovedConcepts.Count);
            Assert.AreEqual(2, dbUpdate.InsertedConcepts.Count);
        }