From b21099f9d2defc78c0c15235e0021793d1681d71 Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Mon, 8 Apr 2019 18:13:46 +0100 Subject: [PATCH 1/2] Cleanup event args in System.Windows.Forms.Design --- .../ComponentModel/Design/LoadedEventArgs.cs | 33 ++++++++++++++++ .../Design/LoadedEventHandler.cs | 39 ------------------- .../System/Drawing/Design/IToolboxService.cs | 5 ++- .../src/System/Drawing/Design/IToolboxUser.cs | 1 - .../ToolboxComponentsCreatedEventArgs.cs | 9 ++++- .../ToolboxComponentsCreatingEventArgs.cs | 4 +- .../Behavior/BehaviorDragDropEventArgs.cs | 10 ++--- .../DesignerActionListsChangedEventArgs.cs | 29 ++++++-------- .../DesignerActionListsChangedEventHandler.cs | 7 ++-- .../Design/DesignerActionListsChangedType.cs | 5 ++- .../DesignerActionUIStateChangeEventArgs.cs | 18 ++++----- .../Design/DesignerActionUIStateChangeType.cs | 4 +- 12 files changed, 76 insertions(+), 88 deletions(-) create mode 100644 src/System.Windows.Forms.Design/src/System/ComponentModel/Design/LoadedEventArgs.cs diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/LoadedEventArgs.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/LoadedEventArgs.cs new file mode 100644 index 00000000000..d0f45bb2d8b --- /dev/null +++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/LoadedEventArgs.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections; + +namespace System.ComponentModel.Design +{ + /// + /// Provides additional information for the Loaded event. + /// + public sealed class LoadedEventArgs : EventArgs + { + /// + /// Creates a new LoadedEventArgs object. + /// + public LoadedEventArgs(bool succeeded, ICollection errors) + { + HasSucceeded = succeeded; + Errors = errors ?? Array.Empty(); + } + + /// + /// True to indicate the designer load was successful. Even successful loads can have errors, if the errors were not too servere to prevent the designer from loading. + /// + public bool HasSucceeded { get; } + + /// + /// A collection of errors that occurred while the designer was loading. + /// + public ICollection Errors { get; } + } +} diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/LoadedEventHandler.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/LoadedEventHandler.cs index c93d6141769..afcca44f685 100644 --- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/LoadedEventHandler.cs +++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/LoadedEventHandler.cs @@ -2,49 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections; - namespace System.ComponentModel.Design { /// /// Represents the method that will handle a Loaded event. /// public delegate void LoadedEventHandler(object sender, LoadedEventArgs e); - - /// - /// Provides additional information for the Loaded event. - /// - public sealed class LoadedEventArgs : EventArgs - { - private readonly bool _succeeded; - private readonly ICollection _errors; - /// - /// Creates a new LoadedEventArgs object. - /// - public LoadedEventArgs(bool succeeded, ICollection errors) - { - _succeeded = succeeded; - _errors = errors; - if (_errors == null) - { - _errors = new object[0]; - } - } - - /// - /// A collection of errors that occurred while the designer was loading. - /// - public ICollection Errors - { - get => _errors; - } - - /// - /// True to indicate the designer load was successful. Even successful loads can have errors, if the errors were not too servere to prevent the designer from loading. - /// - public bool HasSucceeded - { - get => _succeeded; - } - } } diff --git a/src/System.Windows.Forms.Design/src/System/Drawing/Design/IToolboxService.cs b/src/System.Windows.Forms.Design/src/System/Drawing/Design/IToolboxService.cs index e549316828b..1b9433c8c30 100644 --- a/src/System.Windows.Forms.Design/src/System/Drawing/Design/IToolboxService.cs +++ b/src/System.Windows.Forms.Design/src/System/Drawing/Design/IToolboxService.cs @@ -11,7 +11,9 @@ namespace System.Drawing.Design /// /// Provides access to the toolbox in the development environment. /// - [ComImport(), Guid("4BACD258-DE64-4048-BC4E-FEDBEF9ACB76"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + [Guid("4BACD258-DE64-4048-BC4E-FEDBEF9ACB76")] + [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] public interface IToolboxService { /// @@ -167,4 +169,3 @@ public interface IToolboxService void SetSelectedToolboxItem(ToolboxItem toolboxItem); } } - diff --git a/src/System.Windows.Forms.Design/src/System/Drawing/Design/IToolboxUser.cs b/src/System.Windows.Forms.Design/src/System/Drawing/Design/IToolboxUser.cs index 51b2558b542..9ecc48c7cfe 100644 --- a/src/System.Windows.Forms.Design/src/System/Drawing/Design/IToolboxUser.cs +++ b/src/System.Windows.Forms.Design/src/System/Drawing/Design/IToolboxUser.cs @@ -21,4 +21,3 @@ public interface IToolboxUser void ToolPicked(ToolboxItem tool); } } - diff --git a/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatedEventArgs.cs b/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatedEventArgs.cs index 25b7080bd06..c00465ce485 100644 --- a/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatedEventArgs.cs +++ b/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatedEventArgs.cs @@ -12,14 +12,19 @@ namespace System.Drawing.Design /// public class ToolboxComponentsCreatedEventArgs : EventArgs { + private IComponent[] _components; + /// /// Initializes a new instance of the - public ToolboxComponentsCreatedEventArgs(IComponent[] components) => throw new NotImplementedException(SR.NotImplementedByDesign); + public ToolboxComponentsCreatedEventArgs(IComponent[] components) + { + _components = components; + } /// /// An array storing the toolbox components. /// - public IComponent[] Components => throw new NotImplementedException(SR.NotImplementedByDesign); + public IComponent[] Components => (IComponent[])_components?.Clone(); } } diff --git a/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatingEventArgs.cs b/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatingEventArgs.cs index 7da77cff477..5305e74a478 100644 --- a/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatingEventArgs.cs +++ b/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatingEventArgs.cs @@ -18,8 +18,8 @@ public class ToolboxComponentsCreatingEventArgs : EventArgs public ToolboxComponentsCreatingEventArgs(IDesignerHost host) => throw new NotImplementedException(SR.NotImplementedByDesign); /// - /// An instance of IDesignerHost that has made the creat request. This can be null if no designer host - /// was provided to the toolbox item. + /// An instance of IDesignerHost that has made the creat request. + /// This can be null if no designer host was provided to the toolbox item. /// public IDesignerHost DesignerHost => throw new NotImplementedException(SR.NotImplementedByDesign); } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgs.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgs.cs index dcb2410a1f1..eeeb5648057 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgs.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgs.cs @@ -7,22 +7,18 @@ namespace System.Windows.Forms.Design.Behavior { /// - /// This class represents the arguments describing a BehaviorDragDrop event - /// fired by the BehaviorService. + /// This class represents the arguments describing a BehaviorDragDrop event + /// fired by the BehaviorService. /// public class BehaviorDragDropEventArgs : EventArgs { - /// - /// Constructor. This class is created by the BehaviorService directly - /// before a drag operation begins. - /// public BehaviorDragDropEventArgs(ICollection dragComponents) { throw new NotImplementedException(SR.NotImplementedByDesign); } /// - /// Returns the list of IComponents currently being dragged. + /// Returns the list of IComponents currently being dragged. /// public ICollection DragComponents => throw new NotImplementedException(SR.NotImplementedByDesign); } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedEventArgs.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedEventArgs.cs index 734aea70427..9b1162ab9c9 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedEventArgs.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedEventArgs.cs @@ -9,34 +9,29 @@ namespace System.ComponentModel.Design /// public class DesignerActionListsChangedEventArgs : EventArgs { - - private readonly object _relatedObject; - private readonly DesignerActionListCollection _actionLists; - private readonly DesignerActionListsChangedType _changeType; - /// /// Constructor that requires the object in question, the type of change and the remaining actionlists left for the object. on the related object. - /// + /// public DesignerActionListsChangedEventArgs(object relatedObject, DesignerActionListsChangedType changeType, DesignerActionListCollection actionLists) { - _relatedObject = relatedObject; - _changeType = changeType; - _actionLists = actionLists; + RelatedObject = relatedObject; + ChangeType = changeType; + ActionLists = actionLists; } /// - /// The type of changed that caused the related event to be thrown. - /// - public DesignerActionListsChangedType ChangeType => _changeType; + /// The object this change is related to. + /// + public object RelatedObject { get; } /// - /// The object this change is related to. - /// - public object RelatedObject => _relatedObject; + /// The type of changed that caused the related event to be thrown. + /// + public DesignerActionListsChangedType ChangeType { get; } /// /// The remaining actionlists left for the related object. - /// - public DesignerActionListCollection ActionLists => _actionLists; + /// + public DesignerActionListCollection ActionLists { get; } } } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedEventHandler.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedEventHandler.cs index 700ebd2583e..ac8057309e4 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedEventHandler.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedEventHandler.cs @@ -2,11 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.InteropServices; + namespace System.ComponentModel.Design { - /// - /// This event is thown by the DesignerActionListservice when a shortcut is either added or removed to/from the related object. - /// - [System.Runtime.InteropServices.ComVisible(true)] + [ComVisible(true)] public delegate void DesignerActionListsChangedEventHandler(object sender, DesignerActionListsChangedEventArgs e); } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedType.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedType.cs index b901681903b..6e939eeb40d 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedType.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionListsChangedType.cs @@ -2,12 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.InteropServices; + namespace System.ComponentModel.Design { /// /// An enum that defines what time of action happend to the related object's DesignerActionLists collection. /// - [System.Runtime.InteropServices.ComVisible(true)] + [ComVisible(true)] public enum DesignerActionListsChangedType { /// @@ -19,6 +21,5 @@ public enum DesignerActionListsChangedType /// Signifies that one or more DesignerActionList was removed. /// ActionListsRemoved - } } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionUIStateChangeEventArgs.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionUIStateChangeEventArgs.cs index a307989ce40..1489cf48b32 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionUIStateChangeEventArgs.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionUIStateChangeEventArgs.cs @@ -9,27 +9,23 @@ namespace System.ComponentModel.Design /// public class DesignerActionUIStateChangeEventArgs : EventArgs { - private readonly object _relatedObject; - private readonly DesignerActionUIStateChangeType _changeType; - /// /// Constructor that requires the object in question, the type of change and the remaining actionlists left for the object on the related object. /// public DesignerActionUIStateChangeEventArgs(object relatedObject, DesignerActionUIStateChangeType changeType) { - _relatedObject = relatedObject; - _changeType = changeType; + RelatedObject = relatedObject; + ChangeType = changeType; } - /// - /// The type of changed that caused the related event to be thrown. - /// - public DesignerActionUIStateChangeType ChangeType => _changeType; - /// /// The object this change is related to. /// - public object RelatedObject => _relatedObject; + public object RelatedObject { get; } + /// + /// The type of changed that caused the related event to be thrown. + /// + public DesignerActionUIStateChangeType ChangeType { get; } } } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionUIStateChangeType.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionUIStateChangeType.cs index ed9edc4cec5..e4f35eed025 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionUIStateChangeType.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionUIStateChangeType.cs @@ -6,6 +6,8 @@ namespace System.ComponentModel.Design { public enum DesignerActionUIStateChangeType { - Show, Hide, Refresh + Show, + Hide, + Refresh } } From 6b76469a4928e0289a9a55852939ed549e41aab0 Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Mon, 8 Apr 2019 18:14:01 +0100 Subject: [PATCH 2/2] Implement missing event args, fix NRE bug and add tests --- .../ToolboxComponentsCreatingEventArgs.cs | 7 +++- .../Behavior/BehaviorDragDropEventArgs.cs | 4 +- ...esignerActionListsChangedEventArgsTests.cs | 29 ++++++++++++++ ...signerActionUIStateChangeEventArgsTests.cs | 28 ++++++++++++++ .../Design/LoadedEventArgsTests.cs | 36 ++++++++++++++++++ .../ToolboxComponentsCreatedEventArgsTests.cs | 38 +++++++++++++++++++ ...ToolboxComponentsCreatingEventArgsTests.cs | 28 ++++++++++++++ .../BehaviorDragDropEventArgsTests.cs | 28 ++++++++++++++ 8 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionListsChangedEventArgsTests.cs create mode 100644 src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionUIStateChangeEventArgsTests.cs create mode 100644 src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/LoadedEventArgsTests.cs create mode 100644 src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxComponentsCreatedEventArgsTests.cs create mode 100644 src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxComponentsCreatingEventArgsTests.cs create mode 100644 src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgsTests.cs diff --git a/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatingEventArgs.cs b/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatingEventArgs.cs index 5305e74a478..a104a81ec72 100644 --- a/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatingEventArgs.cs +++ b/src/System.Windows.Forms.Design/src/System/Drawing/Design/ToolboxComponentsCreatingEventArgs.cs @@ -15,12 +15,15 @@ public class ToolboxComponentsCreatingEventArgs : EventArgs /// /// Initializes a new instance of the object. /// - public ToolboxComponentsCreatingEventArgs(IDesignerHost host) => throw new NotImplementedException(SR.NotImplementedByDesign); + public ToolboxComponentsCreatingEventArgs(IDesignerHost host) + { + DesignerHost = host; + } /// /// An instance of IDesignerHost that has made the creat request. /// This can be null if no designer host was provided to the toolbox item. /// - public IDesignerHost DesignerHost => throw new NotImplementedException(SR.NotImplementedByDesign); + public IDesignerHost DesignerHost { get; } } } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgs.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgs.cs index eeeb5648057..ddfa7e6fd36 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgs.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgs.cs @@ -14,12 +14,12 @@ public class BehaviorDragDropEventArgs : EventArgs { public BehaviorDragDropEventArgs(ICollection dragComponents) { - throw new NotImplementedException(SR.NotImplementedByDesign); + DragComponents = dragComponents; } /// /// Returns the list of IComponents currently being dragged. /// - public ICollection DragComponents => throw new NotImplementedException(SR.NotImplementedByDesign); + public ICollection DragComponents { get; } } } diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionListsChangedEventArgsTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionListsChangedEventArgsTests.cs new file mode 100644 index 00000000000..495f2c09ef0 --- /dev/null +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionListsChangedEventArgsTests.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections; +using System.Collections.Generic; +using Xunit; + +namespace System.ComponentModel.Design.Tests +{ + public class DesignerActionListsChangedEventArgsTests + { + public static IEnumerable Ctor_Object_DesignerActionListsChangedType_DesignerActionListCollection_TestData() + { + yield return new object[] { null, DesignerActionListsChangedType.ActionListsAdded - 1, null }; + yield return new object[] { new object(), DesignerActionListsChangedType.ActionListsAdded, new DesignerActionListCollection() }; + } + + [Theory] + [MemberData(nameof(Ctor_Object_DesignerActionListsChangedType_DesignerActionListCollection_TestData))] + public void Ctor_Object_DesignerActionListsChangedType_DesignerActionListCollection(object relatedObject, DesignerActionListsChangedType changeType, DesignerActionListCollection actionLists) + { + var e = new DesignerActionListsChangedEventArgs(relatedObject, changeType, actionLists); + Assert.Same(relatedObject, e.RelatedObject); + Assert.Equal(changeType, e.ChangeType); + Assert.Same(actionLists, e.ActionLists); + } + } +} diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionUIStateChangeEventArgsTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionUIStateChangeEventArgsTests.cs new file mode 100644 index 00000000000..ad66eca14e7 --- /dev/null +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionUIStateChangeEventArgsTests.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections; +using System.Collections.Generic; +using Xunit; + +namespace System.ComponentModel.Design.Tests +{ + public class DesignerActionUIStateChangeEventArgsTests + { + public static IEnumerable Ctor_Object_DesignerActionUIStateChangeType_TestData() + { + yield return new object[] { null, DesignerActionUIStateChangeType.Show - 1 }; + yield return new object[] { new object(), DesignerActionUIStateChangeType.Show }; + } + + [Theory] + [MemberData(nameof(Ctor_Object_DesignerActionUIStateChangeType_TestData))] + public void Ctor_Object_DesignerActionUIStateChangeType(object relatedObject, DesignerActionUIStateChangeType changeType) + { + var e = new DesignerActionUIStateChangeEventArgs(relatedObject, changeType); + Assert.Same(relatedObject, e.RelatedObject); + Assert.Equal(changeType, e.ChangeType); + } + } +} diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/LoadedEventArgsTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/LoadedEventArgsTests.cs new file mode 100644 index 00000000000..b9851ec8627 --- /dev/null +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/LoadedEventArgsTests.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections; +using System.Collections.Generic; +using Xunit; + +namespace System.ComponentModel.Design.Tests +{ + public class LoadedEventArgsTests + { + public static IEnumerable Ctor_Bool_ICollection_TestData() + { + yield return new object[] { true, null }; + yield return new object[] { false, new object[0] }; + yield return new object[] { true, new object[] { null } }; + } + + [Theory] + [MemberData(nameof(Ctor_Bool_ICollection_TestData))] + public void Ctor_Bool_ICollection(bool succeeded, ICollection errors) + { + var e = new LoadedEventArgs(succeeded, errors); + Assert.Equal(succeeded, e.HasSucceeded); + if (errors == null) + { + Assert.Empty(e.Errors); + } + else + { + Assert.Same(errors, e.Errors); + } + } + } +} diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxComponentsCreatedEventArgsTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxComponentsCreatedEventArgsTests.cs new file mode 100644 index 00000000000..4a4679e5fd3 --- /dev/null +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxComponentsCreatedEventArgsTests.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.ComponentModel; +using Xunit; + +namespace System.Drawing.Design.Tests +{ + public class ToolboxComponentsCreatedEventArgsTests + { + public static IEnumerable Ctor_IComponentArray_TestData() + { + yield return new object[] { null }; + yield return new object[] { new IComponent[0] }; + yield return new object[] { new IComponent[] { null } }; + } + + [Theory] + [MemberData(nameof(Ctor_IComponentArray_TestData))] + public void Ctor_IComponentArray(IComponent[] components) + { + var e = new ToolboxComponentsCreatedEventArgs(components); + if (components == null) + { + Assert.Null(e.Components); + } + else + { + Assert.Equal(components, e.Components); + Assert.NotSame(components, e.Components); + Assert.Equal(e.Components, e.Components); + Assert.NotSame(e.Components, e.Components); + } + } + } +} diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxComponentsCreatingEventArgsTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxComponentsCreatingEventArgsTests.cs new file mode 100644 index 00000000000..96e3967bb18 --- /dev/null +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Drawing/Design/ToolboxComponentsCreatingEventArgsTests.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.ComponentModel.Design; +using Moq; +using Xunit; + +namespace System.Drawing.Design.Tests +{ + public class ToolboxComponentsCreatingEventArgsTests + { + public static IEnumerable Ctor_IDesignerHost_TestData() + { + yield return new object[] { null }; + yield return new object[] { new Mock(MockBehavior.Strict).Object }; + } + + [Theory] + [MemberData(nameof(Ctor_IDesignerHost_TestData))] + public void Ctor_IDesignerHost(IDesignerHost host) + { + var e = new ToolboxComponentsCreatingEventArgs(host); + Assert.Equal(host, e.DesignerHost); + } + } +} diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgsTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgsTests.cs new file mode 100644 index 00000000000..bc9db5ef906 --- /dev/null +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/Behavior/BehaviorDragDropEventArgsTests.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections; +using System.Collections.Generic; +using Xunit; + +namespace System.Windows.Forms.Design.Behavior.Tests +{ + public class BehaviorDragDropEventArgsTests + { + public static IEnumerable Ctor_ICollection_TestData() + { + yield return new object[] { null }; + yield return new object[] { new object[0] }; + yield return new object[] { new object[] { null } }; + } + + [Theory] + [MemberData(nameof(Ctor_ICollection_TestData))] + public void Ctor_ICollection(ICollection components) + { + var e = new BehaviorDragDropEventArgs(components); + Assert.Same(components, e.DragComponents); + } + } +}