Added unittest

This commit is contained in:
Holger Börchers 2018-04-04 20:28:52 +02:00
parent ff424c6c14
commit 71d5981b8d
13 changed files with 187 additions and 25 deletions

View File

@ -1,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
</startup> </startup>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="NuGet.Frameworks" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <assemblyIdentity name="NuGet.Frameworks" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.4" newVersion="4.5.0.4" /> <bindingRedirect oldVersion="0.0.0.0-4.5.0.4" newVersion="4.5.0.4"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="NuGet.Versioning" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <assemblyIdentity name="NuGet.Versioning" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.4" newVersion="4.5.0.4" /> <bindingRedirect oldVersion="0.0.0.0-4.5.0.4" newVersion="4.5.0.4"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="NuGet.Packaging" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <assemblyIdentity name="NuGet.Packaging" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.4" newVersion="4.5.0.4" /> <bindingRedirect oldVersion="0.0.0.0-4.5.0.4" newVersion="4.5.0.4"/>
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>

View File

@ -9,15 +9,16 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KattekerCreator</RootNamespace> <RootNamespace>KattekerCreator</RootNamespace>
<AssemblyName>KattekerCreator</AssemblyName> <AssemblyName>KattekerCreator</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages> <RestorePackages>true</RestorePackages>
<NuGetPackageImportStamp> <NuGetPackageImportStamp>
</NuGetPackageImportStamp> </NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>

View File

@ -15,7 +15,7 @@
<TargetFrameworkProfile /> <TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{76E9E47E-C810-4C13-BAC3-1F53CF4BCB92}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Katteker.Test</RootNamespace>
<AssemblyName>Katteker.Test</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="KattekerLibTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="testdata\Example.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Katteker\Katteker.csproj">
<Project>{A45E1C59-BA9E-452C-A5E2-50DE49D53E92}</Project>
<Name>Katteker</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}".</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets')" />
</Project>

View File

@ -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<UriFormatException>(() => 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);
}
}
}

View File

@ -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")]

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="1.2.0" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.2.0" targetFramework="net461" />
</packages>

BIN
Katteker.Test/testdata/Example.exe vendored Normal file

Binary file not shown.

View File

@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Example\Example.
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Katteker.Gui", "Katteker.Gui\Katteker.Gui.csproj", "{07E2DE31-80A0-43DA-B307-1CA47CD930A1}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Katteker.Gui", "Katteker.Gui\Katteker.Gui.csproj", "{07E2DE31-80A0-43DA-B307-1CA47CD930A1}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Katteker.Test", "Katteker.Test\Katteker.Test.csproj", "{76E9E47E-C810-4C13-BAC3-1F53CF4BCB92}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{07E2DE31-80A0-43DA-B307-1CA47CD930A1}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,4 +1,5 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden // 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.*")]
[assembly: AssemblyVersion("1.0.4")] [assembly: AssemblyVersion("1.0.4")]
[assembly: AssemblyFileVersion("1.0.4")] [assembly: AssemblyFileVersion("1.0.4")]
[assembly: InternalsVisibleTo("Katteker.Test")]

View File

@ -15,7 +15,7 @@ namespace Katteker
/// </summary> /// </summary>
public class UpdateManager public class UpdateManager
{ {
private static readonly string _baseDir = AppDomain.CurrentDomain.BaseDirectory; private static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
private static KattekerConfig _config; private static KattekerConfig _config;
private readonly string _applicationName; private readonly string _applicationName;
private readonly string _packageDir; private readonly string _packageDir;
@ -133,7 +133,7 @@ namespace Katteker
private static KattekerConfig ReadConfigFile() 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); if (!File.Exists(configPath)) throw new FileNotFoundException("Configuration file not found.", configPath);
return KattekerConfig.ReadFromFile(configPath); return KattekerConfig.ReadFromFile(configPath);
} }

View File

@ -15,17 +15,14 @@ namespace Katteker
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
} }
internal static string GetApplicationName() internal static string GetApplicationName(Assembly assembly = null) => (assembly ?? Assembly.GetEntryAssembly()).GetName().Name;
{
return Assembly.GetEntryAssembly().GetName().Name;
}
/// <summary> /// <summary>
/// Is true if the url is a web-address. False otherwise. /// Is true if the url is a web-address. False otherwise.
/// </summary> /// </summary>
/// <param name="urlOrPath"></param> /// <param name="urlOrPath"></param>
/// <returns></returns> /// <returns></returns>
public static bool IsWebUrl(string urlOrPath) internal static bool IsWebUrl(string urlOrPath)
{ {
var uri = new Uri(urlOrPath); var uri = new Uri(urlOrPath);
return uri.Scheme == "http" || uri.Scheme == "https"; return uri.Scheme == "http" || uri.Scheme == "https";
@ -37,7 +34,7 @@ namespace Katteker
/// </summary> /// </summary>
/// <param name="filename"></param> /// <param name="filename"></param>
/// <returns></returns> /// <returns></returns>
public static string ComputeFileHash(string filename) internal static string ComputeFileHash(string filename)
{ {
string sha1; string sha1;
var fileInfo = new FileInfo(filename); var fileInfo = new FileInfo(filename);

View File

@ -12,11 +12,12 @@ namespace Katteker
/// <summary> /// <summary>
/// Get the current Version of Application. /// Get the current Version of Application.
/// </summary> /// </summary>
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 getCurrentVersion = SemVersion.Parse(assemblyVersion);
var informalVersion = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion; var informalVersion = a.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
if (informalVersion != null && SemVersion.TryParse(informalVersion, out var semVersion)) if (informalVersion != null && SemVersion.TryParse(informalVersion, out var semVersion))
return semVersion; return semVersion;
return getCurrentVersion; return getCurrentVersion;