Example #1
0
        public void Test_MultipleBrokenRules()
        {
            var builder = new ValidationBuilder(typeof(FooE));
            var ruleSet = builder.LowLevelRules;

            var foo = new FooE {
                Name = "Robert"
            };

            // should fail both
            var result = ruleSet.Test(foo);

            Assert.IsFalse(result.Success);
            Assert.AreEqual(2, result.Reasons.Length);

            // should fail only Name length
            foo.Color = "Blue";
            result    = ruleSet.Test(foo);
            Assert.IsFalse(result.Success);
            Assert.AreEqual(1, result.Reasons.Length);

            // should fail neither
            foo.Name = "Bot";
            result   = ruleSet.Test(foo);
            Assert.IsTrue(result.Success);
            Assert.AreEqual(0, result.Reasons.Length);

            // should fail Color required
            foo.Color = null;
            result    = ruleSet.Test(foo);
            Assert.IsFalse(result.Success);
            Assert.AreEqual(1, result.Reasons.Length);
        }
Example #2
0
		public void Test_Validate_validation_disabled_via_inherited_attribute()
		{
			try
			{
				var foo = new FooE() { Name = "Bethany" };
				var validator = new DomainObjectValidator();
				validator.Validate(foo);
			}
			catch (EntityValidationException)
			{
				Assert.Fail("validation was disabled and should not have failed");
			}
		}
		public void Test_MultipleBrokenRules()
		{
			var builder = new ValidationBuilder(typeof(FooE));
			var ruleSet = builder.LowLevelRules;

			var foo = new FooE {Name = "Robert"};

			// should fail both
			var result = ruleSet.Test(foo);
			Assert.IsFalse(result.Success);
			Assert.AreEqual(2, result.Reasons.Length);

			// should fail only Name length
			foo.Color = "Blue";
			result = ruleSet.Test(foo);
			Assert.IsFalse(result.Success);
			Assert.AreEqual(1, result.Reasons.Length);

			// should fail neither
			foo.Name = "Bot";
			result = ruleSet.Test(foo);
			Assert.IsTrue(result.Success);
			Assert.AreEqual(0, result.Reasons.Length);

			// should fail Color required
			foo.Color = null;
			result = ruleSet.Test(foo);
			Assert.IsFalse(result.Success);
			Assert.AreEqual(1, result.Reasons.Length);
		}
		public void Test_Validate_validation_disabled_via_inherited_attribute()
		{
			try
			{
				var foo = new FooE() { Name = "Bethany" };
				var validator = new DomainObjectValidator();
				validator.Validate(foo);
			}
			catch (EntityValidationException)
			{
				Assert.Fail("validation was disabled and should not have failed");
			}
		}