diff --git a/KeeTrayTOTP.Tests/Menu/EntryMenuItemProviderTests.cs b/KeeTrayTOTP.Tests/Menu/EntryMenuItemProviderTests.cs new file mode 100644 index 0000000..5ad63a7 --- /dev/null +++ b/KeeTrayTOTP.Tests/Menu/EntryMenuItemProviderTests.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using FluentAssertions; +using KeePass.UI; +using KeePass.Util; +using KeeTrayTOTP.Menu; +using KeeTrayTOTP.Tests.Extensions; +using KeeTrayTOTP.Tests.Helpers; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace KeeTrayTOTP.Tests.Menu +{ + [TestClass] + public class EntryMenuItemProviderTests + { + private EntryMenuItemProvider _entryMenuItemProvider; + + [TestInitialize] + public void Initialize() + { + var (plugin, host) = PluginHostHelper.CreateAndInitialize(); + + _entryMenuItemProvider = new EntryMenuItemProvider(plugin, host.Object); + } + + [TestMethod] + public void EntryMenuItemProvider_Should_ProvideAllMenuItemsWithCorrectShortcutKeys() + { + var sut = _entryMenuItemProvider.ProvideMenuItem(); + + sut.DropDownItems.Count.Should().Be(3, + "because, there are exactly three menu items for an entry."); + + sut.DropDownItems + .Cast() + .All(menuItem => menuItem.ShortcutKeys != Keys.None) + .Should().BeTrue("because, all entries should have a shortcut key assigned."); + } + } +} diff --git a/KeeTrayTOTP/Menu/EntryMenuItemProvider.cs b/KeeTrayTOTP/Menu/EntryMenuItemProvider.cs index 9d0b5fc..2ffcdc5 100644 --- a/KeeTrayTOTP/Menu/EntryMenuItemProvider.cs +++ b/KeeTrayTOTP/Menu/EntryMenuItemProvider.cs @@ -23,10 +23,23 @@ public ToolStripMenuItem ProvideMenuItem() { var rootEntryMenuItem = new ToolStripMenuItem(Localization.Strings.TrayTOTPPlugin, Properties.Resources.TOTP); - var entryMenuCopyTotp = new ToolStripMenuItem(Localization.Strings.CopyTOTP, Properties.Resources.TOTP, OnEntryMenuTOTPClick, (Keys)Shortcut.CtrlT); - var entryMenuSetupTotp = new ToolStripMenuItem(Localization.Strings.SetupTOTP, Properties.Resources.TOTP_Setup, OnEntryMenuSetupClick, (Keys)Shortcut.CtrlShiftI); - var entryMenuShowQrCode = new ToolStripMenuItem(Localization.Strings.ShowQR, Properties.Resources.TOTP_Setup, OnEntryMenuShowQRClick, (Keys)Shortcut.CtrlShiftJ); - + // The ShortCutKeys assignments are required in this form and + // can not be setup as constructor parameters, because an implementation + // in the mono framework is missing. + // see https://github.com/mono/mono/issues/19755 + var entryMenuCopyTotp = new ToolStripMenuItem(Localization.Strings.CopyTOTP, Properties.Resources.TOTP, OnEntryMenuTOTPClick) + { + ShortcutKeys = (Keys)Shortcut.CtrlT + }; + var entryMenuSetupTotp = new ToolStripMenuItem(Localization.Strings.SetupTOTP, Properties.Resources.TOTP_Setup, OnEntryMenuSetupClick) + { + ShortcutKeys = (Keys)Shortcut.CtrlShiftI + }; + var entryMenuShowQrCode = new ToolStripMenuItem(Localization.Strings.ShowQR, Properties.Resources.TOTP_Setup, OnEntryMenuShowQRClick) + { + ShortcutKeys = (Keys)Shortcut.CtrlShiftJ + }; + rootEntryMenuItem.DropDownItems.Add(entryMenuCopyTotp); rootEntryMenuItem.DropDownItems.Add(entryMenuSetupTotp); rootEntryMenuItem.DropDownItems.Add(entryMenuShowQrCode);