Tests: Add the ServiceDescriptorAssert class.

The class provides basic logic for analyzing parameters
pull/170/head
Oleg Nenashev 2016-12-23 22:29:24 +01:00
parent 67bfc6bcd2
commit 4db3266125
2 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,67 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using winsw;
using winsw.Configuration;
namespace winswTests.Util
{
public static class ServiceDescriptorAssert
{
// TODO: convert to Extension attributes once the .NET dependency is upgraded
// BTW there is a way to get them working in .NET2, but KISS
public static void AssertPropertyIsDefault(ServiceDescriptor d, string property)
{
PropertyInfo actualProperty = typeof(ServiceDescriptor).GetProperty(property);
Assert.IsNotNull(actualProperty, "Cannot find property " + property + " in the service descriptor" + d);
PropertyInfo defaultProperty = typeof(DefaultWinSWSettings).GetProperty(property);
Assert.IsNotNull(defaultProperty, "Cannot find property " + property + " in the default settings");
Assert.AreEqual(defaultProperty.GetValue(ServiceDescriptor.Defaults, null), actualProperty.GetValue(d, null),
"Value of property " + property + " does not equal to the default one");
}
public static void AssertPropertyIsDefault(ServiceDescriptor d, List<string> properties)
{
foreach (var prop in properties)
{
AssertPropertyIsDefault(d, prop);
}
}
public static void AssertAllOptionalPropertiesAreDefault(ServiceDescriptor d)
{
AssertPropertyIsDefault(d, AllOptionalProperties);
}
private static List<string> AllProperties {
get {
var res = new List<string>();
var properties = typeof(IWinSWConfiguration).GetProperties();
foreach (var prop in properties)
{
res.Add(prop.Name);
}
return res;
}
}
private static List<string> AllOptionalProperties
{
get
{
var properties = AllProperties;
properties.Remove("Id");
properties.Remove("Caption");
properties.Remove("Description");
properties.Remove("Executable");
return properties;
}
}
}
}

View File

@ -62,6 +62,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceDescriptorTests.cs" /> <Compile Include="ServiceDescriptorTests.cs" />
<Compile Include="Util\CLITestHelper.cs" /> <Compile Include="Util\CLITestHelper.cs" />
<Compile Include="Util\ServiceDescriptorAssert.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Core\ServiceWrapper\winsw.csproj"> <ProjectReference Include="..\..\Core\ServiceWrapper\winsw.csproj">