public void SortingCircular()
        {
            // Circular dependencies are not supported in Rhetos,
            // but this test verifies robustness of the algorithm implementation
            // and error detection.

            var cA = new C1 {
                Name = "A"
            };
            var cB = new C1 {
                Name = "B"
            };

            cA.Ref1 = cB;
            cB.Ref1 = cA;
            var cInit = new InitializationConcept {
                RhetosVersion = "init"
            };
            var cDependant = new C2 {
                Name = "dep", Ref1 = cA, Ref2 = cB
            };

            var testData = new List <IConceptInfo> {
                cDependant, cA, cB, cInit
            };
            var dslContainer = new DslContainerAccessor {
                ResolvedConcepts = testData
            };

            TestUtility.ShouldFail <FrameworkException>(
                () => dslContainer.SortReferencesBeforeUsingConcept(InitialConceptsSort.None),
                "C1 A");
        }
        public void SortEmpty()
        {
            var testData     = new List <IConceptInfo> {
            };
            var dslContainer = new DslContainerAccessor {
                ResolvedConcepts = testData
            };

            dslContainer.SortReferencesBeforeUsingConcept(InitialConceptsSort.None);
            Assert.AreEqual(
                TestUtility.Dump(testData, c => c.GetKey()),
                TestUtility.Dump(dslContainer.ResolvedConcepts, c => c.GetKey()));
        }
        public void SortInitOnly()
        {
            var cInit = new InitializationConcept {
                RhetosVersion = "init"
            };

            var testData = new List <IConceptInfo> {
                cInit
            };
            var dslContainer = new DslContainerAccessor {
                ResolvedConcepts = testData
            };

            dslContainer.SortReferencesBeforeUsingConcept(InitialConceptsSort.None);
            Assert.AreEqual(
                TestUtility.Dump(testData, c => c.GetKey()),
                TestUtility.Dump(dslContainer.ResolvedConcepts, c => c.GetKey()));
        }
Exemple #4
0
        public void Sorting()
        {
            var cInit = new InitializationConcept {
                RhetosVersion = "init"
            };
            var c01 = new C0 {
                Name = "1"
            };
            var c02 = new C0 {
                Name = "2"
            };
            var c03 = new C0 {
                Name = "3"
            };
            var cB1 = new CBase {
                Name = "1"
            };
            var cB2 = new CBase {
                Name = "2"
            };
            var c2Dependant = new C2 {
                Name = "dep", Ref1 = c01, Ref2 = cB2
            };

            var testData = new List <IConceptInfo> {
                c02, c01, cB2, c2Dependant, cInit, c03, cB1
            };

            // The expected positions may somewhat change if the sorting algorithm internals change.
            var tests = new List <(string SortMethod, List <IConceptInfo> ExpectedResult)>
            {
                // cInit always goes first. cDependant does not need to move because it is after referenced c1 and c5.
                ("None", new List <IConceptInfo> {
                    cInit, c02, c01, cB2, c2Dependant, c03, cB1
                }),

                // cB2 is pushed before c2Dependant, to respect dependency precedence.
                ("Key", new List <IConceptInfo> {
                    cInit, c01, c02, c03, cB2, c2Dependant, cB1
                }),

                // c01 is pushed before c2Dependant, to respect dependency precedence.
                ("KeyDescending", new List <IConceptInfo> {
                    cInit, cB2, cB1, c01, c2Dependant, c03, c02
                }),
            };

            foreach (var test in tests)
            {
                var configuration = new MockConfiguration {
                    { "CommonConcepts.Debug.SortConcepts", test.SortMethod }
                };
                var dslContainer = new DslContainerAccessor(configuration);
                dslContainer.ResolvedConcepts = testData;
                dslContainer.SortReferencesBeforeUsingConcept();
                Assert.AreEqual(
                    TestUtility.Dump(test.ExpectedResult, c => c.GetKey()),
                    TestUtility.Dump(dslContainer.ResolvedConcepts, c => c.GetKey()),
                    test.SortMethod);
            }
        }
        public void Sorting()
        {
            var cInit = new InitializationConcept {
                RhetosVersion = "init"
            };
            var c01 = new C0 {
                Name = "1"
            };
            var c02 = new C0 {
                Name = "2"
            };
            var c03 = new C0 {
                Name = "3"
            };
            var cB1 = new CBase {
                Name = "1"
            };
            var cB2 = new CBase {
                Name = "2"
            };
            var c2Dependant = new C2 {
                Name = "dep", Ref1 = c01, Ref2 = cB2
            };

            var testData = new List <IConceptInfo> {
                c02, c01, cB2, c2Dependant, cInit, c03, cB1
            };

            // The expected positions may somewhat change if the sorting algorithm internals change.
            var tests = new List <(InitialConceptsSort SortMethod, List <IConceptInfo> ExpectedResult)>
            {
                // cInit always goes first. cDependant is moved to the end, even though it does not need to be moved
                // because it is after referenced c01 and cB2. Putting all level 2 concept after level 1,
                // instead of keeping the initial sort based on dynamic evaluation, should result with
                // less changes in the final generated code.
                (InitialConceptsSort.None, new List <IConceptInfo> {
                    cInit, c02, c01, cB2, c03, cB1, c2Dependant
                }),

                // Keeping the InitialConceptsSort ordering between the concepts of the same level.
                (InitialConceptsSort.Key, new List <IConceptInfo> {
                    cInit, c01, c02, c03, cB1, cB2, c2Dependant
                }),

                // Keeping the InitialConceptsSort ordering between the concepts of the same level.
                (InitialConceptsSort.KeyDescending, new List <IConceptInfo> {
                    cInit, cB2, cB1, c03, c02, c01, c2Dependant
                }),
            };

            foreach (var test in tests)
            {
                var dslContainer = new DslContainerAccessor {
                    ResolvedConcepts = testData
                };
                dslContainer.SortReferencesBeforeUsingConcept(test.SortMethod);
                Assert.AreEqual(
                    TestUtility.Dump(test.ExpectedResult, c => c.GetKey()),
                    TestUtility.Dump(dslContainer.ResolvedConcepts, c => c.GetKey()),
                    $"SortConceptsMethod: {test.SortMethod}");
            }
        }