Index: Core/Common/src/Core.Common.Controls/Dialogs/DialogBase.cs =================================================================== diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Controls/Dialogs/DialogBase.cs (.../DialogBase.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f) +++ Core/Common/src/Core.Common.Controls/Dialogs/DialogBase.cs (.../DialogBase.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -60,24 +60,24 @@ { private readonly int minWidth; private readonly int minHeight; - private readonly IWin32Window owner; + private readonly IWin32Window dialogParent; /// /// Constructs a new . /// - /// The owner of the dialog. + /// The owner of the dialog. /// The icon to show in the control box. /// The minimum width of the dialog. /// The minimum height of the dialog. - /// Thrown when or is null. + /// Thrown when or is null. /// Thrown when or is not greater than 0. - protected DialogBase(IWin32Window owner, Icon icon, int minWidth, int minHeight) + protected DialogBase(IWin32Window dialogParent, Icon icon, int minWidth, int minHeight) { InitializeComponent(); - if (owner == null) + if (dialogParent == null) { - throw new ArgumentNullException("owner"); + throw new ArgumentNullException("dialogParent"); } if (icon == null) @@ -95,7 +95,7 @@ throw new ArgumentException("The minimum height of the dialog should be greater than 0"); } - this.owner = owner; + this.dialogParent = dialogParent; this.minWidth = minWidth; this.minHeight = minHeight; @@ -109,7 +109,7 @@ /// A . public new DialogResult ShowDialog() { - return base.ShowDialog(owner); + return base.ShowDialog(dialogParent); } protected override void OnLoad(EventArgs e) Index: Core/Common/src/Core.Common.Controls/Dialogs/ExceptionDialog.cs =================================================================== diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Controls/Dialogs/ExceptionDialog.cs (.../ExceptionDialog.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f) +++ Core/Common/src/Core.Common.Controls/Dialogs/ExceptionDialog.cs (.../ExceptionDialog.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -44,9 +44,9 @@ /// /// Constructs a new . /// - /// The owner of the dialog. + /// The owner of the dialog. /// The exception to show in the dialog. - public ExceptionDialog(IWin32Window owner, Exception exception) : base(owner, Resources.bug__exclamation, 470, 200) + public ExceptionDialog(IWin32Window dialogParent, Exception exception) : base(dialogParent, Resources.bug__exclamation, 470, 200) { InitializeComponent(); Index: Core/Common/src/Core.Common.Gui/Forms/MessageWindow/MessageWindowDialog.cs =================================================================== diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Gui/Forms/MessageWindow/MessageWindowDialog.cs (.../MessageWindowDialog.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f) +++ Core/Common/src/Core.Common.Gui/Forms/MessageWindow/MessageWindowDialog.cs (.../MessageWindowDialog.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -33,9 +33,9 @@ /// /// Constructs a new . /// - /// The owner of the dialog. + /// The owner of the dialog. /// The text to show in the dialog. - public MessageWindowDialog(IWin32Window owner, string text) : base(owner, Resources.application_import_blue1, 200, 150) + public MessageWindowDialog(IWin32Window dialogParent, string text) : base(dialogParent, Resources.application_import_blue1, 200, 150) { InitializeComponent(); Index: Core/Common/src/Core.Common.Gui/Forms/Options/OptionsDialog.cs =================================================================== diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Gui/Forms/Options/OptionsDialog.cs (.../OptionsDialog.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f) +++ Core/Common/src/Core.Common.Gui/Forms/Options/OptionsDialog.cs (.../OptionsDialog.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -30,11 +30,19 @@ namespace Core.Common.Gui.Forms.Options { + /// + /// Dialog for edition user settings. + /// public partial class OptionsDialog : DialogBase { private readonly ApplicationSettingsBase userSettings; - public OptionsDialog(IWin32Window owner, ApplicationSettingsBase userSettings) : base(owner, Resources.OptionsHS1, 430, 170) + /// + /// Initializes a new instance of the class. + /// + /// The dialog parent for which this should be shown on top. + /// The user settings. + public OptionsDialog(IWin32Window dialogParent, ApplicationSettingsBase userSettings) : base(dialogParent, Resources.OptionsHS1, 430, 170) { InitializeComponent(); Index: Core/Common/src/Core.Common.Gui/Forms/ProgressDialog/ActivityProgressDialog.cs =================================================================== diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Gui/Forms/ProgressDialog/ActivityProgressDialog.cs (.../ActivityProgressDialog.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f) +++ Core/Common/src/Core.Common.Gui/Forms/ProgressDialog/ActivityProgressDialog.cs (.../ActivityProgressDialog.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -32,15 +32,26 @@ namespace Core.Common.Gui.Forms.ProgressDialog { + /// + /// Dialog that runs a sequence of activities, showing their progress during the execution, + /// when shown. + /// public partial class ActivityProgressDialog : DialogBase { + private const int maximumNumberOfProgressTextCharacters = 75; + private Task task; private Activity runningActivity; private readonly IEnumerable activities; private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); private readonly ProgressReporter progressReporter = new ProgressReporter(); - public ActivityProgressDialog(IWin32Window owner, IEnumerable activities) : base(owner, Resources.Ringtoets, 520, 150) + /// + /// Initializes a new instance of the class. + /// + /// The dialog parent for which this dialog should be shown on top. + /// The activities to be executed when the dialog is shown. + public ActivityProgressDialog(IWin32Window dialogParent, IEnumerable activities) : base(dialogParent, Resources.Ringtoets, 520, 150) { InitializeComponent(); @@ -184,9 +195,9 @@ // Update the activity progress text label labelActivityProgressText.Text = !progressTextNullOrEmpty - ? activity.ProgressText.Length <= 75 + ? activity.ProgressText.Length <= maximumNumberOfProgressTextCharacters ? activity.ProgressText - : activity.ProgressText.Take(75) + "..." + : activity.ProgressText.Take(maximumNumberOfProgressTextCharacters) + "..." : ""; }); } Index: Core/Common/src/Core.Common.Gui/Forms/ProgressDialog/ActivityProgressDialogRunner.cs =================================================================== diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Gui/Forms/ProgressDialog/ActivityProgressDialogRunner.cs (.../ActivityProgressDialogRunner.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f) +++ Core/Common/src/Core.Common.Gui/Forms/ProgressDialog/ActivityProgressDialogRunner.cs (.../ActivityProgressDialogRunner.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -25,16 +25,29 @@ namespace Core.Common.Gui.Forms.ProgressDialog { + /// + /// Helper methods for running a sequence of activities and observe their progress in a dialog. + /// public static class ActivityProgressDialogRunner { - public static void Run(IWin32Window owner, Activity activity) + /// + /// Runs a given activity while showing progress in a dialog. + /// + /// The dialog parent for which the progress dialog should be shown on top. + /// The activity to be executed. + public static void Run(IWin32Window dialogParent, Activity activity) { - Run(owner, new[] { activity }); + Run(dialogParent, new[] { activity }); } - public static void Run(IWin32Window owner, IEnumerable activities) + /// + /// Runs a sequence of activities while showing progress in a dialog. + /// + /// The dialog parent. + /// The activities. + public static void Run(IWin32Window dialogParent, IEnumerable activities) { - using (var activityProgressDialog = new ActivityProgressDialog(owner, activities)) + using (var activityProgressDialog = new ActivityProgressDialog(dialogParent, activities)) { activityProgressDialog.ShowDialog(); } Index: Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/IPropertyResolver.cs =================================================================== diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/IPropertyResolver.cs (.../IPropertyResolver.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f) +++ Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/IPropertyResolver.cs (.../IPropertyResolver.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -30,7 +30,8 @@ /// Returns object properties based on the provided . /// /// The source data to get the object properties for. - /// An object properties object, or null when no relevant properties object is found. + /// An object properties object, or null when no relevant properties object is found + /// or multiple matches are found. object GetObjectProperties(object sourceData); } } \ No newline at end of file Index: Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyGridView.cs =================================================================== diff -u -r0c64d8a6c718c0aa67403a16c94dd0c10f862455 -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyGridView.cs (.../PropertyGridView.cs) (revision 0c64d8a6c718c0aa67403a16c94dd0c10f862455) +++ Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyGridView.cs (.../PropertyGridView.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -31,6 +31,9 @@ namespace Core.Common.Gui.Forms.PropertyGridView { + /// + /// View for displaying the properties of an data object. + /// public class PropertyGridView : PropertyGrid, IPropertyGrid, IObserver { /// @@ -43,10 +46,16 @@ private IObservable observable; + /// + /// Initializes a new instance of the class. + /// + /// The application selection mechanism. + /// The class responsible for finding the object properties + /// for a given data object. public PropertyGridView(IApplicationSelection applicationSelection, IPropertyResolver propertyResolver) { HideTabsButton(); - FixDescriptionArea(); + DisableDescriptionAreaAutoSizing(); TranslateToolTips(); PropertySort = PropertySort.Categorized; @@ -57,9 +66,6 @@ this.applicationSelection.SelectionChanged += GuiSelectionChanged; } - /// - /// Comes from IObserver. Reaction to the change in observable. - /// public void UpdateObserver() { if (InvokeRequired) @@ -73,10 +79,6 @@ } } - /// - /// Handles properties sorting change. - /// - /// protected override void OnPropertySortChanged(EventArgs e) { // Needed for maintaining property order (no support for both categorized and alphabetical sorting) @@ -143,11 +145,6 @@ } } - /// - /// Retrieves adapter for the sourceData to be shown as the source object in the grid. - /// - /// - /// public object GetObjectProperties(object sourceData) { return propertyResolver.GetObjectProperties(sourceData); @@ -161,9 +158,6 @@ /// Do special processing for Tab key. /// http://www.codeproject.com/csharp/wdzPropertyGridUtils.asp /// - /// - /// - /// [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { @@ -245,23 +239,19 @@ /// private void HideTabsButton() { - var strip = Controls.OfType().ToList()[0]; - + ToolStrip strip = Controls.OfType().First(); strip.Items[3].Visible = false; strip.Items[4].Visible = false; } private void TranslateToolTips() { - var strip = Controls.OfType().ToList()[0]; + ToolStrip strip = Controls.OfType().First(); strip.Items[0].ToolTipText = Resources.PropertyGridView_Order_Categorized; strip.Items[1].ToolTipText = Resources.PropertyGridView_Order_Alphabetically; } - /// - /// Ensures the description area is no longer auto-resizing. - /// - private void FixDescriptionArea() + private void DisableDescriptionAreaAutoSizing() { foreach (var control in Controls) { Index: Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyResolver.cs =================================================================== diff -u -r0c64d8a6c718c0aa67403a16c94dd0c10f862455 -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyResolver.cs (.../PropertyResolver.cs) (revision 0c64d8a6c718c0aa67403a16c94dd0c10f862455) +++ Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyResolver.cs (.../PropertyResolver.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -31,7 +31,8 @@ namespace Core.Common.Gui.Forms.PropertyGridView { /// - /// Helper class for resolving object properties. + /// Class responsible for finding the that has been + /// registered for a given data-object. /// public class PropertyResolver : IPropertyResolver { @@ -41,6 +42,7 @@ /// Creates a new instance of with the given . /// /// The list of property information objects to obtain the object properties from. + /// When is null. public PropertyResolver(IEnumerable propertyInfos) { if (propertyInfos == null) @@ -50,42 +52,37 @@ this.propertyInfos = propertyInfos.ToArray(); } - /// - /// Returns object properties based on the provided . - /// - /// The source data to get the object properties for. - /// An object properties object, or null when no relevant properties object is found. public object GetObjectProperties(object sourceData) { if (sourceData == null) { return null; } - // 1. Match property information based on ObjectType and on AdditionalDataCheck + // 1. Match property information based on ObjectType and on AdditionalDataCheck: var filteredPropertyInfos = propertyInfos.Where(pi => pi.ObjectType.IsInstanceOfType(sourceData) && (pi.AdditionalDataCheck == null || pi.AdditionalDataCheck(sourceData))).ToArray(); - // 2. Match property information based on object type inheritance + // 2. Match property information based on object type inheritance, prioritizing most specialized object types: filteredPropertyInfos = FilterPropertyInfoByTypeInheritance(filteredPropertyInfos, pi => pi.ObjectType); - // 3. Match property information based on property type inheritance + // 3. Match property information based on property type inheritance, prioritizing most specialized object property types: filteredPropertyInfos = FilterPropertyInfoByTypeInheritance(filteredPropertyInfos, pi => pi.PropertyType); if (filteredPropertyInfos.Length == 0) { - // No (or multiple) object properties found: return 'null' so that no object properties are shown in the property grid + // No object properties found: return 'null' so that no object properties are shown in the property grid return null; } if (filteredPropertyInfos.Length > 1) { - // 4. We assume that the propertyInfos with AdditionalDataCheck are the most specific + // 4. Prioritize on having AdditionalDataCheck as it's a more specialized property info: filteredPropertyInfos = filteredPropertyInfos.Where(pi => pi.AdditionalDataCheck != null).ToArray(); } if (filteredPropertyInfos.Length == 1) { - return CreateObjectProperties(filteredPropertyInfos.ElementAt(0), sourceData); + return CreateObjectProperties(filteredPropertyInfos[0], sourceData); } return null; Index: Core/Common/src/Core.Common.Gui/Forms/SelectItemDialog.cs =================================================================== diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Gui/Forms/SelectItemDialog.cs (.../SelectItemDialog.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f) +++ Core/Common/src/Core.Common.Gui/Forms/SelectItemDialog.cs (.../SelectItemDialog.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -30,7 +30,7 @@ { public partial class SelectItemDialog : DialogBase { - public SelectItemDialog(IWin32Window owner) : base(owner, Resources.plus, 320, 220) + public SelectItemDialog(IWin32Window dialogParent) : base(dialogParent, Resources.plus, 320, 220) { InitializeComponent(); Index: Core/Common/src/Core.Common.Gui/Forms/SelectViewDialog.cs =================================================================== diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Gui/Forms/SelectViewDialog.cs (.../SelectViewDialog.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f) +++ Core/Common/src/Core.Common.Gui/Forms/SelectViewDialog.cs (.../SelectViewDialog.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -32,7 +32,7 @@ { private IList items; - public SelectViewDialog(IWin32Window owner) : base(owner, Resources.arrow_000_medium_question_mark, 350, 200) + public SelectViewDialog(IWin32Window dialogParent) : base(dialogParent, Resources.arrow_000_medium_question_mark, 350, 200) { InitializeComponent(); Index: Core/Common/src/Core.Common.Gui/PropertyBag/DynamicPropertyBag.cs =================================================================== diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/src/Core.Common.Gui/PropertyBag/DynamicPropertyBag.cs (.../DynamicPropertyBag.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f) +++ Core/Common/src/Core.Common.Gui/PropertyBag/DynamicPropertyBag.cs (.../DynamicPropertyBag.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -34,19 +34,20 @@ /// It processes the special attributes defined in Core.Common.Gui.Attributes /// to dynamically affect property order or adding/removing . /// + /// This class makes sure the following special attributes on properties are processed: + /// + /// + /// + /// + /// + /// public class DynamicPropertyBag : ICustomTypeDescriptor { /// /// Instantiates a new instance of , wrapping another /// object and exposing properties for that object. /// /// The object to be wrapped. - /// This class makes sure the following special attributes on properties are processed: - /// - /// - /// - /// - /// public DynamicPropertyBag(object propertyObject) { Properties = new HashSet(); Index: Core/Common/test/Core.Common.Controls.Test/Dialogs/DialogBaseTest.cs =================================================================== diff -u -r13d085cce60350733df7e62c9ccba0525d9fd279 -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/test/Core.Common.Controls.Test/Dialogs/DialogBaseTest.cs (.../DialogBaseTest.cs) (revision 13d085cce60350733df7e62c9ccba0525d9fd279) +++ Core/Common/test/Core.Common.Controls.Test/Dialogs/DialogBaseTest.cs (.../DialogBaseTest.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -25,7 +25,7 @@ var message = Assert.Throws(test).Message; // Assert - StringAssert.EndsWith("owner", message); + StringAssert.EndsWith("dialogParent", message); } [Test] @@ -166,8 +166,8 @@ private class TestDialog : DialogBase { - public TestDialog(IWin32Window owner, Icon icon, int minWidth, int minHeight) - : base(owner, icon, minWidth, minHeight) {} + public TestDialog(IWin32Window dialogParent, Icon icon, int minWidth, int minHeight) + : base(dialogParent, icon, minWidth, minHeight) {} protected override Button GetCancelButton() { Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj =================================================================== diff -u -r07138211a0efc377b1c9ef29a8e86178e8d90ab3 -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 07138211a0efc377b1c9ef29a8e86178e8d90ab3) +++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -115,6 +115,7 @@ + True True Index: Core/Common/test/Core.Common.Gui.Test/Forms/MainWindow/MainWindowTest.cs =================================================================== diff -u -r07138211a0efc377b1c9ef29a8e86178e8d90ab3 -r0358065f73923af6b8ca6566ee1e210c78c55e44 --- Core/Common/test/Core.Common.Gui.Test/Forms/MainWindow/MainWindowTest.cs (.../MainWindowTest.cs) (revision 07138211a0efc377b1c9ef29a8e86178e8d90ab3) +++ Core/Common/test/Core.Common.Gui.Test/Forms/MainWindow/MainWindowTest.cs (.../MainWindowTest.cs) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -411,7 +411,7 @@ var selectedObjectProperties = mocks.Stub(); var toolWindowList = mocks.Stub(); - toolWindowList.Expect(l => l.Add(Arg.Matches(grid => + toolWindowList.Expect(l => l.Add(Arg.Matches(grid => grid.Text == "Eigenschappen" && grid.Data == selectedObjectProperties), Arg.Is.Equal(ViewLocation.Right | ViewLocation.Bottom))); @@ -436,7 +436,7 @@ mainWindow.InitPropertiesWindowAndActivate(); // Assert - Assert.IsInstanceOf(toolWindowList.ActiveView); + Assert.IsInstanceOf(toolWindowList.ActiveView); Assert.AreEqual("Eigenschappen", toolWindowList.ActiveView.Text); Assert.AreEqual(selectedObjectProperties, toolWindowList.ActiveView.Data); @@ -457,7 +457,7 @@ var selectedObjectProperties = mocks.Stub(); var toolWindowList = mocks.Stub(); - toolWindowList.Expect(l => l.Add(Arg.Matches(grid => + toolWindowList.Expect(l => l.Add(Arg.Matches(grid => grid.Text == "Eigenschappen" && grid.Data == selectedObjectProperties), Arg.Is.Equal(ViewLocation.Right | ViewLocation.Bottom))); @@ -524,7 +524,7 @@ var selectedObjectProperties = mocks.Stub(); var toolWindowList = mocks.Stub(); - toolWindowList.Expect(l => l.Add(Arg.Matches(grid => + toolWindowList.Expect(l => l.Add(Arg.Matches(grid => grid.Text == "Eigenschappen" && grid.Data == selectedObjectProperties), Arg.Is.Equal(ViewLocation.Right | ViewLocation.Bottom))); @@ -557,7 +557,7 @@ mainWindow.InitializeToolWindows(); // Assert - Assert.IsInstanceOf(mainWindow.PropertyGrid); + Assert.IsInstanceOf(mainWindow.PropertyGrid); Assert.AreEqual("Eigenschappen", mainWindow.PropertyGrid.Text); Assert.AreEqual(selectedObjectProperties, mainWindow.PropertyGrid.Data); Index: Core/Common/test/Core.Common.Gui.Test/Forms/PropertyGridView/PropertyResolverTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Gui.Test/Forms/PropertyGridView/PropertyResolverTest.cs (revision 0) +++ Core/Common/test/Core.Common.Gui.Test/Forms/PropertyGridView/PropertyResolverTest.cs (revision 0358065f73923af6b8ca6566ee1e210c78c55e44) @@ -0,0 +1,360 @@ +using System; +using System.Linq; + +using Core.Common.Gui.Forms.PropertyGridView; +using Core.Common.Gui.Plugin; +using Core.Common.Gui.PropertyBag; +using Core.Common.TestUtil; + +using NUnit.Framework; + +namespace Core.Common.Gui.Test.Forms.PropertyGridView +{ + [TestFixture] + public class PropertyResolverTest + { + [Test] + public void ParameteredConstructor_ExpectedValues() + { + // Call + var resolver = new PropertyResolver(Enumerable.Empty()); + + // Assert + Assert.IsInstanceOf(resolver); + } + + [Test] + public void ParameteredConstructor_InputIsNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => new PropertyResolver(null); + + // Assert + const string expectedMessage = "Kan geen 'PropertyResolver' maken zonder een lijst van 'PropertyInfo'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] + public void GetObjectProperties_DataIsNull_ReturnNull() + { + // Setup + var propertyInfos = new PropertyInfo[] { new PropertyInfo() }; + + var resolver = new PropertyResolver(propertyInfos); + + // Call + var result = resolver.GetObjectProperties(null); + + // Assert + Assert.IsNull(result); + } + + [Test] + public void GetObjectProperties_DataMatchesSinglePropertyInfoDataTypeDirectly_ReturnNewInstanceOfCorrespondingObjectProperties() + { + // Setup + var propertyInfos = new PropertyInfo[] { new PropertyInfo() }; + + var resolver = new PropertyResolver(propertyInfos); + + var source = new A(); + + // Call + var result = resolver.GetObjectProperties(source); + + // Assert + Assert.IsInstanceOf(result); + Assert.IsInstanceOf(((DynamicPropertyBag)result).WrappedObject); + Assert.AreSame(source, ((IObjectProperties)((DynamicPropertyBag)result).WrappedObject).Data); + } + + [Test] + public void GetObjectProperties_DataMatchesInfoWithGetObjectPropertiesData_ReturnObjectPropertiesWithDataFromInjectedDelegate() + { + // Setup + var otherObject = new B + { + Name = "" + }; + var propertyInfos = new PropertyInfo[] + { + new PropertyInfo + { + GetObjectPropertiesData = a => otherObject + } + }; + + var resolver = new PropertyResolver(propertyInfos); + + var source = new A(); + + // Call + var result = resolver.GetObjectProperties(source); + + // Assert + var bag = (DynamicPropertyBag)result; + var properties = (PropertiesForA)bag.WrappedObject; + Assert.AreSame(otherObject, properties.Data); + } + + [Test] + public void GetObjectProperties_DataMatchesInfoWithAfterCreate_ReturnObjectPropertiesAfterCreateExecuted() + { + // Setup + var otherObject = new B + { + Name = "" + }; + var source = new A(); + + var propertyInfos = new PropertyInfo[] + { + new PropertyInfo + { + AfterCreate = p => + { + Assert.AreSame(source, p.Data, + "properties object should have been initialized with 'source'."); + p.Data = otherObject; + } + } + }; + + var resolver = new PropertyResolver(propertyInfos); + + // Call + var result = resolver.GetObjectProperties(source); + + // Assert + var bag = (DynamicPropertyBag)result; + var properties = (PropertiesForA)bag.WrappedObject; + Assert.AreSame(otherObject, properties.Data); + } + + [Test] + public void GetObjectProperties_DataMatchesMultiplePropertyInfoDataTypeDirectly_ReturnBasedOnAdditionalDataCheck() + { + // Setup + var propertyInfos = new PropertyInfo[] + { + new PropertyInfo + { + AdditionalDataCheck = a => false + }, + new PropertyInfo + { + AdditionalDataCheck = a => true + }, + }; + + var resolver = new PropertyResolver(propertyInfos); + + var source = new A(); + + // Call + var result = resolver.GetObjectProperties(source); + + // Assert + Assert.IsInstanceOf(result); + Assert.IsInstanceOf(((DynamicPropertyBag)result).WrappedObject); + Assert.AreSame(source, ((IObjectProperties)((DynamicPropertyBag)result).WrappedObject).Data); + } + + [Test] + public void GetObjectProperties_DataMatchesMultiplePropertyInfoDataTypeDirectly_PrioritizeAdditionalDataCheckOverNotHavingCheck() + { + // Setup + var propertyInfos = new PropertyInfo[] + { + new PropertyInfo + { + AdditionalDataCheck = a => true + }, + new PropertyInfo(), + }; + + var resolver = new PropertyResolver(propertyInfos); + + var source = new A(); + + // Call + var result = resolver.GetObjectProperties(source); + + // Assert + Assert.IsInstanceOf(result); + Assert.IsInstanceOf(((DynamicPropertyBag)result).WrappedObject); + Assert.AreSame(source, ((IObjectProperties)((DynamicPropertyBag)result).WrappedObject).Data); + } + + [Test] + public void GetObjectProperties_DataHasNoMatches_ReturnNull() + { + // Setup + var propertyInfos = new PropertyInfo[] + { + new PropertyInfo + { + AdditionalDataCheck = a => false + }, + new PropertyInfo(), + }; + + var resolver = new PropertyResolver(propertyInfos); + + var source = new A(); + + // Call + var result = resolver.GetObjectProperties(source); + + // Assert + Assert.IsNull(result); + } + + [Test] + public void GetObjectProperties_DataMatchesMultiplePropertyInfoByDataTypeInheritance_PrioritizeMostSpecialized() + { + // Setup + var propertyInfos = new PropertyInfo[] + { + new PropertyInfo(), + new PropertyInfo(), + }; + + var resolver = new PropertyResolver(propertyInfos); + + var source = new InheritsFromA(); + + // Call + var result = resolver.GetObjectProperties(source); + + // Assert + Assert.IsInstanceOf(result); + Assert.IsInstanceOf(((DynamicPropertyBag)result).WrappedObject); + Assert.AreSame(source, ((IObjectProperties)((DynamicPropertyBag)result).WrappedObject).Data); + } + + [Test] + public void GetObjectProperties_DataMatchesMultiplePropertyInfoByObjectPropertiesTypeInheritance_PrioritizeMostSpecialized() + { + // Setup + var propertyInfos = new PropertyInfo[] + { + new PropertyInfo(), + new PropertyInfo(), + }; + + var resolver = new PropertyResolver(propertyInfos); + + var source = new A(); + + // Call + var result = resolver.GetObjectProperties(source); + + // Assert + Assert.IsInstanceOf(result); + Assert.IsInstanceOf(((DynamicPropertyBag)result).WrappedObject); + Assert.AreSame(source, ((IObjectProperties)((DynamicPropertyBag)result).WrappedObject).Data); + } + + [Test] + public void GetObjectProperties_DataMatchesMultiplePropertyInfoByDataTypeAndObjectPropertiesTypeInheritance_PrioritizeMostSpecializedDataTypeFollowedByMostSpecializedObjectPropertiesType() + { + // Setup + var propertyInfos = new PropertyInfo[] + { + new PropertyInfo(), + new PropertyInfo(), + new PropertyInfo(), + new PropertyInfo(), + }; + + var resolver = new PropertyResolver(propertyInfos); + + var source = new InheritsFromA(); + + // Call + var result = resolver.GetObjectProperties(source); + + // Assert + Assert.IsInstanceOf(result); + Assert.IsInstanceOf(((DynamicPropertyBag)result).WrappedObject); + Assert.AreSame(source, ((IObjectProperties)((DynamicPropertyBag)result).WrappedObject).Data); + } + + [Test] + public void GetObjectProperties_DataMatchesPropertyInfoDataTypeBase_ReturnMatchedObjectProperties() + { + // Setup + var propertyInfos = new PropertyInfo[] + { + new PropertyInfo(), + }; + + var resolver = new PropertyResolver(propertyInfos); + + var source = new InheritsFromA(); + + // Call + var result = resolver.GetObjectProperties(source); + + // Assert + Assert.IsInstanceOf(result); + Assert.IsInstanceOf(((DynamicPropertyBag)result).WrappedObject); + Assert.AreSame(source, ((IObjectProperties)((DynamicPropertyBag)result).WrappedObject).Data); + } + + [Test] + public void GetObjectProperties_DataMatchesMultipleEqualPropertyInfos_ReturnNull() + { + // Setup + var propertyInfos = new PropertyInfo[] + { + new PropertyInfo(), + new PropertyInfo(), + }; + + var resolver = new PropertyResolver(propertyInfos); + + var source = new InheritsFromA(); + + // Call + var result = resolver.GetObjectProperties(source); + + // Assert + Assert.IsNull(result); + } + + #region Nester Types: various test-case classes + + private class A + { + + } + + private class PropertiesForA : IObjectProperties + { + public object Data { get; set; } + } + + private class AlternativePropertiesForA : IObjectProperties + { + public object Data { get; set; } + } + + private class InheritsFromPropertiesForA : PropertiesForA {} + + private class InheritsFromA : A {} + + private class B + { + public string Name { get; set; } + } + + private class PropertiesForB : IObjectProperties + { + public object Data { get; set; } + } + + #endregion + } +} \ No newline at end of file