Exemple #1
0
        public void Should_Add_AsNullableRule_When_AsNullable()
        {
            var builder = new MemberSpecificationBuilder <object, int?>();

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

            builder.AsNullable(memberSpecification);

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

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

            Assert.Equal("AsNullable", command.Name);
            Assert.Null(command.RuleSingleError);
            Assert.Same(memberSpecification, command.MemberSpecification);
        }
Exemple #2
0
            public void Should_Add_AsNullableRule_When_AsNullable_And_AdvancedSpecification()
            {
                var builder = new MemberSpecificationBuilder <object, int?>();

                Predicate <int> innerPredicate = z => true;

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

                builder.AsNullable(memberSpecification);

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

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

                Assert.Equal("AsNullable", command.Name);
                Assert.Null(command.RuleSingleError);
                Assert.Same(memberSpecification, command.MemberSpecification);
                Assert.NotNull(command.MemberSpecification);
                Assert.Equal("single_message", command.MemberValidator.SingleError.Message);
                Assert.Same(innerPredicate, ((ValidRule <int>)command.MemberValidator.Rules.Single()).IsValid);
            }
Exemple #3
0
            public void Should_ThrowException_When_AsNullable_And_NullMemberSpecification()
            {
                var builder = new MemberSpecificationBuilder <object, int?>();

                Assert.Throws <ArgumentNullException>(() => { builder.AsNullable(null); });
            }