Пример #1
0
        public void TestCompareComparableTypes()
        {
            var testContext = _propertyTestData.GetContext();

            var x = new ConfigurationCollection <IChildElement>(null, testContext.ChildConfigurationCollectionPropertyDef,
                                                                testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            var customObjectA = testContext.GetChildElement("a");
            var configObjectA = x.AddCopy(customObjectA);

            var otherCustomObject = new ChildElementMock();

            otherCustomObject.Name  = customObjectA.Name;
            otherCustomObject.Value = customObjectA.Value;

            Assert.NotEqual(customObjectA, configObjectA);
            Assert.Equal(customObjectA, configObjectA, ConfigurationObjectComparer.Instance);

            Assert.Equal(configObjectA, configObjectA, ConfigurationObjectComparer.Instance);
            Assert.Equal(customObjectA, customObjectA, ConfigurationObjectComparer.Instance);

            Assert.Equal(otherCustomObject, configObjectA, ConfigurationObjectComparer.Instance);
            Assert.Equal(otherCustomObject, customObjectA, ConfigurationObjectComparer.Instance);

            Assert.NotEqual(customObjectA, null, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(customObjectA, null, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(otherCustomObject, null, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(configObjectA, null, ConfigurationObjectComparer.Instance);

            Assert.NotEqual(null, customObjectA, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(null, customObjectA, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(null, otherCustomObject, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(null, configObjectA, ConfigurationObjectComparer.Instance);
        }
Пример #2
0
        public void TestCopyValue_Object()
        {
            var root = _propertyTestData.GetContext().Configuration.ConfigurationRoot;

            var propertyInfo = typeof(IRootElement).GetProperty(nameof(IRootElement.ChildElementProperty), BindingFlags.Instance | BindingFlags.Public);
            var propertyDef  = new PropertyDef(propertyInfo, new ConfigurationObjectSettings());

            var child = new ChildElementMock()
            {
                Name  = "NAME-1",
                Value = 1
            };

            var copy = propertyDef.CopyValue <IChildElement>(propertyDef.Implementation, child, null, root);

            Assert.NotNull(copy);
            Assert.Equal(child.Name, copy.Name);
            Assert.Equal(child.Value, copy.Value);

            copy = propertyDef.CopyValue <IChildElement>(propertyDef.Implementation, null, null, root);

            Assert.Null(copy);
        }
Пример #3
0
        public void TestCompareMismatchedTypes()
        {
            var testContext = _propertyTestData.GetContext();

            var x = new ConfigurationCollection <IChildElement>(null, testContext.ChildConfigurationCollectionPropertyDef,
                                                                testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            var customObjectA = testContext.GetChildElement("a");
            var configObjectA = x.AddCopy(customObjectA);

            var otherCustomObject = new ChildElementMock();

            otherCustomObject.Name  = customObjectA.Name;
            otherCustomObject.Value = customObjectA.Value;

            var otherCustomObjectMultiInterface = new ChildElementMockMultiInterface();

            otherCustomObjectMultiInterface.Name  = customObjectA.Name;
            otherCustomObjectMultiInterface.Value = customObjectA.Value;

            Assert.NotEqual(customObjectA, otherCustomObjectMultiInterface);
            Assert.NotEqual((IChildElement)otherCustomObject, otherCustomObjectMultiInterface);
            Assert.NotEqual(configObjectA, otherCustomObjectMultiInterface);
        }