public void CreateOpositeValue()
        {
            var validation = new DefinitionOfValid <PrimaryType>();

            validation.Add(p => p.AnBooleanValue).Value(true);

            var strategy = validation.CreateViolation(p => p.AnBooleanValue, ViolationType.OppositeValue);

            var items = Common.CreateItems(100, strategy);

            Assert.IsTrue(items.All(p => p.AnBooleanValue == false));
        }
Esempio n. 2
0
        public void CreateIsRequiredValidation()
        {
            var validation = new DefinitionOfValid <PrimaryType>();

            validation.Add(p => p.AnIntegerValue)
            .Min(50)
            .Max(100);

            var strategy = validation.CreateViolation(nameof(PrimaryType.AnIntegerValue), ViolationType.OppositeValue);

            var item = Common.CreateItem(strategy);

            Assert.IsTrue(item.AnIntegerValue == 0);
        }
Esempio n. 3
0
        public void CreateMinValidation()
        {
            var validation = new DefinitionOfValid <PrimaryType>();

            validation.Add(p => p.AnIntegerValue)
            .Min(50)
            .Max(100);

            var strategy = validation.CreateViolation(nameof(PrimaryType.AnIntegerValue), ViolationType.MinimumValue);

            var items = Common.CreateItems(100, strategy);

            Assert.IsTrue(items.All(p => p.AnIntegerValue < 50 || p.AnIntegerValue > 100));
        }
Esempio n. 4
0
        public void CreateMaxValidationByExpression()
        {
            var validation = new DefinitionOfValid <Person>();

            validation.Add(p => p.Age)
            .Min(10)
            .Max(120);

            var strategy = validation.CreateViolation(p => p.Age, ViolationType.MaximumValue);

            var items = Common.CreateItems(100, strategy);

            Assert.IsTrue(items.All(p => p.Age < 10 || p.Age > 120));
        }
Esempio n. 5
0
        public void CreateForMaxValue()
        {
            var validation = new DefinitionOfValid <Person>();

            validation.Add(p => p.Age)
            .Min(10)
            .Max(120);

            var strategy = validation.CreateViolation(nameof(Person.Age), ViolationType.MaximumValue);

            var item = Common.CreateItem(strategy);

            Assert.IsTrue(item.Age > 100);
        }
        public void CreateForMinValue()
        {
            var validation = new DefinitionOfValid <Person>();

            validation.Add(p => p.FirstName)
            .NotNull()
            .MaxLength(150)
            .MinLength(10);

            var strategy = validation.CreateViolation(p => p.FirstName, ViolationType.MinimumLength);

            var item = Common.CreateItem(strategy);

            Assert.IsTrue(item.FirstName.Length < 10);
        }
        public void CreateForNullValue()
        {
            var validation = new DefinitionOfValid <Person>();

            validation.Add(p => p.FirstName)
            .NotNull()
            .MaxLength(150)
            .MinLength(5);

            var strategy = validation.CreateViolation(p => p.FirstName, ViolationType.Presence);

            var item = Common.CreateItem(strategy);

            Assert.IsTrue(String.IsNullOrEmpty(item.FirstName));
        }