This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for framework initialization.
- Loading branch information
Brian Friesen
committed
May 21, 2014
1 parent
465f4c0
commit e7b10b1
Showing
16 changed files
with
313 additions
and
19 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
Rock.Core.IntegrationTests/AssemblyInitialization/ModuleInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Rock.Core.IntegrationTests.AssemblyInitialization | ||
{ | ||
// NOTE: This module initializer exists only to ensure that the module initialization tests | ||
// run successfully, even if the integration tests start first. NUnit seems to create a single | ||
// app domain for all of its tests, so order is important. This is also the reason why this | ||
// project references the unit test project. | ||
internal static class ModuleInitializer | ||
{ | ||
internal static void Run() | ||
{ | ||
Rock.AssemblyInitialization.ModuleInitializer.Run(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="InjectModuleInitializer" version="1.3.1" targetFramework="net45" developmentDependency="true" /> | ||
<package id="NUnit" version="2.6.3" targetFramework="net45" /> | ||
<package id="XSerializer" version="0.1.11" targetFramework="net45" /> | ||
</packages> |
29 changes: 29 additions & 0 deletions
29
...oduleInitializer.UnitTestSupport/AssemblyInitialization/FrameworkInitializerTestHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Rock.AssemblyInitialization; | ||
|
||
namespace Rock.Core.ModuleInitializer.UnitTestSupport.AssemblyInitialization | ||
{ | ||
public static class FrameworkInitializerTestHelper | ||
{ | ||
private static readonly List<Type> _calledFrameworkInitializers = new List<Type>(); | ||
|
||
/// <summary> | ||
/// A method to be called when an inheritor of <see cref="IFrameworkInitializer"/> has its | ||
/// <see cref="IFrameworkInitializer.Initialize"/> method called. | ||
/// </summary> | ||
public static void RegisterInitializeCall(Type frameworkInitializerType) | ||
{ | ||
_calledFrameworkInitializers.Add(frameworkInitializerType); | ||
} | ||
|
||
/// <summary> | ||
/// Gets a collection of types that are in the order that they were added via the | ||
/// <see cref="RegisterInitializeCall"/> method. | ||
/// </summary> | ||
public static IEnumerable<Type> CalledFrameworkInitializerTypes | ||
{ | ||
get { return _calledFrameworkInitializers; } | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Rock.Core.ModuleInitializer.UnitTestSupport/AssemblyInitialization/ModuleInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Rock.Core.ModuleInitializer.UnitTestSupport.AssemblyInitialization | ||
{ | ||
internal static class ModuleInitializer | ||
{ | ||
internal static void Run() | ||
{ | ||
Rock.AssemblyInitialization.ModuleInitializer.Run(); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ssemblyInitialization/Rock_Core_ModuleInitializer_UnitTestSupport_FrameworkInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Rock.AssemblyInitialization; | ||
|
||
namespace Rock.Core.ModuleInitializer.UnitTestSupport.AssemblyInitialization | ||
{ | ||
// ReSharper disable once InconsistentNaming | ||
/// <summary> | ||
/// This inheritor of IFrameworkInitializer counts the number of times any instance has its Initialize() method | ||
/// invoked. It also registers the instance call with FrameworkInitializerTestHelper when its Initializer() | ||
/// method is called. | ||
/// </summary> | ||
public class Rock_Core_ModuleInitializer_UnitTestSupport_FrameworkInitializer : IFrameworkInitializer | ||
{ | ||
public void Initialize() | ||
{ | ||
InitializeInvocationCount++; | ||
FrameworkInitializerTestHelper.RegisterInitializeCall(GetType()); | ||
} | ||
|
||
public static int InitializeInvocationCount { get; private set; } | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Rock.Core.ModuleInitializer.UnitTestSupport/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Rock.Core.ModuleInitializer.UnitTestSupport")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Rock.Core.ModuleInitializer.UnitTestSupport")] | ||
[assembly: AssemblyCopyright("Copyright © 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("5e3dbeb1-6c6c-4549-8aa8-0f10844763e9")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
67 changes: 67 additions & 0 deletions
67
...Core.ModuleInitializer.UnitTestSupport/Rock.Core.ModuleInitializer.UnitTestSupport.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{34D6B6AD-5725-469C-AF77-EAB7DBE61666}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Rock.Core.ModuleInitializer.UnitTestSupport</RootNamespace> | ||
<AssemblyName>Rock.Core.ModuleInitializer.UnitTestSupport</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</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="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="AssemblyInitialization\FrameworkInitializerTestHelper.cs" /> | ||
<Compile Include="AssemblyInitialization\ModuleInitializer.cs" /> | ||
<Compile Include="AssemblyInitialization\Rock_Core_ModuleInitializer_UnitTestSupport_FrameworkInitializer.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Rock.Core\Rock.Core.csproj"> | ||
<Project>{0feb58cd-b15c-4cdc-83d6-7621c1db98c7}</Project> | ||
<Name>Rock.Core</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="InjectModuleInitializer" AfterTargets="AfterBuild"> | ||
<Exec Command="..\packages\InjectModuleInitializer.1.3.1\tools\InjectModuleInitializer.exe "$(TargetPath)"" /> | ||
</Target> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="InjectModuleInitializer" version="1.3.1" targetFramework="net45" developmentDependency="true" /> | ||
</packages> |
10 changes: 10 additions & 0 deletions
10
Rock.Core.UnitTests/AssemblyInitialization/ModuleInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Rock.Core.UnitTests.AssemblyInitialization | ||
{ | ||
public static class ModuleInitializer | ||
{ | ||
public static void Run() | ||
{ | ||
global::Rock.AssemblyInitialization.ModuleInitializer.Run(); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
Rock.Core.UnitTests/AssemblyInitialization/ModuleInitializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using Rock.AssemblyInitialization; | ||
using Rock.Core.ModuleInitializer.UnitTestSupport.AssemblyInitialization; | ||
|
||
namespace Rock.Core.UnitTests.AssemblyInitialization | ||
{ | ||
public class ModuleInitializerTests | ||
{ | ||
[Test] | ||
public void EachImplementorOfIFrameworkInitializerHasItsInitializeMethodInvokedOnce() | ||
{ | ||
Assert.That(Rock_Core_UnitTests_FrameworkInitializer.InitializeInvocationCount, Is.EqualTo(1)); | ||
Assert.That(Rock_Core_ModuleInitializer_UnitTestSupport_FrameworkInitializer.InitializeInvocationCount, Is.EqualTo(1)); | ||
} | ||
|
||
/// <summary> | ||
/// Verify that instances of the inheritors of <see cref="IFrameworkInitializer"/> are executed | ||
/// in the correct order. The order should be such that an instance whose type's assembly | ||
/// is referenced by the assembly of another instance's type in the list should be before those | ||
/// other types. | ||
/// </summary> | ||
[Test] | ||
public void ImplementorsOfFrameworkInitializerAreExecutedInAssemblyReferenceOrder() | ||
{ | ||
Assert.That(FrameworkInitializerTestHelper.CalledFrameworkInitializerTypes, Is.EqualTo(TypesInAssemblyReferenceOrder)); | ||
} | ||
|
||
/// <summary> | ||
/// Get a collection of types, in "assembly reference" order. Since the assembly of | ||
/// <see cref="Rock_Core_ModuleInitializer_UnitTestSupport_FrameworkInitializer"/> is referenced by | ||
/// the assembly of <see cref="Rock_Core_UnitTests_FrameworkInitializer"/>, | ||
/// <see cref="Rock_Core_ModuleInitializer_UnitTestSupport_FrameworkInitializer"/> is first, and | ||
/// <see cref="Rock_Core_UnitTests_FrameworkInitializer"/> is second. | ||
/// </summary> | ||
private IEnumerable<Type> TypesInAssemblyReferenceOrder | ||
{ | ||
get | ||
{ | ||
yield return typeof(Rock_Core_ModuleInitializer_UnitTestSupport_FrameworkInitializer); | ||
yield return typeof(Rock_Core_UnitTests_FrameworkInitializer); | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Rock.Core.UnitTests/AssemblyInitialization/Rock_Core_UnitTests_FrameworkInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Rock.AssemblyInitialization; | ||
using Rock.Core.ModuleInitializer.UnitTestSupport.AssemblyInitialization; | ||
|
||
namespace Rock.Core.UnitTests.AssemblyInitialization | ||
{ | ||
// ReSharper disable once InconsistentNaming | ||
/// <summary> | ||
/// This inheritor of IFrameworkInitializer counts the number of times any instance has its Initialize() method | ||
/// invoked. It also registers the instance call with FrameworkInitializerTestHelper when its Initializer() | ||
/// method is called. | ||
/// </summary> | ||
public class Rock_Core_UnitTests_FrameworkInitializer : IFrameworkInitializer | ||
{ | ||
public void Initialize() | ||
{ | ||
InitializeInvocationCount++; | ||
FrameworkInitializerTestHelper.RegisterInitializeCall(GetType()); | ||
} | ||
|
||
public static int InitializeInvocationCount { get; private set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.