From a3f60cfd253881d77aa013d9bd8c4be27a7e3e63 Mon Sep 17 00:00:00 2001 From: Neo Anderson Date: Mon, 30 Mar 2020 00:32:33 -0700 Subject: [PATCH] Add unit tests! woo! --- FrappeMocha.sln | 10 +- PlatformUnitTests/PlatformUnitTest.cs | 104 ++++++++++++++++++ .../PlatformUnitTests.csproj | 8 +- UnitTests/UnitTest1.cs | 13 --- 4 files changed, 116 insertions(+), 19 deletions(-) create mode 100644 PlatformUnitTests/PlatformUnitTest.cs rename UnitTests/UnitTests.csproj => PlatformUnitTests/PlatformUnitTests.csproj (75%) delete mode 100644 UnitTests/UnitTest1.cs diff --git a/FrappeMocha.sln b/FrappeMocha.sln index 356e2d7..39fc018 100644 --- a/FrappeMocha.sln +++ b/FrappeMocha.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.28307.1022 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrappeMocha", "FrappeMocha.csproj", "{04AB5523-E679-4628-8B8B-B928A5DA5107}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{EB446B1A-E322-48E8-968A-3E4C9B02454F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlatformUnitTests", "PlatformUnitTests\PlatformUnitTests.csproj", "{CEF3A8CA-7FAA-416F-A1FD-2AB221A84AF8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,10 +17,10 @@ Global {04AB5523-E679-4628-8B8B-B928A5DA5107}.Debug|Any CPU.Build.0 = Debug|Any CPU {04AB5523-E679-4628-8B8B-B928A5DA5107}.Release|Any CPU.ActiveCfg = Release|Any CPU {04AB5523-E679-4628-8B8B-B928A5DA5107}.Release|Any CPU.Build.0 = Release|Any CPU - {EB446B1A-E322-48E8-968A-3E4C9B02454F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EB446B1A-E322-48E8-968A-3E4C9B02454F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EB446B1A-E322-48E8-968A-3E4C9B02454F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EB446B1A-E322-48E8-968A-3E4C9B02454F}.Release|Any CPU.Build.0 = Release|Any CPU + {CEF3A8CA-7FAA-416F-A1FD-2AB221A84AF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CEF3A8CA-7FAA-416F-A1FD-2AB221A84AF8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CEF3A8CA-7FAA-416F-A1FD-2AB221A84AF8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CEF3A8CA-7FAA-416F-A1FD-2AB221A84AF8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PlatformUnitTests/PlatformUnitTest.cs b/PlatformUnitTests/PlatformUnitTest.cs new file mode 100644 index 0000000..1ec0878 --- /dev/null +++ b/PlatformUnitTests/PlatformUnitTest.cs @@ -0,0 +1,104 @@ +using System.Reflection; +using FrappeMocha.Keygen; +using FrappeMocha.Keygen.Platforms; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace PlatformUnitTests +{ + [TestClass] + public class PlatformUnitTest + { + private KeygenBase platform; + private readonly string[] _testCompanyUserStrings = {"Test", "FrappeMocha", "abcd", "1234"}; + + [TestMethod] + public void TestWindowsPlatform() + { + platform = new PlatformWindows(); + foreach (var product in platform.Products) + { + var types = platform.GenerateLicencetypes(product); + for (int i = 0; i < types.Count; i++) + { + foreach (string company in _testCompanyUserStrings) + { + var key = platform.Generate(i, company, product.Licence); + Assert.IsTrue(platform.Check(key, company, product.Licence)); + } + } + } + } + + [TestMethod] + public void TestMacOsxPlatform() + { + platform = new PlatformMac(); + foreach (var product in platform.Products) + { + var types = platform.GenerateLicencetypes(product); + for (int i = 0; i < types.Count; i++) + { + foreach (string company in _testCompanyUserStrings) + { + var key = platform.Generate(i, company, product.Licence); + Assert.IsTrue(platform.Check(key, company, product.Licence)); + } + } + } + } + + [TestMethod] + public void TestAndroidPlatform() + { + platform = new PlatformAndroid(); + foreach (var product in platform.Products) + { + var types = platform.GenerateLicencetypes(product); + for (int i = 0; i < types.Count; i++) + { + foreach (string company in _testCompanyUserStrings) + { + var key = platform.Generate(i, company, product.Licence); + Assert.IsTrue(platform.Check(key, company, product.Licence)); + } + } + } + } + + [TestMethod] + public void TestJavaPlatform() + { + platform = new PlatformJava(); + foreach (var product in platform.Products) + { + var types = platform.GenerateLicencetypes(product); + for (int i = 0; i < types.Count; i++) + { + foreach (string company in _testCompanyUserStrings) + { + var key = platform.Generate(i, company, product.Licence); + Assert.IsTrue(platform.Check(key, company, product.Licence)); + } + } + } + } + + [TestMethod] + public void TestJavaScriptPlatform() + { + platform = new PlatformJavaScript(); + foreach (var product in platform.Products) + { + var types = platform.GenerateLicencetypes(product); + for (int i = 0; i < types.Count; i++) + { + foreach (string company in _testCompanyUserStrings) + { + var key = platform.Generate(i, company, product.Licence); + Assert.IsTrue(platform.Check(key, company, product.Licence)); + } + } + } + } + } +} diff --git a/UnitTests/UnitTests.csproj b/PlatformUnitTests/PlatformUnitTests.csproj similarity index 75% rename from UnitTests/UnitTests.csproj rename to PlatformUnitTests/PlatformUnitTests.csproj index 62eb1ee..a1d7e1d 100644 --- a/UnitTests/UnitTests.csproj +++ b/PlatformUnitTests/PlatformUnitTests.csproj @@ -7,7 +7,9 @@ - + Library + + @@ -16,4 +18,8 @@ + + + + diff --git a/UnitTests/UnitTest1.cs b/UnitTests/UnitTest1.cs deleted file mode 100644 index 78d0b38..0000000 --- a/UnitTests/UnitTest1.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace UnitTests -{ - [TestClass] - public class UnitTest1 - { - [TestMethod] - public void TestMethod1() - { - } - } -}