Example #1
0
        public void CreateNewApplications_MissingMiddleApplications()
        {
            IConceptInfo ci1 = new SimpleCi {
                Name = "1"
            };                                              // Concept application SimpleConceptImplementation will generate SQL script "create 1".
            IConceptInfo ci2 = new SimpleCi2 {
                Name = "2"
            };                                               // No concept application in database.
            IConceptInfo ci3 = new SimpleCi3 {
                Name = "3"
            };                                               // Concept application ExtendingConceptImplementation does not generate SQL script.

            var conceptImplementations = new PluginsMetadataList <IConceptDatabaseDefinition>
            {
                new NullImplementation(),
                { new SimpleConceptImplementation(), typeof(SimpleCi) },
                { new ExtendingConceptImplementation(), typeof(SimpleCi3) },
            };

            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 databasePlugins      = MockDatabasePluginsContainer.Create(conceptImplementations);
            var databaseModelBuilder = new DatabaseModelBuilderAccessor(databasePlugins, dslModel);
            var conceptApplications  = databaseModelBuilder.CreateDatabaseModel().DatabaseObjects;

            tempConceptInfoDependencies = null;

            var ca1 = conceptApplications.Where(ca => ca.ConceptInfoKey == ci1.GetKey()).Single();
            var ca3 = conceptApplications.Where(ca => ca.ConceptInfoKey == ci3.GetKey()).Single();

            Assert.IsTrue(DirectAndIndirectDependencies(ca1).Contains(ca3), "Concept application ca3 should be included in direct or indirect dependencies of ca1.");
        }
Example #2
0
        public void ExtractCreateQueries_Empty()
        {
            var sqlCodeBuilder = new CodeBuilder("/*", "*/");

            var createQueries = DatabaseModelBuilderAccessor.ExtractCreateQueries(sqlCodeBuilder.GeneratedCode);

            Assert.AreEqual(
                "",
                TestUtility.DumpSorted(createQueries, cq => $"{cq.Key}:{cq.Value}"));
        }
Example #3
0
        public void ExtractCreateQueries_BeforeFirst2()
        {
            var sqlCodeBuilder = new CodeBuilder("/*", "*/");

            sqlCodeBuilder.InsertCode("before first");

            var newConceptApplications = new List <CodeGenerator>();

            TestUtility.ShouldFail <FrameworkException>(
                () => DatabaseModelBuilderAccessor.ExtractCreateQueries(sqlCodeBuilder.GeneratedCode),
                "The first segment should be empty");
        }
Example #4
0
        public void ExtractCreateQueries_BeforeFirst1()
        {
            var ca1 = new CodeGenerator(new BaseCi {
                Name = "ci1"
            }, new SimpleConceptImplementation());
            const string createQuery1 = "create query 1";
            var          ca2          = new CodeGenerator(new BaseCi {
                Name = "ci2"
            }, new SimpleConceptImplementation());
            const string createQuery2 = "create query 2";

            var sqlCodeBuilder = new CodeBuilder("/*", "*/");

            sqlCodeBuilder.InsertCode("before first");
            sqlCodeBuilder.InsertCode(DatabaseModelBuilderAccessor.GetCodeGeneratorSeparator(0));
            sqlCodeBuilder.InsertCode(createQuery1);
            sqlCodeBuilder.InsertCode(DatabaseModelBuilderAccessor.GetCodeGeneratorSeparator(1));
            sqlCodeBuilder.InsertCode(createQuery2);

            TestUtility.ShouldFail <FrameworkException>(
                () => DatabaseModelBuilderAccessor.ExtractCreateQueries(sqlCodeBuilder.GeneratedCode),
                "The first segment should be empty");
        }
Example #5
0
        public void ExtractCreateQueries()
        {
            var ca1 = new CodeGenerator(new BaseCi {
                Name = "ci1"
            }, new SimpleConceptImplementation());
            const string createQuery1 = "create query 1";
            var          ca2          = new CodeGenerator(new BaseCi {
                Name = "ci2"
            }, new SimpleConceptImplementation());
            const string createQuery2 = "create query 2";

            var sqlCodeBuilder = new CodeBuilder("/*", "*/");

            sqlCodeBuilder.InsertCode(DatabaseModelBuilderAccessor.GetCodeGeneratorSeparator(ca1.Id));
            sqlCodeBuilder.InsertCode(createQuery1);
            sqlCodeBuilder.InsertCode(DatabaseModelBuilderAccessor.GetCodeGeneratorSeparator(ca2.Id));
            sqlCodeBuilder.InsertCode(createQuery2);

            var createQueries = DatabaseModelBuilderAccessor.ExtractCreateQueries(sqlCodeBuilder.GeneratedCode);

            Assert.AreEqual(
                $"{ca1.Id}:create query 1, {ca2.Id}:create query 2",
                TestUtility.DumpSorted(createQueries, cq => $"{cq.Key}:{cq.Value}"));
        }