Index: test/DeltaShell/DeltaShell.Tests/DeltaShell.Tests.csproj
===================================================================
diff -u -r9f1efb36120427350936d48059c87c7e011657a9 -ra9ee3a5708adb2ab6d84460265bed2fd7dd59767
--- test/DeltaShell/DeltaShell.Tests/DeltaShell.Tests.csproj (.../DeltaShell.Tests.csproj) (revision 9f1efb36120427350936d48059c87c7e011657a9)
+++ test/DeltaShell/DeltaShell.Tests/DeltaShell.Tests.csproj (.../DeltaShell.Tests.csproj) (revision a9ee3a5708adb2ab6d84460265bed2fd7dd59767)
@@ -87,7 +87,7 @@
-
+
Fisheye: Tag a9ee3a5708adb2ab6d84460265bed2fd7dd59767 refers to a dead (removed) revision in file `test/DeltaShell/DeltaShell.Tests/Gui/Forms/PropertyGrid/PropertyResolverTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: test/DeltaShell/DeltaShell.Tests/Gui/Forms/PropertyGridView/PropertyResolverTest.cs
===================================================================
diff -u
--- test/DeltaShell/DeltaShell.Tests/Gui/Forms/PropertyGridView/PropertyResolverTest.cs (revision 0)
+++ test/DeltaShell/DeltaShell.Tests/Gui/Forms/PropertyGridView/PropertyResolverTest.cs (revision a9ee3a5708adb2ab6d84460265bed2fd7dd59767)
@@ -0,0 +1,317 @@
+using System;
+using System.Collections.Generic;
+using DelftTools.Shell.Gui;
+using DelftTools.TestUtils;
+using DelftTools.Utils.PropertyBag.Dynamic;
+using DeltaShell.Gui;
+using DeltaShell.Gui.Forms.PropertyGridView;
+using NUnit.Framework;
+using Rhino.Mocks;
+
+namespace DeltaShell.Tests.Gui.Forms.PropertyGrid
+{
+ [TestFixture]
+ public class PropertyResolverTest
+ {
+ # region GetObjectProperties tests
+
+ [Test]
+ public void GetObjectProperties_WhenNoPropertyInfoIsFound_ReturnNull()
+ {
+ // Assert
+ Assert.IsNull(PropertyResolver.GetObjectProperties(new List(), 1.0));
+ }
+
+ [Test]
+ public void GetObjectProperties_WhenOnePropertyInfoIsFound_ReturnDynamicPropertyBagContainingOnlyThatPropertiesObject()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>()
+ };
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new A());
+
+ // Assert
+ Assert.IsTrue(objectProperties is DynamicPropertyBag);
+ Assert.AreSame(typeof(SimpleProperties), ((DynamicPropertyBag) objectProperties).GetContentType());
+ }
+
+
+ [Test]
+ public void GetObjectProperties_WhenOnePropertyInfoIsFoundButAdditionalChecksFail_ReturnNull()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>()
+ {
+ AdditionalDataCheck = o => false
+ }
+ };
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new A());
+
+ // Assert
+ Assert.IsNull(objectProperties);
+ }
+
+ [Test]
+ public void GetObjectProperties_WhenTwoPropertyInfoAreFoundOneWithAdditionalCheckOneWithBetterType_ReturnPropertiesObjectMatchingAdditionCheck()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>()
+ {
+ AdditionalDataCheck = o => false
+ },
+ new PropertyInfo>() // specifically for C
+ };
+
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new C()); //we ask for C
+
+ // Assert
+ Assert.AreSame(typeof(SimpleProperties),
+ ((DynamicPropertyBag)objectProperties).GetContentType(), "we got A, expected C");
+ }
+
+ [Test]
+ public void GetObjectProperties_BasedOnDirectObjectTypeMatch_ReturnObjectPropertiesMatchingTypeD()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>(),
+ new PropertyInfo>()
+ };
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new D());
+
+ // Setup
+ Assert.IsTrue(objectProperties is DynamicPropertyBag);
+ Assert.AreSame(typeof(SimpleProperties), ((DynamicPropertyBag)objectProperties).GetContentType());
+ }
+
+ [Test]
+ public void GetObjectProperties_BasedOnDerivedObjectTypeMatch_ReturnObjectPropertiesForBaseClass()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>(),
+ new PropertyInfo>()
+ };
+
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new D());
+
+ // Assert
+ Assert.IsTrue(objectProperties is DynamicPropertyBag);
+ Assert.AreSame(typeof(SimpleProperties), ((DynamicPropertyBag)objectProperties).GetContentType());
+ }
+
+ [Test]
+ public void GetObjectProperties_BasedOnDerivedObjectTypeMatchAndAdditionalDataCheck_ReturnObjectPropertiesForBaseClassMatchingAdditionCheck()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>
+ {
+ AdditionalDataCheck = o => true
+ },
+ new PropertyInfo>
+ {
+ AdditionalDataCheck = o => true
+ }
+ };
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new D());
+
+ // Assert
+ Assert.IsTrue(objectProperties is DynamicPropertyBag);
+ Assert.AreSame(typeof(SimpleProperties), ((DynamicPropertyBag)objectProperties).GetContentType());
+ }
+
+ [Test]
+ public void GetObjectProperties_BasedOnMatchingAdditionalDataCheck_ReturnMatchingWithAdditionalDataCheck()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>
+ {
+ AdditionalDataCheck = o => true
+ }, // Additional data check which will be matched
+ new PropertyInfo>()
+ };
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new B());
+
+ // Assert
+ Assert.IsTrue(objectProperties is DynamicPropertyBag);
+ Assert.AreSame(typeof(SimpleProperties), ((DynamicPropertyBag)objectProperties).GetContentType());
+ }
+
+ [Test]
+ public void GetObjectProperties_BasedOnMismatchingAdditionalDataCheck_ReturnFallBackPropertiesObject()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>
+ {
+ AdditionalDataCheck = o => false
+ }, // Additional data check which will not be matched
+ new PropertyInfo>()
+ };
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new B());
+
+ // Assert
+ Assert.IsTrue(objectProperties is DynamicPropertyBag);
+ Assert.AreSame(typeof(OtherSimpleProperties), ((DynamicPropertyBag)objectProperties).GetContentType());
+ }
+
+ [Test]
+ public void GetObjectProperties_BasedOnDerivedPropertyTypeMatch_ReturnDerivedObjectPropertiesClass()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>(),
+ new PropertyInfo>()
+ };
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new B());
+
+ // Assert
+ Assert.IsTrue(objectProperties is DynamicPropertyBag);
+ Assert.AreSame(typeof(DerivedSimpleProperties), ((DynamicPropertyBag)objectProperties).GetContentType());
+ }
+
+ [Test]
+ public void GetObjectProperties_BasedOnDerivedPropertyTypeMatchAndAdditionalDataCheck_ReturnDerivedObjectProperties()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>
+ {
+ AdditionalDataCheck = o => true
+ },
+ new PropertyInfo>
+ {
+ AdditionalDataCheck = o => true
+ }
+ };
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new B());
+
+ // Assert
+ Assert.IsTrue(objectProperties is DynamicPropertyBag);
+ Assert.AreSame(typeof(DerivedSimpleProperties), ((DynamicPropertyBag)objectProperties).GetContentType());
+ }
+
+ [Test]
+ public void GetObjectProperties_WhenMultiplePropertyObjectsAreFound_ReturnNull()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>(),
+ new PropertyInfo>()
+ };
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new B());
+ Assert.IsNull(objectProperties);
+ }
+
+ [Test]
+ public void GetObjectProperties_TakingAllPropertyInfoPropertiesIntoAccount_ReturnDerivedObjectPropertiesMatchingDataCheck()
+ {
+ // Setup
+ var propertyInfos = new List
+ {
+ new PropertyInfo>
+ {
+ AdditionalDataCheck = o => true
+ }, // D is not assignable from C: no candidate
+ new PropertyInfo>
+ {
+ AdditionalDataCheck = o => true
+ }, // A is less specific than C: candidate but not the most specific one
+ new PropertyInfo>
+ {
+ AdditionalDataCheck = o => false
+ }, // Additional data check is false: no candidate
+ new PropertyInfo>
+ {
+ AdditionalDataCheck = o => true
+ }, // SimpleProperties is less specific than DerivedSimpleProperties: candidate but not the most specific one
+ new PropertyInfo>
+ {
+ AdditionalDataCheck = o => true
+ } // Most specific!
+ };
+
+ // Call
+ var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new C());
+
+ // Assert
+ Assert.IsTrue(objectProperties is DynamicPropertyBag);
+ Assert.AreSame(typeof(DerivedSimpleProperties), ((DynamicPropertyBag)objectProperties).GetContentType());
+ }
+
+ # endregion
+
+ # region Nested types
+
+ /*
+ * A
+ * ___^___
+ * | |
+ * B C
+ * |
+ * D
+ *
+ *
+ *
+ * SimpleProperties OtherSimpleProperties
+ * ^
+ * |
+ * DerivedSimpleProperties
+ *
+ */
+
+ internal class A {}
+
+ private class B : A {}
+
+ internal class C : A {}
+
+ private class D : C {}
+
+ internal class SimpleProperties : ObjectProperties {}
+
+ private class DerivedSimpleProperties : SimpleProperties {}
+
+ private class OtherSimpleProperties : ObjectProperties {}
+
+ # endregion
+ }
+}
\ No newline at end of file