public void CallsFactoriesFromTheFactoryMap()
        {
            var o = new NamedTypeWithAttributedProperty
            {
                Name  = "Ralph",
                Value = new TypeWithAttributedProperty
                {
                    PropertyWithTestAttribute    = "TestValue",
                    PropertyWithoutTestAttribute = "ShouldBeIgnored"
                }
            };

            var map = new ObjectGraphFactoryMap(true);

            map[typeof(TypeWithAttributedProperty)] = new ExtractAttributeObjectGraphFactory();

            var factory = new PublicPropertyObjectGraphFactory();
            var graph   = factory.CreateObjectGraph(o, map);

            var expected =
                @"RootObjectValue = 'Microsoft.Test.AcceptanceTests.ObjectComparison.ObjectGraphFactoryTests+NamedTypeWithAttributedProperty' Type=Microsoft.Test.AcceptanceTests.ObjectComparison.ObjectGraphFactoryTests+NamedTypeWithAttributedProperty
    ValueValue = 'Microsoft.Test.AcceptanceTests.ObjectComparison.TypeWithAttributedProperty' Type=Microsoft.Test.AcceptanceTests.ObjectComparison.TypeWithAttributedProperty
        PropertyWithTestAttributeValue = 'TestValue' Type=System.String
    NameValue = 'Ralph' Type=System.String";
            var actual = TestHelpers.StringFromGraph(graph);

            Assert.Equal(expected, actual.Trim());
        }
示例#2
0
        public void CustomFactoryMismatch()
        {
            TypeWithAttributedProperty leftObject = new TypeWithAttributedProperty()
            {
                PropertyWithoutTestAttribute = "Should not be compared",
                PropertyWithTestAttribute    = "Should be compared",
            };

            TypeWithAttributedProperty rightObject = new TypeWithAttributedProperty()
            {
                PropertyWithoutTestAttribute = "Should not be compared - so this is different",
                PropertyWithTestAttribute    = "Should be compared - and should fail because its different",
            };

            ExtractAttributeObjectGraphFactory factory = new ExtractAttributeObjectGraphFactory();
            ObjectComparer comparer = new ObjectComparer(factory);

            Assert.False(comparer.Compare(leftObject, rightObject), "Custom compare passed when it should have failed");
        }
        public void CustomFactoryMatch()
        {
            TypeWithAttributedProperty leftObject = new TypeWithAttributedProperty()
            {
                PropertyWithoutTestAttribute = "Should not be compared",
                PropertyWithTestAttribute    = "Should be compared",
            };

            TypeWithAttributedProperty rightObject = new TypeWithAttributedProperty()
            {
                PropertyWithoutTestAttribute = "Should not be compared - so this is different",
                PropertyWithTestAttribute    = "Should be compared",
            };

            ExtractAttributeObjectGraphFactory factory = new ExtractAttributeObjectGraphFactory();
            ObjectGraphComparer comparer = new ObjectGraphComparer();
            var left  = factory.CreateObjectGraph(leftObject);
            var right = factory.CreateObjectGraph(rightObject);

            Assert.True(comparer.Compare(left, right), "Custom compare failed");
        }