Example #1
0
        public void Should_Add_AsCollectionRule_When_AsCollection_And_List()
        {
            var builder = new MemberSpecificationBuilder <object, List <int> >();

            var itemSpecification = new MemberSpecification <object, int>(x => x);

            builder.AsCollection(itemSpecification);

            AssertCollectionRuleAdded(builder.Commands, itemSpecification);
        }
Example #2
0
            public void Should_Add_AsCollectionRule_When_AsCollection()
            {
                var builder = new MemberSpecificationBuilder <object, IEnumerable <int> >();

                var itemSpecification = new MemberSpecification <object, int>(x => x);

                builder.AsCollection <object, IEnumerable <int>, int>(itemSpecification);

                Assert.Single(builder.Commands);
                Assert.IsType <AsCollectionRule <object, int> >(builder.Commands.Single());

                var command = (AsCollectionRule <object, int>)builder.Commands.Single();

                Assert.Equal("AsCollection", command.Name);
                Assert.Null(command.RuleSingleError);
                Assert.Same(itemSpecification, command.ItemSpecification);
                Assert.NotNull(command.ItemSpecification);
            }
Example #3
0
            public void Should_Add_AsCollectionRule_When_AsCollection_And_AdvancedSpecification()
            {
                var builder = new MemberSpecificationBuilder <object, IEnumerable <int> >();

                Predicate <int> innerPredicate = z => true;

                var itemSpecification = new MemberSpecification <object, int>(x => x.Valid(innerPredicate).SetSingleError("single_message"));

                builder.AsCollection <object, IEnumerable <int>, int>(itemSpecification);

                Assert.Single(builder.Commands);
                Assert.IsType <AsCollectionRule <object, int> >(builder.Commands.Single());

                var command = (AsCollectionRule <object, int>)builder.Commands.Single();

                Assert.Equal("AsCollection", command.Name);
                Assert.Null(command.RuleSingleError);
                Assert.Same(itemSpecification, command.ItemSpecification);
                Assert.NotNull(command.ItemSpecification);
                Assert.False(command.MemberValidator.IsOptional);
                Assert.Equal("single_message", command.MemberValidator.SingleError.Message);
                Assert.Same(innerPredicate, ((ValidRule <int>)command.MemberValidator.Rules.Single()).IsValid);
            }
Example #4
0
            public void Should_ThrowException_When_AsCollection_And_NullMemberSpecification()
            {
                var builder = new MemberSpecificationBuilder <object, IEnumerable <int> >();

                Assert.Throws <ArgumentNullException>(() => { builder.AsCollection <object, IEnumerable <int>, int>(null); });
            }