diff --git a/Creator/App.config b/Creator/App.config index 68ab0eb..a28c49f 100644 --- a/Creator/App.config +++ b/Creator/App.config @@ -1,26 +1,26 @@ - + - + - - + + - - + + - - + + - - + + - \ No newline at end of file + diff --git a/Creator/KattekerCreator.csproj b/Creator/KattekerCreator.csproj index 1000c2d..d9e03e2 100644 --- a/Creator/KattekerCreator.csproj +++ b/Creator/KattekerCreator.csproj @@ -9,15 +9,16 @@ Properties KattekerCreator KattekerCreator - v4.5 + v4.7 512 ..\ true + - x64 + AnyCPU true full false diff --git a/Example/Example.csproj b/Example/Example.csproj index 1013e13..5c31bb8 100644 --- a/Example/Example.csproj +++ b/Example/Example.csproj @@ -15,7 +15,7 @@ - x64 + AnyCPU true full false diff --git a/Katteker.Test/Katteker.Test.csproj b/Katteker.Test/Katteker.Test.csproj new file mode 100644 index 0000000..8dea54e --- /dev/null +++ b/Katteker.Test/Katteker.Test.csproj @@ -0,0 +1,78 @@ + + + + + Debug + AnyCPU + {76E9E47E-C810-4C13-BAC3-1F53CF4BCB92} + Library + Properties + Katteker.Test + Katteker.Test + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + PreserveNewest + + + + + {A45E1C59-BA9E-452C-A5E2-50DE49D53E92} + Katteker + + + + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + + + + \ No newline at end of file diff --git a/Katteker.Test/KattekerLibTest.cs b/Katteker.Test/KattekerLibTest.cs new file mode 100644 index 0000000..18775a7 --- /dev/null +++ b/Katteker.Test/KattekerLibTest.cs @@ -0,0 +1,52 @@ +using System; +using System.IO; +using System.Reflection; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Katteker.Test +{ + [TestClass] + public class KattekerLibTest + { + private static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory; + private static readonly string ExampleFile = Path.Combine(BaseDir, "testdata", "Example.exe"); + + [TestMethod] + public void Sha1ChecksumOfFile() + { + var actual = Utility.ComputeFileHash(ExampleFile); + const string expected = "0zgDmFuotnldZIyADoWrpiSDUx4="; + Assert.AreEqual(expected, actual); + } + + [TestMethod] + public void CheckIfStringIsWebUrl() + { + const string test1 = "http://TolleUrl.de/Test"; + const string test2 = "https://TolleUrl.de/Test"; + const string test3 = "C:\\Test"; + const string test4 = "furz"; + + Assert.IsTrue(Utility.IsWebUrl(test1)); + Assert.IsTrue(Utility.IsWebUrl(test2)); + Assert.IsFalse(Utility.IsWebUrl(test3)); + Assert.ThrowsException(() => Utility.IsWebUrl(test4)); + } + + [TestMethod] + public void CheckRightAssemblyName() + { + const string expected = "Example"; + var actual = Utility.GetApplicationName(Assembly.LoadFile(ExampleFile)); + Assert.AreEqual(expected, actual); + } + + [TestMethod] + public void CheckAssemblyVersionStuff() + { + var expected = new Semver.SemVersion(1, 0, 53); + var actual = VersionUtils.GetCurrentVersion(Assembly.LoadFile(ExampleFile)); + Assert.AreEqual(expected, actual); + } + } +} \ No newline at end of file diff --git a/Katteker.Test/Properties/AssemblyInfo.cs b/Katteker.Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..12c86c0 --- /dev/null +++ b/Katteker.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Katteker.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Katteker.Test")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("76e9e47e-c810-4c13-bac3-1f53cf4bcb92")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Katteker.Test/packages.config b/Katteker.Test/packages.config new file mode 100644 index 0000000..cf2d094 --- /dev/null +++ b/Katteker.Test/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Katteker.Test/testdata/Example.exe b/Katteker.Test/testdata/Example.exe new file mode 100644 index 0000000..7a9374d Binary files /dev/null and b/Katteker.Test/testdata/Example.exe differ diff --git a/Katteker.sln b/Katteker.sln index b0d1294..dd01bc3 100644 --- a/Katteker.sln +++ b/Katteker.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Example\Example. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Katteker.Gui", "Katteker.Gui\Katteker.Gui.csproj", "{07E2DE31-80A0-43DA-B307-1CA47CD930A1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Katteker.Test", "Katteker.Test\Katteker.Test.csproj", "{76E9E47E-C810-4C13-BAC3-1F53CF4BCB92}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {07E2DE31-80A0-43DA-B307-1CA47CD930A1}.Debug|Any CPU.Build.0 = Debug|Any CPU {07E2DE31-80A0-43DA-B307-1CA47CD930A1}.Release|Any CPU.ActiveCfg = Release|Any CPU {07E2DE31-80A0-43DA-B307-1CA47CD930A1}.Release|Any CPU.Build.0 = Release|Any CPU + {76E9E47E-C810-4C13-BAC3-1F53CF4BCB92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {76E9E47E-C810-4C13-BAC3-1F53CF4BCB92}.Debug|Any CPU.Build.0 = Debug|Any CPU + {76E9E47E-C810-4C13-BAC3-1F53CF4BCB92}.Release|Any CPU.ActiveCfg = Release|Any CPU + {76E9E47E-C810-4C13-BAC3-1F53CF4BCB92}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Katteker/Properties/AssemblyInfo.cs b/Katteker/Properties/AssemblyInfo.cs index ba3bb53..6ccc645 100644 --- a/Katteker/Properties/AssemblyInfo.cs +++ b/Katteker/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // Allgemeine Informationen über eine Assembly werden über die folgenden @@ -33,3 +34,4 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.4")] [assembly: AssemblyFileVersion("1.0.4")] +[assembly: InternalsVisibleTo("Katteker.Test")] \ No newline at end of file diff --git a/Katteker/UpdateManager.cs b/Katteker/UpdateManager.cs index 5dd068d..a4961a9 100644 --- a/Katteker/UpdateManager.cs +++ b/Katteker/UpdateManager.cs @@ -15,7 +15,7 @@ namespace Katteker /// public class UpdateManager { - private static readonly string _baseDir = AppDomain.CurrentDomain.BaseDirectory; + private static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory; private static KattekerConfig _config; private readonly string _applicationName; private readonly string _packageDir; @@ -133,7 +133,7 @@ namespace Katteker private static KattekerConfig ReadConfigFile() { - var configPath = Path.Combine(_baseDir, Constants.KattekerConfig); + var configPath = Path.Combine(BaseDir, Constants.KattekerConfig); if (!File.Exists(configPath)) throw new FileNotFoundException("Configuration file not found.", configPath); return KattekerConfig.ReadFromFile(configPath); } diff --git a/Katteker/Utility.cs b/Katteker/Utility.cs index 2992406..29ffbaf 100644 --- a/Katteker/Utility.cs +++ b/Katteker/Utility.cs @@ -15,17 +15,14 @@ namespace Katteker return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); } - internal static string GetApplicationName() - { - return Assembly.GetEntryAssembly().GetName().Name; - } + internal static string GetApplicationName(Assembly assembly = null) => (assembly ?? Assembly.GetEntryAssembly()).GetName().Name; /// /// Is true if the url is a web-address. False otherwise. /// /// /// - public static bool IsWebUrl(string urlOrPath) + internal static bool IsWebUrl(string urlOrPath) { var uri = new Uri(urlOrPath); return uri.Scheme == "http" || uri.Scheme == "https"; @@ -37,7 +34,7 @@ namespace Katteker /// /// /// - public static string ComputeFileHash(string filename) + internal static string ComputeFileHash(string filename) { string sha1; var fileInfo = new FileInfo(filename); diff --git a/Katteker/VersionUtils.cs b/Katteker/VersionUtils.cs index b500be6..18fda63 100644 --- a/Katteker/VersionUtils.cs +++ b/Katteker/VersionUtils.cs @@ -12,11 +12,12 @@ namespace Katteker /// /// Get the current Version of Application. /// - public static SemVersion GetCurrentVersion() + public static SemVersion GetCurrentVersion(Assembly assembly = null) { - var assemblyVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(3); + var a = assembly ?? Assembly.GetEntryAssembly(); + var assemblyVersion = a.GetName().Version.ToString(3); var getCurrentVersion = SemVersion.Parse(assemblyVersion); - var informalVersion = Assembly.GetEntryAssembly().GetCustomAttribute()?.InformationalVersion; + var informalVersion = a.GetCustomAttribute()?.InformationalVersion; if (informalVersion != null && SemVersion.TryParse(informalVersion, out var semVersion)) return semVersion; return getCurrentVersion;