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_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 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 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_Build_RuleCommandScope_When_RuleTemplate_WithoutArgs_And_CustomError(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;

                Specification <TestClass> specification = m => appendSetupCommands(appendContentCommands(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(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().BeEmpty();
                }
            }
            public void Should_Build_RuleCommandScope_When_RuleTemplate_WithArgs(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;

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

                Specification <TestClass> specification = m => appendSetupCommands(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(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().BeSameAs(args);
                error.Codes.Should().BeEmpty();
            }
            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);
            }