public void RegisterError_Should_AddErrors_And_AssignDifferentIds()
        {
            var context = new ScopeBuilderContext();

            var error1 = new Error();
            var error2 = new Error();
            var error3 = new Error();

            var errorId1 = context.RegisterError(error1);
            var errorId2 = context.RegisterError(error2);
            var errorId3 = context.RegisterError(error3);

            context.Errors.Count.Should().Be(6);

            context.Errors.Keys.Should().Contain(errorId1);
            context.Errors[errorId1].Should().BeSameAs(error1);

            context.Errors.Keys.Should().Contain(errorId2);
            context.Errors[errorId2].Should().BeSameAs(error2);

            context.Errors.Keys.Should().Contain(errorId3);
            context.Errors[errorId3].Should().BeSameAs(error3);

            context.Scopes.Should().BeEmpty();
            context.Types.Should().BeEmpty();
        }
            public void Should_CreateSpecificationScope_And_SaveType_And_ReturnIds_For_DifferentSpecifications()
            {
                var context = new ScopeBuilderContext();

                Specification <object>    specification1 = m => m;
                Specification <DateTime?> specification2 = m => m;
                Specification <int>       specification3 = m => m;

                var specificationScopeId1 = context.GetOrRegisterSpecificationScope(specification1);
                var specificationScopeId2 = context.GetOrRegisterSpecificationScope(specification2);
                var specificationScopeId3 = context.GetOrRegisterSpecificationScope(specification3);

                specificationScopeId1.Should().Be(0);
                specificationScopeId2.Should().Be(1);
                specificationScopeId3.Should().Be(2);

                context.Scopes.Should().NotBeEmpty();
                context.Scopes.Count.Should().Be(3);

                context.Scopes.Keys.Should().Contain(specificationScopeId1);
                context.Scopes[specificationScopeId1].Should().BeOfType <SpecificationScope <object> >();

                context.Scopes.Keys.Should().Contain(specificationScopeId2);
                context.Scopes[specificationScopeId2].Should().BeOfType <SpecificationScope <DateTime?> >();

                context.Scopes.Keys.Should().Contain(specificationScopeId3);
                context.Scopes[specificationScopeId3].Should().BeOfType <SpecificationScope <int> >();

                context.Types.Should().NotBeEmpty();
                context.Types.Count.Should().Be(3);
                context.Types[specificationScopeId1].Should().Be(typeof(object));
                context.Types[specificationScopeId2].Should().Be(typeof(DateTime?));
                context.Types[specificationScopeId3].Should().Be(typeof(int));
            }
            public void Should_Return_Required_WithCustomError_And_Rules(string testId, Func <dynamic, ISpecificationOut <TestClass> > appendErrorCommands, ErrorContentApiHelper.ExpectedErrorContent expected)
            {
                testId.Should().NotBeNull();

                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Specification <TestClass> specification = m => AppendRule(appendErrorCommands(m.Required()));

                var scope = builder.Build(specification, context);

                if (expected.ShouldBeEmpty(0))
                {
                    scope.RequiredErrorId.Should().Be(context.RequiredErrorId);
                }
                else
                {
                    scope.RequiredErrorId.Should().NotBe(context.RequiredErrorId);
                    context.Errors.Keys.Should().Contain(scope.RequiredErrorId);

                    expected.Match(context.Errors[scope.RequiredErrorId]);
                }

                dynamic AppendRule(dynamic api)
                {
                    if (api is IRuleIn <TestClass> ruleIn)
                    {
                        return(RuleExtension.Rule(ruleIn, m => false));
                    }

                    throw new InvalidOperationException("Dynamic api tests failed");
                }
            }
            public void Should_Build_AsMemberScope_When_AsMemberScope(string testId, Func <dynamic, ISpecificationOut <TestParent> > appendSetupCommands, ErrorSetupApiHelper.ExpectedErrorSetup <TestParent> expectedErrorSetup)
            {
                testId.Should().NotBeNull();

                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Specification <TestClass> innerSpecification = m => m;

                Specification <TestParent> specification = m => appendSetupCommands(m.Member(m1 => m1.TestMember, innerSpecification));

                var scope = builder.Build(specification, context);

                scope.CommandScopes.Should().NotBeEmpty();
                scope.CommandScopes.Count.Should().Be(1);
                scope.CommandScopes[0].Should().BeOfType <MemberCommandScope <TestParent, TestClass> >();

                var memberCommandScope = (MemberCommandScope <TestParent, TestClass>)scope.CommandScopes[0];

                memberCommandScope.Path.Should().Be(expectedErrorSetup.Path ?? "TestMember");
                memberCommandScope.ErrorMode.Should().Be(ErrorMode.Append);
                memberCommandScope.ErrorId.Should().BeNull();
                memberCommandScope.ExecutionCondition.Should().BeSameAs(expectedErrorSetup.ShouldExecute);

                context.Scopes.Keys.Should().Contain(memberCommandScope.ScopeId);

                context.Scopes[memberCommandScope.ScopeId].Should().BeOfType <SpecificationScope <TestClass> >();
            }
            public void Should_Build_RuleCommandScope_When_Rule(string testId, Func <dynamic, ISpecificationOut <TestClass> > appendSetupCommands, ErrorSetupApiHelper.ExpectedErrorSetup <TestClass> expectedErrorSetup)
            {
                testId.Should().NotBeNull();

                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Predicate <TestClass> predicate = x => true;

                Specification <TestClass> specification = m => appendSetupCommands(m.Rule(predicate));

                var scope = builder.Build(specification, context);

                scope.CommandScopes.Should().NotBeEmpty();
                scope.CommandScopes.Count.Should().Be(1);
                scope.CommandScopes[0].Should().BeOfType <RuleCommandScope <TestClass> >();

                var ruleCommandScope = (RuleCommandScope <TestClass>)scope.CommandScopes[0];

                ruleCommandScope.Path.Should().Be(expectedErrorSetup.Path);
                ruleCommandScope.ExecutionCondition.Should().Be(expectedErrorSetup.ShouldExecute);
                ruleCommandScope.ErrorMode.Should().Be(ErrorMode.Append);
                ruleCommandScope.IsValid.Should().BeSameAs(predicate);

                ruleCommandScope.ErrorId.Should().Be(context.DefaultErrorId);
            }
            public void Should_Build_AsNullableScope_When_AsNullable(string testId, Func <dynamic, ISpecificationOut <int?> > appendSetupCommands, ErrorSetupApiHelper.ExpectedErrorSetup <int?> expectedErrorSetup)
            {
                _ = testId;

                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Specification <int> innerSpecification = m => m;

                Specification <int?> specification = m => appendSetupCommands(m.AsNullable(innerSpecification));

                var scope = builder.Build(specification, context);

                scope.CommandScopes.Should().NotBeEmpty();
                scope.CommandScopes.Count.Should().Be(1);
                scope.CommandScopes[0].Should().BeOfType <NullableCommandScope <int> >();

                var nullableCommandScope = (NullableCommandScope <int>)scope.CommandScopes[0];

                nullableCommandScope.Path.Should().Be(expectedErrorSetup.Path);
                nullableCommandScope.ErrorMode.Should().Be(ErrorMode.Append);
                nullableCommandScope.ErrorId.Should().BeNull();
                nullableCommandScope.ExecutionCondition.Should().BeSameAs(expectedErrorSetup.ShouldExecute);

                context.Scopes.Keys.Should().Contain(nullableCommandScope.ScopeId);

                context.Scopes[nullableCommandScope.ScopeId].Should().BeOfType <SpecificationScope <int> >();
            }
            public void Should_Return_Forbidden_WithCustomError(string testId, Func <dynamic, ISpecificationOut <TestClass> > appendErrorCommands, ErrorContentApiHelper.ExpectedErrorContent expected)
            {
                testId.Should().NotBeNull();

                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Specification <TestClass> specification = m => appendErrorCommands(m.Forbidden());

                var scope = builder.Build(specification, context);

                if (expected.ShouldBeEmpty(0))
                {
                    scope.ForbiddenErrorId.Should().Be(context.ForbiddenErrorId);
                }
                else
                {
                    scope.ForbiddenErrorId.Should().NotBe(context.ForbiddenErrorId);

                    context.Errors.Keys.Should().Contain(scope.ForbiddenErrorId);

                    expected.Match(context.Errors[scope.ForbiddenErrorId]);
                }
            }
        public static ModelScheme <T> Create <T>(Specification <T> specification, ICapacityInfo capacityInfo)
        {
            ThrowHelper.NullArgument(specification, nameof(specification));

            var scopeBuilderContext = new ScopeBuilderContext();

            var rootSpecificationScopeId = scopeBuilderContext.GetOrRegisterSpecificationScope(specification);

            var discoveryContext = new DiscoveryContext(scopeBuilderContext, rootSpecificationScopeId);

            var rootSpecificationScope = (SpecificationScope <T>)scopeBuilderContext.Scopes[rootSpecificationScopeId];

            rootSpecificationScope.Discover(discoveryContext);

            if (capacityInfo is ICapacityInfoHelpersConsumer capacityInfoHelpersConsumer)
            {
                capacityInfoHelpersConsumer.InjectHelpers(CapacityInfoHelpers);
            }

            if (capacityInfo is IFeedableCapacityInfo feedableCapacityInfo && feedableCapacityInfo.ShouldFeed)
            {
                feedableCapacityInfo.Feed(discoveryContext);
            }

            return(new ModelScheme <T>(
                       scopeBuilderContext.Scopes,
                       rootSpecificationScopeId,
                       scopeBuilderContext.Errors,
                       discoveryContext.Errors.ToDictionary(p => p.Key, p => (IReadOnlyList <int>)p.Value),
                       discoveryContext.Paths.ToDictionary(p => p.Key, p => (IReadOnlyDictionary <string, string>)p.Value),
                       capacityInfo,
                       discoveryContext.ReferenceLoopRoots.Count > 0));
        }
            public void Should_ThrowException_When_NullSpecification()
            {
                var context = new ScopeBuilderContext();

                Action action = () => context.GetOrRegisterSpecificationScope <object>(null);

                action.Should().ThrowExactly <ArgumentNullException>();
            }
        public void RegisterError_Should_ThrowException_NullError()
        {
            var context = new ScopeBuilderContext();

            Action action = () => context.RegisterError(null);

            action.Should().ThrowExactly <ArgumentNullException>();
        }
            public void Should_ThrowException_When_InvalidId()
            {
                var context = new ScopeBuilderContext();

                Action action = () =>
                {
                    context.GetDiscoverableSpecificationScope(321);
                };

                action.Should().ThrowExactly <KeyNotFoundException>();
            }
Example #12
0
        public void Should_BeEmpty_When_NoCommand()
        {
            var context = new ScopeBuilderContext();

            var builder = new ScopeBuilder();

            Specification <TestClass> specification = m => m;

            var scope = builder.Build(specification, context);

            scope.CommandScopes.Should().BeEmpty();
        }
            public void Should_GetSpecificationScope()
            {
                var context = new ScopeBuilderContext();

                Specification <TestClass> specification = m => m;

                var specificationScopeId = context.GetOrRegisterSpecificationScope(specification);

                var discoverableSpecificationScope = context.GetDiscoverableSpecificationScope(specificationScopeId);

                discoverableSpecificationScope.Should().BeSameAs(context.Scopes[specificationScopeId]);
            }
Example #14
0
            public void Should_Return_Required_When_NoCommand()
            {
                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Specification <TestClass> specification = m => m;

                var scope = builder.Build(specification, context);

                scope.Presence.Should().Be(Presence.Required);
                scope.RequiredErrorId.Should().Be(context.RequiredErrorId);
            }
Example #15
0
            public void Should_Return_Optional_When_Optional()
            {
                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Specification <TestClass> specification = m => m
                                                          .Optional();

                var scope = builder.Build(specification, context);

                scope.Presence.Should().Be(Presence.Optional);
            }
Example #16
0
            public void Should_Return_Forbidden_When_Forbidden()
            {
                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Specification <TestClass> specification = m => m
                                                          .Forbidden();

                var scope = builder.Build(specification, context);

                scope.Presence.Should().Be(Presence.Forbidden);
                scope.ForbiddenErrorId.Should().Be(context.ForbiddenErrorId);
            }
Example #17
0
            public void Should_Build_RuleCommandScope_When_RuleTemplate_WithArgs_AndCustomError(string testId, Func <dynamic, ISpecificationOut <TestClass> > appendContentCommands, ErrorContentApiHelper.ExpectedErrorContent expectedErrorContent, Func <dynamic, ISpecificationOut <TestClass> > appendSetupCommands, ErrorSetupApiHelper.ExpectedErrorSetup <TestClass> expectedErrorSetup)
            {
                testId.Should().NotBeNull();

                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Predicate <TestClass> predicate = x => true;

                var args = new IArg[]
                {
                    Arg.Text("argName1", "argValue"),
                    Arg.Number("argName2", 2),
                };

                Specification <TestClass> specification = m => appendSetupCommands(appendContentCommands(m.RuleTemplate(predicate, "ruleKey", args)));

                var scope = builder.Build(specification, context);

                scope.CommandScopes.Should().NotBeEmpty();
                scope.CommandScopes.Count.Should().Be(1);
                scope.CommandScopes[0].Should().BeOfType <RuleCommandScope <TestClass> >();

                var ruleCommandScope = (RuleCommandScope <TestClass>)scope.CommandScopes[0];

                ruleCommandScope.Path.Should().Be(expectedErrorSetup.Path);
                ruleCommandScope.ExecutionCondition.Should().Be(expectedErrorSetup.ShouldExecute);
                ruleCommandScope.ErrorMode.Should().Be(expectedErrorContent.Mode);
                ruleCommandScope.IsValid.Should().BeSameAs(predicate);

                ruleCommandScope.ErrorId.Should().BeGreaterOrEqualTo(0);

                if (expectedErrorContent.ShouldBeEmpty())
                {
                    ruleCommandScope.ErrorId.Should().Be(context.DefaultErrorId);
                }
                else
                {
                    ruleCommandScope.ErrorId.Should().NotBe(context.DefaultErrorId);

                    context.Errors.Keys.Should().Contain(ruleCommandScope.ErrorId);
                    var error = context.Errors[ruleCommandScope.ErrorId];

                    expectedErrorContent.Match(error);

                    error.Args.Should().BeSameAs(args);
                }
            }
Example #18
0
            public void Should_Build_AsCollectionScope_When_AsCollection_WithCustomError(string testId, Func <dynamic, ISpecificationOut <TestParent> > appendContentCommands, ErrorContentApiHelper.ExpectedErrorContent expectedErrorContent, Func <dynamic, ISpecificationOut <TestParent> > appendSetupCommands, ErrorSetupApiHelper.ExpectedErrorSetup <TestParent> expectedErrorSetup)
            {
                testId.Should().NotBeNull();

                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Specification <TestClass> innerSpecification = m => m;

                Specification <TestParent> specification = m => appendContentCommands(appendSetupCommands(m.Member(m1 => m1.TestMember, innerSpecification)));

                var scope = builder.Build(specification, context);

                scope.CommandScopes.Should().NotBeEmpty();
                scope.CommandScopes.Count.Should().Be(1);
                scope.CommandScopes[0].Should().BeOfType <MemberCommandScope <TestParent, TestClass> >();

                var memberCommandScope = (MemberCommandScope <TestParent, TestClass>)scope.CommandScopes[0];

                memberCommandScope.Path.Should().Be(expectedErrorSetup.Path ?? "TestMember");
                memberCommandScope.ExecutionCondition.Should().BeSameAs(expectedErrorSetup.ShouldExecute);
                memberCommandScope.ErrorMode.Should().Be(expectedErrorContent.Mode);

                var testParent = new TestParent()
                {
                    TestMember = new TestClass()
                };

                memberCommandScope.GetMemberValue(testParent).Should().BeSameAs(testParent.TestMember);

                memberCommandScope.ErrorId.Should().HaveValue();
                context.Errors.Keys.Should().Contain(memberCommandScope.ErrorId.Value);

                if (expectedErrorContent.ShouldBeEmpty(0))
                {
                    memberCommandScope.ErrorId.Should().Be(context.DefaultErrorId);
                }
                else
                {
                    memberCommandScope.ErrorId.Should().NotBe(context.DefaultErrorId);
                    expectedErrorContent.Match(context.Errors[memberCommandScope.ErrorId.Value], 0);
                }

                context.Scopes.Keys.Should().Contain(memberCommandScope.ScopeId);

                context.Scopes[memberCommandScope.ScopeId].Should().BeOfType <SpecificationScope <TestClass> >();
            }
        public void RegisterError_Should_AddError()
        {
            var context = new ScopeBuilderContext();

            var error = new Error();

            var errorId = context.RegisterError(error);

            context.Errors.Count.Should().Be(4);
            context.Errors.Keys.Should().Contain(errorId);

            context.Errors[errorId].Should().BeSameAs(error);

            context.Scopes.Should().BeEmpty();
            context.Types.Should().BeEmpty();
        }
        public void Should_Initialize_WithBasicErrorsRegistered_And_EmptyDictionaries()
        {
            var context = new ScopeBuilderContext();

            context.DefaultErrorId.Should().Be(0);
            context.ForbiddenErrorId.Should().Be(1);
            context.RequiredErrorId.Should().Be(2);

            context.Errors.Should().NotBeEmpty();
            context.Errors.Count.Should().Be(3);

            context.Errors[context.DefaultErrorId].ShouldBeEqualTo(new Error
            {
                Messages = new[]
                {
                    "Global.Error"
                },
                Codes = Array.Empty <string>(),
                Args  = Array.Empty <IArg>(),
            });

            context.Errors[context.ForbiddenErrorId].ShouldBeEqualTo(new Error
            {
                Messages = new[]
                {
                    "Global.Forbidden"
                },
                Codes = Array.Empty <string>(),
                Args  = Array.Empty <IArg>(),
            });

            context.Errors[context.RequiredErrorId].ShouldBeEqualTo(new Error
            {
                Messages = new[]
                {
                    "Global.Required"
                },
                Codes = Array.Empty <string>(),
                Args  = Array.Empty <IArg>(),
            });

            context.Scopes.Should().BeEmpty();
            context.Types.Should().BeEmpty();
        }
            public void Should_CreateSpecificationScope_And_SaveType_And_ReturnItsId()
            {
                var context = new ScopeBuilderContext();

                Specification <TestClass> specification = m => m;

                var specificationScopeId = context.GetOrRegisterSpecificationScope(specification);

                specificationScopeId.Should().Be(0);

                context.Scopes.Should().NotBeEmpty();
                context.Scopes.Count.Should().Be(1);
                context.Scopes.Keys.Should().Contain(specificationScopeId);

                context.Scopes[specificationScopeId].Should().BeOfType <SpecificationScope <TestClass> >();

                context.Types.Should().NotBeEmpty();
                context.Types.Count.Should().Be(1);
                context.Types[specificationScopeId].Should().Be(typeof(TestClass));
            }
Example #22
0
            public void Should_Build_AsNullableScope_When_AsNullable_WithCustomError(string testId, Func <dynamic, ISpecificationOut <int?> > appendContentCommands, ErrorContentApiHelper.ExpectedErrorContent expectedErrorContent, Func <dynamic, ISpecificationOut <int?> > appendSetupCommands, ErrorSetupApiHelper.ExpectedErrorSetup <int?> expectedErrorSetup)
            {
                _ = testId;

                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Specification <int> innerSpecification = m => m;

                Specification <int?> specification = m => appendContentCommands(appendSetupCommands(m.AsNullable(innerSpecification)));

                var scope = builder.Build(specification, context);

                scope.CommandScopes.Should().NotBeEmpty();
                scope.CommandScopes.Count.Should().Be(1);
                scope.CommandScopes[0].Should().BeOfType <NullableCommandScope <int> >();

                var nullableCommandScope = (NullableCommandScope <int>)scope.CommandScopes[0];

                nullableCommandScope.Path.Should().Be(expectedErrorSetup.Path);
                nullableCommandScope.ExecutionCondition.Should().BeSameAs(expectedErrorSetup.ShouldExecute);
                nullableCommandScope.ErrorMode.Should().Be(expectedErrorContent.Mode);

                nullableCommandScope.ErrorId.Should().HaveValue();
                context.Errors.Keys.Should().Contain(nullableCommandScope.ErrorId.Value);

                if (expectedErrorContent.ShouldBeEmpty(0))
                {
                    nullableCommandScope.ErrorId.Should().Be(context.DefaultErrorId);
                }
                else
                {
                    nullableCommandScope.ErrorId.Should().NotBe(context.DefaultErrorId);
                    expectedErrorContent.Match(context.Errors[nullableCommandScope.ErrorId.Value], 0);
                }

                context.Scopes.Keys.Should().Contain(nullableCommandScope.ScopeId);

                context.Scopes[nullableCommandScope.ScopeId].Should().BeOfType <SpecificationScope <int> >();
            }
        public static IModelScheme <T> Create <T>(Specification <T> specification)
        {
            ThrowHelper.NullArgument(specification, nameof(specification));

            var scopeBuilderContext = new ScopeBuilderContext();

            var rootSpecificationScopeId = scopeBuilderContext.GetOrRegisterSpecificationScope(specification);

            var discoveryContext = new DiscoveryContext(scopeBuilderContext, rootSpecificationScopeId);

            var rootSpecificationScope = (SpecificationScope <T>)scopeBuilderContext.Scopes[rootSpecificationScopeId];

            rootSpecificationScope.Discover(discoveryContext);

            return(new ModelScheme <T>(
                       scopeBuilderContext.Scopes,
                       rootSpecificationScopeId,
                       scopeBuilderContext.Errors,
                       discoveryContext.Errors.ToDictionary(p => p.Key, p => (IReadOnlyList <int>)p.Value),
                       discoveryContext.Paths.ToDictionary(p => p.Key, p => (IReadOnlyDictionary <string, string>)p.Value),
                       discoveryContext.ReferenceLoopRoots.Count > 0));
        }
Example #24
0
            public void Should_Build_RuleCommandScope_When_Rule_WithCustomError(string testId, Func <dynamic, ISpecificationOut <TestClass> > appendContentCommands, ErrorContentApiHelper.ExpectedErrorContent expectedErrorContent, Func <dynamic, ISpecificationOut <TestClass> > appendSetupCommands, ErrorSetupApiHelper.ExpectedErrorSetup <TestClass> expectedErrorSetup)
            {
                testId.Should().NotBeEmpty();

                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Predicate <TestClass> predicate = x => true;

                Specification <TestClass> specification = m => appendContentCommands(appendSetupCommands(m.Rule(predicate)));

                var scope = builder.Build(specification, context);

                scope.CommandScopes.Should().NotBeEmpty();
                scope.CommandScopes.Count.Should().Be(1);
                scope.CommandScopes[0].Should().BeOfType <RuleCommandScope <TestClass> >();

                var ruleCommandScope = (RuleCommandScope <TestClass>)scope.CommandScopes[0];

                ruleCommandScope.Path.Should().Be(expectedErrorSetup.Path);
                ruleCommandScope.ExecutionCondition.Should().BeSameAs(expectedErrorSetup.ShouldExecute);
                ruleCommandScope.ErrorMode.Should().Be(expectedErrorContent.Mode);
                ruleCommandScope.IsValid.Should().BeSameAs(predicate);

                ruleCommandScope.ErrorId.Should().BeGreaterOrEqualTo(0);

                if (expectedErrorContent.ShouldBeEmpty(0))
                {
                    ruleCommandScope.ErrorId.Should().Be(context.DefaultErrorId);
                }
                else
                {
                    ruleCommandScope.ErrorId.Should().NotBe(context.DefaultErrorId);
                    context.Errors.Keys.Should().Contain(ruleCommandScope.ErrorId);
                    expectedErrorContent.Match(context.Errors[ruleCommandScope.ErrorId], initialMessagesAmount: 0);
                }
            }
Example #25
0
            public void Should_Build_RuleCommandScope_When_RuleTemplate_WithoutArgs(string testId, Func <dynamic, ISpecificationOut <TestClass> > appendSetupCommands, ErrorSetupApiHelper.ExpectedErrorSetup <TestClass> expectedErrorSetup)
            {
                _ = testId;

                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Predicate <TestClass> predicate = x => true;

                Specification <TestClass> specification = m => appendSetupCommands(m.RuleTemplate(predicate, "ruleKey"));

                var scope = builder.Build(specification, context);

                scope.CommandScopes.Should().NotBeEmpty();
                scope.CommandScopes.Count.Should().Be(1);
                scope.CommandScopes[0].Should().BeOfType <RuleCommandScope <TestClass> >();

                var ruleCommandScope = (RuleCommandScope <TestClass>)scope.CommandScopes[0];

                ruleCommandScope.Path.Should().Be(expectedErrorSetup.Path);
                ruleCommandScope.ExecutionCondition.Should().Be(expectedErrorSetup.ShouldExecute);
                ruleCommandScope.ErrorMode.Should().Be(ErrorMode.Append);
                ruleCommandScope.IsValid.Should().BeSameAs(predicate);

                ruleCommandScope.ErrorId.Should().BeGreaterOrEqualTo(0);
                ruleCommandScope.ErrorId.Should().NotBe(context.DefaultErrorId);

                context.Errors.Keys.Should().Contain(ruleCommandScope.ErrorId);

                var error = context.Errors[ruleCommandScope.ErrorId];

                error.Messages.Count.Should().Be(1);
                error.Messages[0].Should().Be("ruleKey");
                error.Args.Should().BeEmpty();
                error.Codes.Should().BeEmpty();
            }
            public void Should_CreateSpecificationScope_And_SaveType_OnlyOnce_For_MultipleCallsWithSameSpecification()
            {
                var context = new ScopeBuilderContext();

                Specification <object> specification = m => m;

                var specificationScopeId1 = context.GetOrRegisterSpecificationScope(specification);
                var specificationScopeId2 = context.GetOrRegisterSpecificationScope(specification);
                var specificationScopeId3 = context.GetOrRegisterSpecificationScope(specification);

                specificationScopeId1.Should().Be(0);
                specificationScopeId2.Should().Be(0);
                specificationScopeId3.Should().Be(0);

                context.Scopes.Should().NotBeEmpty();
                context.Scopes.Count.Should().Be(1);

                context.Scopes.Keys.Should().Contain(specificationScopeId1);
                context.Scopes[specificationScopeId1].Should().BeOfType <SpecificationScope <object> >();

                context.Types.Should().NotBeEmpty();
                context.Types.Count.Should().Be(1);
                context.Types[specificationScopeId1].Should().Be(typeof(object));
            }
 public void Should_Initialize()
 {
     _ = new ScopeBuilderContext();
 }