Added unittest
This commit is contained in:
parent
ff424c6c14
commit
71d5981b8d
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
|
@ -9,15 +9,16 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>KattekerCreator</RootNamespace>
|
||||
<AssemblyName>KattekerCreator</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
|
@ -15,7 +15,7 @@
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
|
78
Katteker.Test/Katteker.Test.csproj
Normal file
78
Katteker.Test/Katteker.Test.csproj
Normal 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>
|
52
Katteker.Test/KattekerLibTest.cs
Normal file
52
Katteker.Test/KattekerLibTest.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
20
Katteker.Test/Properties/AssemblyInfo.cs
Normal file
20
Katteker.Test/Properties/AssemblyInfo.cs
Normal 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")]
|
5
Katteker.Test/packages.config
Normal file
5
Katteker.Test/packages.config
Normal 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
BIN
Katteker.Test/testdata/Example.exe
vendored
Normal file
Binary file not shown.
@ -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
|
||||
|
@ -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")]
|
@ -15,7 +15,7 @@ namespace Katteker
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Is true if the url is a web-address. False otherwise.
|
||||
/// </summary>
|
||||
/// <param name="urlOrPath"></param>
|
||||
/// <returns></returns>
|
||||
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
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public static string ComputeFileHash(string filename)
|
||||
internal static string ComputeFileHash(string filename)
|
||||
{
|
||||
string sha1;
|
||||
var fileInfo = new FileInfo(filename);
|
||||
|
@ -12,11 +12,12 @@ namespace Katteker
|
||||
/// <summary>
|
||||
/// Get the current Version of Application.
|
||||
/// </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 informalVersion = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
|
||||
var informalVersion = a.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
|
||||
if (informalVersion != null && SemVersion.TryParse(informalVersion, out var semVersion))
|
||||
return semVersion;
|
||||
return getCurrentVersion;
|
||||
|
Loading…
x
Reference in New Issue
Block a user