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"); }
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); }
public static IEnumerable <object[]> Should_Initialize_Data() { 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" }); yield return(new object[] { rootSpecificationScope, specificationScopes, rootSpecificationScopeId, errorRegistry, template, pathMap, Substitute.For <ICapacityInfo>(), false }); }
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>(); }
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); }
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"); }
public void Should_ThrowException_When_Initialize_With_RootSpecificationScopeId_OfSpecificationScopeOfInvalidType(object rootSpecificationScope, Dictionary <int, object> specificationScopes, int rootSpecificationScopeId, Dictionary <int, IError> errorRegistry, Dictionary <string, IReadOnlyList <int> > template, Dictionary <string, IReadOnlyDictionary <string, string> > pathMap, ICapacityInfo capacityInfo, bool isReferenceLoopPossible) { _ = rootSpecificationScope; var invalidRootSpecificationScope = new SpecificationScope <object>(); specificationScopes[rootSpecificationScopeId] = invalidRootSpecificationScope; Action action = () => new ModelScheme <TestClass>(specificationScopes, rootSpecificationScopeId, errorRegistry, template, pathMap, capacityInfo, isReferenceLoopPossible); action.Should().ThrowExactly <ArgumentException>(); }
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); }
public void Should_Discover_ReferenceType(object presenceObj, int commandScopesCount) { var presence = (Presence)presenceObj; var commandScopes = Enumerable.Range(0, commandScopesCount).Select(m => { return(Substitute.For <ICommandScope <TestClass> >()); }).ToList(); var specificationScope = new SpecificationScope <TestClass>(); specificationScope.Presence = presence; specificationScope.CommandScopes = commandScopes; specificationScope.ForbiddenErrorId = 321; specificationScope.RequiredErrorId = 123; var discoveryContext = Substitute.For <IDiscoveryContext>(); specificationScope.Discover(discoveryContext); Received.InOrder(() => { if (presence == Presence.Forbidden) { discoveryContext.AddError(321, true); } else { if (presence == Presence.Required) { discoveryContext.AddError(123, true); } for (var i = 0; i < commandScopesCount; ++i) { commandScopes[i].Discover(Arg.Is(discoveryContext)); } } }); if (presence == Presence.Optional) { discoveryContext.DidNotReceiveWithAnyArgs().AddError(default);
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); }
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"); }