Esempio n. 1
0
        public void PropertySet_ChildSet_ExpectedChildPropertyNotNull_ActualNull()
        {
            var expected = new TestObjectWithChildSet
            {
                ValidationProperty = "value",
                Child = new TestObjectWithChildSet {
                    ValidationProperty = "cildvalue"
                }
            };
            var actual = new TestObjectWithChildSet
            {
                ValidationProperty = "value",
                Child = new TestObjectWithChildSet {
                    ValidationProperty = null
                }
            };
            var messageCheck = new MessageCheck("Property Set is not equal");

            messageCheck.AddObjectLine("cildvalue", "Null", "Child.ValidationProperty");
            var ex = Assert.Throws(typeof(AssertionFailedException),
                                   () => Assert.That(actual, Entity.EqualTo(expected)));

            Console.WriteLine(ex.Message);
            messageCheck.Check(ex);
        }
        public void BlogExample_PropertySet()
        {
            var expected = new BlogExampleObject
            {
                ChildObject = new TestObject {
                    Value = "ChildObjectValue1"
                },
                ChildObjectList = new List <TestObject> {
                    new TestObject {
                        Value = "ListObject1"
                    }
                },
                IgnoredProerty    = "1",
                ProcessedProperty = "Test"
            };
            var actual = new BlogExampleObject
            {
                ChildObject = new TestObject {
                    Value = "ChildObjectValue2"
                },
                ChildObjectList = new List <TestObject> {
                    new TestObject {
                        Value = "ListObject2"
                    }
                },
                IgnoredProerty    = "2",
                Parent            = null,
                CreatedDate       = DateTime.Now,
                ProcessedProperty = "Testprocessed"
            };

            Assert.That(actual, Entity.EqualTo(expected));
        }
Esempio n. 3
0
        public void PropertySet_ChildList()
        {
            var expected = new TestObjectWithChildList
            {
                Child = new List <TestObject> {
                    new TestObject {
                        Value = "value1"
                    }, new TestObject {
                        Value = "value2"
                    }
                }
            };
            var actual = new TestObjectWithChildList
            {
                Child = new List <TestObject> {
                    new TestObject {
                        Value = "value1"
                    }, new TestObject {
                        Value = "value2"
                    }
                }
            };

            Assert.That(actual, Entity.EqualTo(expected));
        }
Esempio n. 4
0
        public void ListContains_PropertySet_Failure_Closestmatch()
        {
            var expected = new SimpleTestObject
            {
                Id        = 5,
                FirstName = "John",
                LastName  = "Doe"
            };
            var actual1 = new SimpleTestObject
            {
                Id        = 5,
                FirstName = "John",
                LastName  = "Foo"
            };
            var actual2 = new SimpleTestObject
            {
                Id        = 5,
                FirstName = "Arabella",
                LastName  = "Monte"
            };
            List <SimpleTestObject> list = new List <SimpleTestObject>();

            list.Add(actual1);
            list.Add(actual2);
            Assert.That(list, Entity.List.Contains(expected, OnListContainsFailure.DisplayClosestMatch), "List");
        }
Esempio n. 5
0
        public void PropertySet_ChildList_ItemDifference()
        {
            var expected = new TestObjectWithChildList {
                Child = new List <TestObject> {
                    new TestObject {
                        Value = "value"
                    }
                }
            };
            var actual = new TestObjectWithChildList
            {
                Child = new List <TestObject> {
                    new TestObject {
                        Value = "different"
                    }
                }
            };
            var messageCheck = new MessageCheck("Property Set is not equal");

            messageCheck.AddPropertyLine("value", "different", "Child[0].Value");
            var ex = Assert.Throws(typeof(AssertionFailedException),
                                   () => Assert.That(actual, Entity.EqualTo(expected)));

            messageCheck.Check(ex);
        }
Esempio n. 6
0
        public void ListContains_PropertySet()
        {
            var expected = new TestObjectWithChildSet
            {
                ValidationProperty = "value",
                Child = new TestObjectWithChildSet {
                    ValidationProperty = "cildvalue"
                }
            };
            var actual = new TestObjectWithChildSet
            {
                ValidationProperty = "value",
                Child = new TestObjectWithChildSet {
                    ValidationProperty = "cildvalue"
                }
            };
            List <TestObjectWithChildSet> list = new List <TestObjectWithChildSet>();

            for (int i = 0; i < 100000; i++)
            {
                var rand = new TestObjectWithChildSet
                {
                    ValidationProperty = Guid.NewGuid().ToString("n"),
                    Child = new TestObjectWithChildSet {
                        ValidationProperty = Guid.NewGuid().ToString()
                    }
                };
                list.Add(rand);
            }

            list.Add(actual);
            Assert.That(list, Entity.List.Contains(expected));
        }
Esempio n. 7
0
        public void PropertySet_ChildSet_SecondLevelDifference()
        {
            var expected = new TestObjectWithChildSet
            {
                ValidationProperty = "value",
                Child = new TestObjectWithChildSet {
                    ValidationProperty = "cildvalue"
                }
            };
            var actual = new TestObjectWithChildSet
            {
                ValidationProperty = "value",
                Child = new TestObjectWithChildSet {
                    ValidationProperty = "cildvalue!"
                }
            };
            var messageCheck = new MessageCheck("Property Set is not equal");

            messageCheck.AddPropertyLine(expected.Child.ValidationProperty, actual.Child.ValidationProperty,
                                         "Child.ValidationProperty");

            var ex = Assert.Throws(typeof(AssertionFailedException),
                                   () => Assert.That(actual, Entity.EqualTo(expected)));

            messageCheck.Check(ex);
        }
Esempio n. 8
0
        public void PropertySet_ExpectingNullObject()
        {
            TestObjectCustomValidation expected = null;
            var ex = Assert.Throws(typeof(ArgumentNullException), () => Entity.EqualTo(expected));

            Console.WriteLine(ex.Message);
            Assert.That(ex.Message, Is.EqualTo("Expected can't be null\r\nParameter name: expected"),
                        "Assertion message");
        }
Esempio n. 9
0
        public void PropertySet_IgnoreValidationIfDefault()
        {
            var expected = new TestObjectIgnoreValidation();
            var actual   = new TestObjectIgnoreValidation {
                Value = "ValidationCustom"
            };

            Assert.That(actual, Entity.EqualTo(expected));
        }
Esempio n. 10
0
        public void PropertySet_ValidateWithProperty_IgnoreIfDefault()
        {
            var expected = new TestObjectCustomValidation();
            var actual   = new TestObjectCustomValidation {
                CustomValidation = "ValidationCustom"
            };

            Assert.That(actual, Entity.EqualTo(expected));
        }
Esempio n. 11
0
        public void PropertySet_ChildList_ExpectingNullList_ActualNull()
        {
            var expected = new TestObjectWithChildList {
                Child = null
            };
            var actual = new TestObjectWithChildList {
                Child = null
            };

            Assert.That(actual, Entity.EqualTo(expected));
        }
Esempio n. 12
0
        public void PropertySet_IgnoreValidation()
        {
            var expected = new TestObjectIgnoreValidation {
                IgnoredField = "Validation"
            };
            var actual = new TestObjectIgnoreValidation {
                IgnoredField = "ValidationCustom"
            };

            Assert.That(actual, Entity.EqualTo(expected));
        }
Esempio n. 13
0
        public void PropertySet_AliasTest()
        {
            RuleStorage rules      = RuleStorage.Instance;
            Type        type1      = typeof(TestAlias1::AliasTestPack.Class1);
            var         type1Rules = rules.GetValidationRules(type1);

            Assert.That(type1Rules.ValidationStrategyBuilders.Any(x => x.Key.Name == "TestPack1NotNull"), Is.True, "type1 rule notNull");
            Type type2      = typeof(TestAlias2::AliasTestPack.Class1);
            var  type2Rules = rules.GetValidationRules(type2);

            Assert.That(type2Rules.ValidationStrategyBuilders.Any(x => x.Key.Name == "TestPack1NotNull"), Is.False, "type1 rule notNull present");
            Assert.That(type2Rules.ValidationStrategyBuilders.Any(x => x.Key.Name == "TestPack2NotNull"), Is.True, "type1 rule notNull present");
        }
Esempio n. 14
0
        public void PropertySet_ActualAttributes_GreaterThan()
        {
            var expected = new TestObjectActualValidationAttributes
            {
                IdGreaterThanZero = 5
            };
            var actual = new TestObjectActualValidationAttributes
            {
                IdGreaterThanZero = 5,
                IdNotNull         = new object()
            };

            Assert.That(actual, Entity.EqualTo(expected));
        }
Esempio n. 15
0
        public void PropertySet_IgnoreValidationIfDefault_StringAndDateTime()
        {
            var expected = new TestObjectIgnoreDefaultValidation {
                StringValue1 = "", StringValue2 = null
            };
            var actual = new TestObjectIgnoreDefaultValidation
            {
                StringValue1 = "val",
                StringValue2 = "test",
                DateFiled    = DateTime.Now
            };

            Assert.That(actual, Entity.EqualTo(expected));
        }
Esempio n. 16
0
        public void PropertySet_ExpectingNotNullObject_ActualNull()
        {
            var expected = new TestObjectCustomValidation {
                CustomValidation = "Validation"
            };
            TestObjectCustomValidation actual = null;
            var messageCheck = new MessageCheck("Property Set is not equal");

            messageCheck.AddObjectLine(typeof(TestObjectCustomValidation).ToString(), "Null");
            var ex = Assert.Throws(typeof(AssertionFailedException),
                                   () => Assert.That(actual, Entity.EqualTo(expected)));

            Console.WriteLine(ex.Message);
            messageCheck.Check(ex);
        }
Esempio n. 17
0
        public void PropertySet_ChildSet_ExpectedChildNull_ActualNull()
        {
            var expected = new TestObjectWithChildSet
            {
                ValidationProperty = "value",
                Child = null
            };
            var actual = new TestObjectWithChildSet
            {
                ValidationProperty = "value",
                Child = null
            };

            Assert.That(actual, Entity.EqualTo(expected));
        }
Esempio n. 18
0
        public void PropertySet_ValidateWithProperty_Negative()
        {
            var expected = new TestObjectCustomValidation {
                CustomValidation = "Validation"
            };
            var actual = new TestObjectCustomValidation {
                CustomValidation = "Validation"
            };
            var messageCheck = new MessageCheck("Property Set is not equal");

            messageCheck.AddPropertyLine(expected.ValidationCustomValidation, actual.CustomValidation,
                                         "CustomValidation");
            var ex = Assert.Throws(typeof(AssertionFailedException),
                                   () => Assert.That(actual, Entity.EqualTo(expected)));

            messageCheck.Check(ex);
        }
        public void PropertySet_ByInterface_Failure()
        {
            var object1 = new TestObjectByInterface1
            {
                ChildList =
                    new List <TestObjectWithChildSet>
                {
                    new TestObjectWithChildSet
                    {
                        Child = new TestObjectWithChildSet {
                            ValidationProperty = "valueExp"
                        }
                    }
                },
                CustomValidation = "ValidationPropertyC",
                Object1Value     = "Object1Value",
                Value1           = "Value1"
            };

            var object2 = new TestObjectByInterface2
            {
                ChildList =
                    new List <TestObjectWithChildSet>
                {
                    new TestObjectWithChildSet
                    {
                        Child = new TestObjectWithChildSet {
                            ValidationProperty = "value"
                        }
                    }
                },
                CustomValidation = "ValidationProperty",
                Object1Value     = "Object2Value",
                Value1           = "Value1",
                Object2Value     = "Value2"
            };
            var messageCheck = new MessageCheck("Property Set is not equal");

            messageCheck.AddPropertyLine("valueExp", "value", "ChildList[0].Child.ValidationProperty");
            messageCheck.AddPropertyLine("ValidationPropertyCCustom", "ValidationProperty", "CustomValidation");
            var ex = Assert.Throws(typeof(AssertionFailedException),
                                   () =>
                                   Assert.That(object2, Entity.EqualTo(object1).ByInterface(typeof(ITestObject))));

            messageCheck.Check(ex);
        }
Esempio n. 20
0
        public void PropertySet_ValidateWithProperty_IncorrectProperty()
        {
            var expected = new TestObjectCustomValidationImproperAttributeUsage {
                CustomValidation = "Validation"
            };
            var actual = new TestObjectCustomValidationImproperAttributeUsage {
                CustomValidation = "ValidationCustom"
            };
            var ex = Assert.Throws(typeof(ImproperAttributeUsageException),
                                   () => Assert.That(actual, Entity.EqualTo(expected)));

            Console.WriteLine(ex.Message);
            Assert.That(ex.Message,
                        Is.EqualTo(
                            "ValidateWithProperty for property CustomValidation was pointing at inexisting property ValidationCustomValidation1"),
                        "Assertion message");
        }
Esempio n. 21
0
        public void PropertySet_ActualAttributes_GreaterThan_ImproperUsage_Null()
        {
            var expected = new TestObjectImproperGreaterThan
            {
                GreaterThanValue = null
            };
            var actual = new TestObjectImproperGreaterThan
            {
                GreaterThanValue = null
            };
            var ex = Assert.Throws(typeof(ImproperAttributeUsageException),
                                   () => Assert.That(actual, Entity.EqualTo(expected)));

            Console.WriteLine(ex.Message);
            Assert.That(ex.Message,
                        Is.EqualTo("ValidateActualGreaterThanAttribute should be defined only on numeric properties"),
                        "Assertion message");
        }
Esempio n. 22
0
        public void PropertySet_ActualAttributes_NotNull_Failure()
        {
            var expected = new TestObjectActualValidationAttributes
            {
                IdGreaterThanZero = 5
            };
            var actual = new TestObjectActualValidationAttributes
            {
                IdGreaterThanZero = 5
            };
            var messageCheck = new MessageCheck("Property Set is not equal");

            messageCheck.AddPropertyLine("Not Null", "Null", "IdNotNull");
            var ex = Assert.Throws(typeof(AssertionFailedException),
                                   () => Assert.That(actual, Entity.EqualTo(expected)));

            messageCheck.Check(ex);
        }
        public void PropertySet_ByInterface_IncompatibleInterface()
        {
            var expected = new TestObjectCustomValidation {
                CustomValidation = "Validation"
            };
            var actual = new TestObjectCustomValidation {
                CustomValidation = "Validation"
            };
            var ex = Assert.Throws(typeof(ImproperTypeUsageException),
                                   () =>
                                   Assert.That(actual,
                                               Entity.EqualTo(expected).ByInterface(typeof(TestObjectWithChildList))));

            Console.WriteLine(ex.Message);
            Assert.That(ex.Message,
                        Is.EqualTo(
                            "Could not get property Child from object of type UsageExample.PropertySetValidatorTests.TestObjects.TestObjectCustomValidation"),
                        "Assertion message");
        }
Esempio n. 24
0
        public void PropertySet_ChildList_ExpectingNotNullList_ActualNull()
        {
            var expected = new TestObjectWithChildList {
                Child = new List <TestObject> {
                    new TestObject()
                }
            };
            var actual = new TestObjectWithChildList {
                Child = null
            };
            var messageCheck = new MessageCheck("Property Set is not equal");

            messageCheck.AddObjectLine(typeof(List <TestObject>).ToString(), "Null", "Child");

            var ex = Assert.Throws(typeof(AssertionFailedException),
                                   () => Assert.That(actual, Entity.EqualTo(expected)));

            Console.WriteLine(ex.Message);
            messageCheck.Check(ex);
        }
Esempio n. 25
0
        public void PropertySet_ChildList_ExpectingLessThanActual()
        {
            var expected = new TestObjectWithChildList {
                Child = new List <TestObject> {
                    new TestObject()
                }
            };
            var actual = new TestObjectWithChildList {
                Child = new List <TestObject> {
                    new TestObject(), new TestObject()
                }
            };
            var messageCheck = new MessageCheck("Property Set is not equal");

            messageCheck.AddPropertyLine("1", "2", "Child.Count");
            var ex = Assert.Throws(typeof(AssertionFailedException),
                                   () => Assert.That(actual, Entity.EqualTo(expected)));

            messageCheck.Check(ex);
        }
Esempio n. 26
0
        public void ListContains_PropertySet_Failure()
        {
            var expected = new TestObjectWithChildSet
            {
                ValidationProperty = "value",
                Child = new TestObjectWithChildSet {
                    ValidationProperty = "cildvalue"
                }
            };
            var actual = new TestObjectWithChildSet
            {
                ValidationProperty = "value",
                Child = new TestObjectWithChildSet {
                    ValidationProperty = "cildvalue1"
                }
            };
            List <TestObjectWithChildSet> list = new List <TestObjectWithChildSet>();

            list.Add(actual);
            Assert.That(list, Entity.List.Contains(expected, OnListContainsFailure.DisplayExpectedAndActualList), "List");
        }
        public void PropertySet_ByInterface()
        {
            var object1 = new TestObjectByInterface1
            {
                ChildList =
                    new List <TestObjectWithChildSet>
                {
                    new TestObjectWithChildSet
                    {
                        Child = new TestObjectWithChildSet {
                            ValidationProperty = "value"
                        }
                    }
                },
                CustomValidation = "ValidationProperty",
                Object1Value     = "Object1Value",
                Value1           = "Value1"
            };

            var object2 = new TestObjectByInterface2
            {
                ChildList =
                    new List <TestObjectWithChildSet>
                {
                    new TestObjectWithChildSet
                    {
                        Child = new TestObjectWithChildSet {
                            ValidationProperty = "value"
                        }
                    }
                },
                CustomValidation = "ValidationPropertyCustom",
                Object1Value     = "Object2Value",
                Value1           = "Value1",
                Object2Value     = "Value2"
            };

            Assert.That(object2, Entity.EqualTo(object1).ByInterface(typeof(ITestObject)));
        }