Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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");
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 8
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");
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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");
        }
        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");
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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);
        }