From a9fc8161a0349296a8ebbc52e0ddb0dc5f53f960 Mon Sep 17 00:00:00 2001 From: Robin van Poppel Date: Sun, 12 Apr 2020 10:48:09 +0200 Subject: [PATCH] Validate keepass plugin conventions (#113) --- .../KeepassPluginConventionsTests.cs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 KeeTrayTOTP.Tests/KeepassPluginConventionsTests.cs diff --git a/KeeTrayTOTP.Tests/KeepassPluginConventionsTests.cs b/KeeTrayTOTP.Tests/KeepassPluginConventionsTests.cs new file mode 100644 index 0000000..bcdf5da --- /dev/null +++ b/KeeTrayTOTP.Tests/KeepassPluginConventionsTests.cs @@ -0,0 +1,73 @@ +using FluentAssertions; +using KeePass.Plugins; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Reflection; + +namespace KeeTrayTOTP.Tests +{ + /// + /// Validate Keepass Plugin Conventions + /// https://keepass.info/help/v2_dev/plg_index.html + /// + [TestClass] + public class KeepassPluginConventionsTests + { + /// + /// Product name: Must be set to "KeePass Plugin" (without the quotes). + /// + [TestMethod] + public void AssemblyProduct_ShouldBeEqualToKeePassPlugin() + { + // Arrange + var pluginAssembly = typeof(KeeTrayTOTPExt).Assembly; + + // Act + var assemblyProduct = pluginAssembly.GetCustomAttribute(); + + // Assert + assemblyProduct.Should().NotBeNull(); + assemblyProduct.Product.Should().Be("KeePass Plugin"); + } + + /// + /// The namespace must be named like the DLL file without extension. + /// + [TestMethod] + public void AssemblyNamespace_ShouldBeEqualToAssemblyName() + { + // Arrange + var pluginType = typeof(KeeTrayTOTPExt); + var pluginAssembly = typeof(KeeTrayTOTPExt).Assembly; + + // Assert + pluginType.Namespace.Should().Be(pluginAssembly.GetName().Name); + } + + /// + /// The plugin class must be named like the namespace plus "Ext". + /// + [TestMethod] + public void PluginClass_ShouldBeEqualToNamespacePlusExt() + { + // Arrange + var pluginType = typeof(KeeTrayTOTPExt); + + // Assert + pluginType.Name.Should().Be($"{pluginType.Namespace}Ext"); + } + + + /// + /// The plugin class must derive from the Plugin class + /// + [TestMethod] + public void PluginClass_ShouldDeriveFromIPlugin() + { + // Arrange + var pluginType = typeof(KeeTrayTOTPExt); + + // Assert + pluginType.Should().BeDerivedFrom(); + } + } +}