Exemplo n.º 1
0
            public void Should_ReturnPathFromFromPathsHelper_IfOnlyNextLevelNotPresent()
            {
                var rootSpecificationScope   = new SpecificationScope <TestClass>();
                var rootSpecificationScopeId = 10;
                var specificationScopes      = new Dictionary <int, object>();

                specificationScopes.Add(rootSpecificationScopeId, rootSpecificationScope);
                var errorRegistry = new Dictionary <int, IError>();

                errorRegistry.Add(44, new Error());
                var template = new Dictionary <string, IReadOnlyList <int> >();

                template.Add("path", new[] { 44 });

                var pathMap = new Dictionary <string, IReadOnlyDictionary <string, string> >();

                pathMap.Add("first", new Dictionary <string, string>()
                {
                    ["next_level_not_present"] = "third"
                });

                var modelScheme = new ModelScheme <TestClass>(specificationScopes, rootSpecificationScopeId, errorRegistry, template, pathMap, Substitute.For <ICapacityInfo>(), false);

                var path = modelScheme.ResolvePath("first", "second");

                path.Should().Be("first.second");
            }
Exemplo n.º 2
0
            public void Should_ThrowException_When_InvalidType()
            {
                var rootSpecificationScope = new SpecificationScope <TestClass>();

                var rootSpecificationScopeId = 10;
                var specificationScopes      = new Dictionary <int, object>();

                specificationScopes.Add(rootSpecificationScopeId, rootSpecificationScope);

                var errorRegistry = new Dictionary <int, IError>();

                errorRegistry.Add(44, new Error());
                var template = new Dictionary <string, IReadOnlyList <int> >();

                template.Add("path", new[] { 44 });
                var pathMap = new Dictionary <string, IReadOnlyDictionary <string, string> >();

                pathMap.Add("", new Dictionary <string, string>()
                {
                    ["path"] = "path"
                });

                var specificationScope1 = new SpecificationScope <decimal>();

                specificationScopes.Add(30, specificationScope1);

                var modelScheme = new ModelScheme <TestClass>(specificationScopes, rootSpecificationScopeId, errorRegistry, template, pathMap, Substitute.For <ICapacityInfo>(), false);

                Action action = () => modelScheme.GetSpecificationScope <TestClass>(30);

                action.Should().ThrowExactly <InvalidCastException>();
            }
Exemplo n.º 3
0
            public void Should_GetSpecificationScope()
            {
                var rootSpecificationScope = new SpecificationScope <TestClass>();

                var rootSpecificationScopeId = 10;
                var specificationScopes      = new Dictionary <int, object>();

                specificationScopes.Add(rootSpecificationScopeId, rootSpecificationScope);

                var errorRegistry = new Dictionary <int, IError>();

                errorRegistry.Add(44, new Error());
                var template = new Dictionary <string, IReadOnlyList <int> >();

                template.Add("path", new[] { 44 });
                var pathMap = new Dictionary <string, IReadOnlyDictionary <string, string> >();

                pathMap.Add("", new Dictionary <string, string>()
                {
                    ["path"] = "path"
                });

                var modelScheme = new ModelScheme <TestClass>(specificationScopes, rootSpecificationScopeId, errorRegistry, template, pathMap, Substitute.For <ICapacityInfo>(), false);

                var scope = modelScheme.GetSpecificationScope <TestClass>(10);

                scope.Should().BeSameAs(rootSpecificationScope);
            }
Exemplo n.º 4
0
        internal static ModelScheme <TestClass> GetDefault()
        {
            var rootSpecificationScope = new SpecificationScope <TestClass>();

            var rootSpecificationScopeId = 10;
            var specificationScopes      = new Dictionary <int, object>();

            specificationScopes.Add(rootSpecificationScopeId, rootSpecificationScope);

            var errorRegistry = new Dictionary <int, IError>();

            errorRegistry.Add(44, new Error());
            var template = new Dictionary <string, IReadOnlyList <int> >();

            template.Add("path", new[] { 44 });
            var pathMap = new Dictionary <string, IReadOnlyDictionary <string, string> >();

            pathMap.Add("", new Dictionary <string, string>()
            {
                ["path"] = "path"
            });

            var modelScheme = new ModelScheme <TestClass>(specificationScopes, rootSpecificationScopeId, errorRegistry, template, pathMap, Substitute.For <ICapacityInfo>(), false);

            return(modelScheme);
        }
Exemplo n.º 5
0
            public void Should_ReturnPathFromMap_IfPresent()
            {
                var rootSpecificationScope   = new SpecificationScope <TestClass>();
                var rootSpecificationScopeId = 10;
                var specificationScopes      = new Dictionary <int, object>();

                specificationScopes.Add(rootSpecificationScopeId, rootSpecificationScope);
                var errorRegistry = new Dictionary <int, IError>();

                errorRegistry.Add(44, new Error());
                var template = new Dictionary <string, IReadOnlyList <int> >();

                template.Add("path", new[] { 44 });

                var pathMap = new Dictionary <string, IReadOnlyDictionary <string, string> >();

                pathMap.Add("first", new Dictionary <string, string>()
                {
                    ["second"] = "third"
                });

                var modelScheme = new ModelScheme <TestClass>(specificationScopes, rootSpecificationScopeId, errorRegistry, template, pathMap, false);

                var path = modelScheme.ResolvePath("first", "second");

                path.Should().Be("third");
            }
Exemplo n.º 6
0
            public void Should_Initialize(object rootSpecificationScope, Dictionary <int, object> specificationScopes, int rootSpecificationScopeId, Dictionary <int, IError> errorRegistry, Dictionary <string, IReadOnlyList <int> > template, Dictionary <string, IReadOnlyDictionary <string, string> > pathMap, bool isReferenceLoopPossible)
            {
                var modelScheme = new ModelScheme <TestClass>(specificationScopes, rootSpecificationScopeId, errorRegistry, template, pathMap, isReferenceLoopPossible);

                modelScheme.RootSpecificationScope.Should().BeSameAs(rootSpecificationScope);

                modelScheme.ErrorRegistry.Should().BeSameAs(errorRegistry);
                modelScheme.Template.Should().BeSameAs(template);
                modelScheme.IsReferenceLoopPossible.Should().Be(isReferenceLoopPossible);
                modelScheme.RootSpecificationScopeId.Should().Be(rootSpecificationScopeId);
            }
Exemplo n.º 7
0
            public void Should_GetSpecificationScope_MultipleTimes()
            {
                var rootSpecificationScope = new SpecificationScope <TestClass>();

                var rootSpecificationScopeId = 10;
                var specificationScopes      = new Dictionary <int, object>();

                specificationScopes.Add(rootSpecificationScopeId, rootSpecificationScope);

                var errorRegistry = new Dictionary <int, IError>();

                errorRegistry.Add(44, new Error());
                var template = new Dictionary <string, IReadOnlyList <int> >();

                template.Add("path", new[] { 44 });
                var pathMap = new Dictionary <string, IReadOnlyDictionary <string, string> >();

                pathMap.Add("", new Dictionary <string, string>()
                {
                    ["path"] = "path"
                });

                var specificationScope1 = new SpecificationScope <TestClass>();

                specificationScopes.Add(30, specificationScope1);

                var specificationScope2 = new SpecificationScope <TestClass>();

                specificationScopes.Add(31, specificationScope2);

                var specificationScope3 = new SpecificationScope <TestClass>();

                specificationScopes.Add(32, specificationScope3);

                var specificationScope4 = new SpecificationScope <int>();

                specificationScopes.Add(33, specificationScope4);

                var specificationScope5 = new SpecificationScope <DateTimeOffset?>();

                specificationScopes.Add(34, specificationScope5);

                var modelScheme = new ModelScheme <TestClass>(specificationScopes, rootSpecificationScopeId, errorRegistry, template, pathMap, Substitute.For <ICapacityInfo>(), false);

                modelScheme.GetSpecificationScope <TestClass>(30).Should().BeSameAs(specificationScope1);
                modelScheme.GetSpecificationScope <TestClass>(31).Should().BeSameAs(specificationScope2);
                modelScheme.GetSpecificationScope <TestClass>(32).Should().BeSameAs(specificationScope3);
                modelScheme.GetSpecificationScope <int>(33).Should().BeSameAs(specificationScope4);
                modelScheme.GetSpecificationScope <DateTimeOffset?>(34).Should().BeSameAs(specificationScope5);
            }
Exemplo n.º 8
0
            public void Should_ReturnPathFromHelper_IfNotPresent(string basePath, string newSegment, string expectedPath)
            {
                var rootSpecificationScope   = new SpecificationScope <TestClass>();
                var rootSpecificationScopeId = 10;
                var specificationScopes      = new Dictionary <int, object>();

                specificationScopes.Add(rootSpecificationScopeId, rootSpecificationScope);
                var errorRegistry = new Dictionary <int, IError>();

                errorRegistry.Add(44, new Error());
                var template = new Dictionary <string, IReadOnlyList <int> >();

                template.Add("path", new[] { 44 });

                var pathMap = new Dictionary <string, IReadOnlyDictionary <string, string> >();

                var modelScheme = new ModelScheme <TestClass>(specificationScopes, rootSpecificationScopeId, errorRegistry, template, pathMap, Substitute.For <ICapacityInfo>(), false);

                var path = modelScheme.ResolvePath(basePath, newSegment);

                path.Should().Be(expectedPath);
            }
Exemplo n.º 9
0
            public void Should_ReturnPath_FroMapIfAllPresent_FromHelperIfNot()
            {
                var rootSpecificationScope   = new SpecificationScope <TestClass>();
                var rootSpecificationScopeId = 10;
                var specificationScopes      = new Dictionary <int, object>();

                specificationScopes.Add(rootSpecificationScopeId, rootSpecificationScope);
                var errorRegistry = new Dictionary <int, IError>();

                errorRegistry.Add(44, new Error());
                var template = new Dictionary <string, IReadOnlyList <int> >();

                template.Add("path", new[] { 44 });

                var pathMap = new Dictionary <string, IReadOnlyDictionary <string, string> >();

                pathMap.Add("A", new Dictionary <string, string>()
                {
                    ["B"]  = "C",
                    ["b"]  = "c",
                    ["d"]  = "d",
                    ["b2"] = "c2",
                    ["<X"] = "XPATH",
                });

                var modelScheme = new ModelScheme <TestClass>(specificationScopes, rootSpecificationScopeId, errorRegistry, template, pathMap, Substitute.For <ICapacityInfo>(), false);

                modelScheme.ResolvePath("first", "second").Should().Be("first.second");
                modelScheme.ResolvePath("A", "B").Should().Be("C");
                modelScheme.ResolvePath("a", "B").Should().Be("a.B");
                modelScheme.ResolvePath("A", "B1").Should().Be("A.B1");
                modelScheme.ResolvePath("A", "b").Should().Be("c");
                modelScheme.ResolvePath("A", "d").Should().Be("d");

                modelScheme.ResolvePath("A", "<X").Should().Be("XPATH");
                modelScheme.ResolvePath("A", "<x").Should().Be("x");
            }