From ca4155031f952a013b95dde421efe009874d8010 Mon Sep 17 00:00:00 2001 From: jbe2277 Date: Sat, 17 Aug 2024 14:31:56 +0200 Subject: [PATCH] InfoMan: Simplify ToolBarCommand type --- .../Applications/ToolBarCommand.cs | 29 +++---------------- .../Services/ToolBarCommandTest.cs | 27 ----------------- 2 files changed, 4 insertions(+), 52 deletions(-) delete mode 100644 src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/ToolBarCommandTest.cs diff --git a/src/System.Waf/Samples/InformationManager/Infrastructure.Interfaces/Applications/ToolBarCommand.cs b/src/System.Waf/Samples/InformationManager/Infrastructure.Interfaces/Applications/ToolBarCommand.cs index 52902760..14387f24 100644 --- a/src/System.Waf/Samples/InformationManager/Infrastructure.Interfaces/Applications/ToolBarCommand.cs +++ b/src/System.Waf/Samples/InformationManager/Infrastructure.Interfaces/Applications/ToolBarCommand.cs @@ -3,28 +3,7 @@ namespace Waf.InformationManager.Infrastructure.Interfaces.Applications; /// Defines a tool bar command -public class ToolBarCommand -{ - /// Initializes a new instance of the class. - /// The command which is invoked when the user clicks on the tool bar button. - /// The text of the tool bar button. - /// The tooltip of the tool bar button. - /// command must not be null. - /// text must not be null or empty. - public ToolBarCommand(ICommand command, string text, string? toolTip = null) - { - Command = command ?? throw new ArgumentNullException(nameof(command)); - if (string.IsNullOrEmpty(text)) throw new ArgumentException("text must not be null or empty.", nameof(text)); - Text = text; - ToolTip = toolTip ?? ""; - } - - /// Gets the command which is invoked when the user clicks on the tool bar button. - public ICommand Command { get; } - - /// Gets the text of the tool bar button. - public string Text { get; } - - /// Gets the tool tip of the tool bar button. - public string ToolTip { get; } -} +/// The command which is invoked when the user clicks on the tool bar button. +/// The text of the tool bar button. +/// The tooltip of the tool bar button. +public record ToolBarCommand(ICommand Command, string Text, string? ToolTip = null); diff --git a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/ToolBarCommandTest.cs b/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/ToolBarCommandTest.cs deleted file mode 100644 index 606594b0..00000000 --- a/src/System.Waf/Samples/InformationManager/Infrastructure.Modules.Applications.Test/Services/ToolBarCommandTest.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Waf.Applications; -using System.Waf.UnitTesting; -using Waf.InformationManager.Infrastructure.Interfaces.Applications; - -namespace Test.InformationManager.Infrastructure.Modules.Applications.Services; - -[TestClass] -public class ToolBarCommandTest -{ - [TestMethod] - public void ConstructorTest() - { - var emptyCommand = new DelegateCommand(() => { }); - - AssertHelper.ExpectedException(() => new ToolBarCommand(null!, null!)); - AssertHelper.ExpectedException(() => new ToolBarCommand(emptyCommand, null!)); - - var toolBarCommand1 = new ToolBarCommand(emptyCommand, "Command 1"); - Assert.AreEqual(emptyCommand, toolBarCommand1.Command); - Assert.AreEqual("Command 1", toolBarCommand1.Text); - Assert.AreEqual("", toolBarCommand1.ToolTip); - - var toolBarCommand2 = new ToolBarCommand(emptyCommand, "Command 2", "ToolTip 2"); - Assert.AreEqual("ToolTip 2", toolBarCommand2.ToolTip); - } -}