Skip to content

Commit 0b2d4c4

Browse files
committed
Add some tests
1 parent 77eafc1 commit 0b2d4c4

12 files changed

Lines changed: 218 additions & 76 deletions

File tree

IntegrationEngine.Tests/EngineHostCompositionRootTest.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
using Moq;
1010
using Nest;
1111
using NUnit.Framework;
12+
using IntegrationServer;
13+
using System.Reflection;
14+
using System.Collections.Generic;
1215

1316
namespace IntegrationEngine.Tests
1417
{
@@ -76,5 +79,37 @@ public void ShouldDisposeOfResources()
7679

7780
mockWebApiApplication.Verify(x => x.Dispose(), Times.Once);
7881
}
82+
83+
[Test]
84+
public void ShouldRegisterIntegrationPoints()
85+
{
86+
Subject.EngineConfiguration = new EngineConfiguration();
87+
Subject.LoadConfiguration();
88+
89+
Subject.RegisterIntegrationPoints();
90+
91+
var container = Subject.Container;
92+
container.Resolve<IMailConfiguration>("DefaultMail");
93+
container.Resolve<IMailConfiguration>("FooMailClient");
94+
container.Resolve<IElasticsearchConfiguration>("DefaultElasticsearch");
95+
container.Resolve<IRabbitMQConfiguration>("DefaultRabbitMQ");
96+
container.Resolve<IJsonServiceConfiguration>("ExampleJsonService");
97+
}
98+
99+
[Test]
100+
public void ShouldRegisterIntegrationJobs()
101+
{
102+
var assembliesWithJobs = new List<Assembly> { typeof(Program).Assembly };
103+
Subject.IntegrationJobTypes = Subject.ExtractIntegrationJobTypesFromAssemblies(assembliesWithJobs);
104+
Subject.LoadConfiguration();
105+
Subject.RegisterIntegrationPoints();
106+
107+
Subject.RegisterIntegrationJobs();
108+
109+
var container = Subject.Container;
110+
container.Resolve<CarMailMessageJob>();
111+
container.Resolve<CarReportJob>();
112+
container.Resolve<SampleSqlReportJob>();
113+
}
79114
}
80115
}

IntegrationEngine.Tests/IntegrationEngine.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@
147147
<Project>{7D49353D-A68C-4ACA-A6A5-40B1C314C30E}</Project>
148148
<Name>IntegrationEngine</Name>
149149
</ProjectReference>
150+
<ProjectReference Include="..\IntegrationServer\IntegrationServer.csproj">
151+
<Project>{C273AE91-E13F-4443-8D01-9C97016AB4AC}</Project>
152+
<Name>IntegrationServer</Name>
153+
</ProjectReference>
150154
</ItemGroup>
151155
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
152156
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

IntegrationEngine.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationEngine.Client.Te
4646
EndProject
4747
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationEngine.Core.net40", "IntegrationEngine.Core.net40\IntegrationEngine.Core.net40.csproj", "{9332D22A-0D09-4DA7-B2F9-6DE7E9F28715}"
4848
EndProject
49+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationServer.Tests", "IntegrationServer.Tests\IntegrationServer.Tests.csproj", "{2E912FF3-B29A-441E-B32D-4647EA33F490}"
50+
EndProject
4951
Global
5052
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5153
Debug|Any CPU = Debug|Any CPU
@@ -76,6 +78,18 @@ Global
7678
{0B499FE4-0BDB-4080-BCB7-F8D4CE54A4FF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
7779
{0B499FE4-0BDB-4080-BCB7-F8D4CE54A4FF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
7880
{0B499FE4-0BDB-4080-BCB7-F8D4CE54A4FF}.Release|x86.ActiveCfg = Release|Any CPU
81+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
82+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Debug|Any CPU.Build.0 = Debug|Any CPU
83+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
84+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
85+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Debug|x86.ActiveCfg = Debug|Any CPU
86+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Debug|x86.Build.0 = Debug|Any CPU
87+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Release|Any CPU.ActiveCfg = Release|Any CPU
88+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Release|Any CPU.Build.0 = Release|Any CPU
89+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
90+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Release|Mixed Platforms.Build.0 = Release|Any CPU
91+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Release|x86.ActiveCfg = Release|Any CPU
92+
{2E912FF3-B29A-441E-B32D-4647EA33F490}.Release|x86.Build.0 = Release|Any CPU
7993
{3F3794D7-4078-4D26-954C-7864173EDD86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
8094
{3F3794D7-4078-4D26-954C-7864173EDD86}.Debug|Any CPU.Build.0 = Debug|Any CPU
8195
{3F3794D7-4078-4D26-954C-7864173EDD86}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU

IntegrationEngine.userprefs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<Properties StartupItem="IntegrationServer/IntegrationServer.csproj">
22
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
3-
<MonoDevelop.Ide.Workbench ActiveDocument="IntegrationServer/IntegrationJobs/SampleSqlReport/SampleSqlReportJob.cs">
3+
<MonoDevelop.Ide.Workbench ActiveDocument="IntegrationEngine.Tests/EngineHostCompositionRootTest.cs">
44
<Files>
5-
<File FileName="IntegrationEngine.Core/IntegrationJob/IIntegrationJob.cs" Line="1" Column="1" />
6-
<File FileName="IntegrationEngine.Core/IntegrationJob/IParameterizedJob.cs" Line="1" Column="1" />
7-
<File FileName="IntegrationEngine.Core/IntegrationJob/IntegrationJobRunFailureException.cs" Line="1" Column="1" />
8-
<File FileName="IntegrationEngine.Core/Configuration/IJsonServiceConfiguration.cs" Line="1" Column="1" />
5+
<File FileName="IntegrationServer/IntegrationJobs/CarReport/CarMailMessageJob.cs" Line="1" Column="1" />
6+
<File FileName="IntegrationServer.Tests/IntegrationJobs/CarReport/CarMailMessageJobTest.cs" Line="13" Column="13" />
7+
<File FileName="IntegrationEngine/EngineHostCompositionRoot.cs" Line="46" Column="46" />
8+
<File FileName="IntegrationEngine.Tests/EngineHostCompositionRootTest.cs" Line="52" Column="52" />
99
<File FileName="IntegrationServer/Program.cs" Line="1" Column="1" />
10-
<File FileName="IntegrationServer/InEngineServerInstaller.cs" Line="1" Column="1" />
11-
<File FileName="IntegrationServer/IntegrationJobs/SampleSqlReport/SampleSqlReportJob.cs" Line="7" Column="7" />
12-
<File FileName="IntegrationServer/IntegrationPoints/FooMailClient.cs" Line="1" Column="1" />
13-
<File FileName="IntegrationServer/IntegrationPoints/IFooMailClient.cs" Line="1" Column="1" />
1410
</Files>
11+
<Pads>
12+
<Pad Id="MonoDevelop.NUnit.TestPad">
13+
<State expanded="True" selected="True" />
14+
</Pad>
15+
</Pads>
1516
</MonoDevelop.Ide.Workbench>
1617
<MonoDevelop.Ide.DebuggingService.Breakpoints>
1718
<BreakpointStore />

IntegrationEngine/EngineHost.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
1-
using System;
1+
using Microsoft.Practices.Unity;
2+
using System;
23
using System.Collections.Generic;
3-
using System.Reflection;
44
using System.Linq;
5+
using System.Reflection;
56

67
namespace IntegrationEngine
78
{
89
public class EngineHost : IDisposable
910
{
10-
EngineHostCompositionRoot _engineConfiguration;
11+
EngineHostCompositionRoot engineHostCompositionRoot;
12+
public IUnityContainer Container { get { return engineHostCompositionRoot.Container; } }
1113
public IList<Assembly> AssembliesWithJobs { get; set; }
12-
14+
1315
public EngineHost(params Assembly[] assembliesWithJobs)
1416
{
1517
AssembliesWithJobs = assembliesWithJobs.ToList();
1618
}
1719

1820
public void Dispose()
1921
{
20-
if (_engineConfiguration != null)
21-
_engineConfiguration.Dispose();
22+
if (engineHostCompositionRoot != null)
23+
engineHostCompositionRoot.Dispose();
2224
}
2325

24-
public void Initialize()
26+
public void Initialize(bool isThreadedListenerEnabled = true,
27+
bool isSchedulerEnabled = true,
28+
bool isWebApiEnabled = true)
2529
{
26-
_engineConfiguration = new EngineHostCompositionRoot();
27-
_engineConfiguration.Configure(AssembliesWithJobs);
30+
engineHostCompositionRoot = new EngineHostCompositionRoot(AssembliesWithJobs) {
31+
IsWebApiEnabled = isWebApiEnabled,
32+
IsSchedulerEnabled = isSchedulerEnabled,
33+
IsThreadedListenerEnabled = isThreadedListenerEnabled,
34+
};
35+
engineHostCompositionRoot.Configure();
2836
}
2937
}
3038
}

IntegrationEngine/EngineHostCompositionRoot.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,42 @@ public class EngineHostCompositionRoot : IDisposable
3333
public IList<Type> IntegrationJobTypes { get; set; }
3434
public ILog Log { get; set; }
3535
public IWebApiApplication WebApiApplication { get; set; }
36+
public bool IsWebApiEnabled { get; set; }
37+
public bool IsSchedulerEnabled { get; set; }
38+
public bool IsThreadedListenerEnabled { get; set; }
3639

3740
public EngineHostCompositionRoot()
3841
{}
3942

40-
public void Configure(IList<Assembly> assembliesWithJobs)
43+
public EngineHostCompositionRoot(IList<Assembly> assembliesWithJobs)
44+
: this()
45+
{
46+
IntegrationJobTypes = ExtractIntegrationJobTypesFromAssemblies(assembliesWithJobs);
47+
}
48+
49+
public IList<Type> ExtractIntegrationJobTypesFromAssemblies(IList<Assembly> assembliesWithJobs)
50+
{
51+
return assembliesWithJobs
52+
.SelectMany(x => x.GetTypes())
53+
.Where(x => typeof(IIntegrationJob).IsAssignableFrom(x) && x.IsClass)
54+
.ToList();
55+
}
56+
57+
public void Configure()
4158
{
4259
Container = ContainerSingleton.GetContainer();
43-
IntegrationJobTypes = assembliesWithJobs
44-
.SelectMany(x => x.GetTypes())
45-
.Where(x => typeof(IIntegrationJob).IsAssignableFrom(x) && x.IsClass)
46-
.ToList();
4760
LoadConfiguration();
4861
SetupLogging();
4962
RegisterIntegrationPoints();
5063
RegisterIntegrationJobs();
5164
SetupRScriptRunner();
5265
SetupElasticsearchRepository();
53-
SetupThreadedListenerManager();
54-
SetupEngineScheduler();
55-
SetupWebApi();
66+
if (IsThreadedListenerEnabled)
67+
SetupThreadedListenerManager();
68+
if (IsSchedulerEnabled)
69+
SetupEngineScheduler();
70+
if (IsWebApiEnabled)
71+
SetupWebApi();
5672
}
5773

5874
public void LoadConfiguration()
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{2E912FF3-B29A-441E-B32D-4647EA33F490}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<RootNamespace>IntegrationServer.Tests</RootNamespace>
9+
<AssemblyName>IntegrationServer.Tests</AssemblyName>
10+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11+
</PropertyGroup>
12+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
13+
<DebugSymbols>true</DebugSymbols>
14+
<DebugType>full</DebugType>
15+
<Optimize>false</Optimize>
16+
<OutputPath>bin\Debug</OutputPath>
17+
<DefineConstants>DEBUG;</DefineConstants>
18+
<ErrorReport>prompt</ErrorReport>
19+
<WarningLevel>4</WarningLevel>
20+
<ConsolePause>false</ConsolePause>
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
23+
<DebugType>full</DebugType>
24+
<Optimize>true</Optimize>
25+
<OutputPath>bin\Release</OutputPath>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
<ConsolePause>false</ConsolePause>
29+
</PropertyGroup>
30+
<ItemGroup>
31+
<Reference Include="System" />
32+
<Reference Include="nunit.framework">
33+
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
34+
</Reference>
35+
<Reference Include="BeekmanLabs.UnitTesting">
36+
<HintPath>..\packages\BeekmanLabs.UnitTesting.0.0.0\lib\net45\BeekmanLabs.UnitTesting.dll</HintPath>
37+
</Reference>
38+
<Reference Include="Moq">
39+
<HintPath>..\packages\Moq.4.2.1502.0911\lib\net40\Moq.dll</HintPath>
40+
</Reference>
41+
<Reference Include="Microsoft.Practices.Unity">
42+
<HintPath>..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Microsoft.Practices.Unity.Configuration">
45+
<HintPath>..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.Configuration.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Microsoft.Practices.Unity.RegistrationByConvention">
48+
<HintPath>..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll</HintPath>
49+
</Reference>
50+
</ItemGroup>
51+
<ItemGroup>
52+
<Compile Include="Properties\AssemblyInfo.cs" />
53+
</ItemGroup>
54+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
55+
<ItemGroup>
56+
<None Include="packages.config" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<ProjectReference Include="..\IntegrationServer\IntegrationServer.csproj">
60+
<Project>{C273AE91-E13F-4443-8D01-9C97016AB4AC}</Project>
61+
<Name>IntegrationServer</Name>
62+
</ProjectReference>
63+
<ProjectReference Include="..\IntegrationEngine.Core\IntegrationEngine.Core.csproj">
64+
<Project>{3F3794D7-4078-4D26-954C-7864173EDD86}</Project>
65+
<Name>IntegrationEngine.Core</Name>
66+
</ProjectReference>
67+
<ProjectReference Include="..\IntegrationEngine.Model\IntegrationEngine.Model.csproj">
68+
<Project>{0B499FE4-0BDB-4080-BCB7-F8D4CE54A4FF}</Project>
69+
<Name>IntegrationEngine.Model</Name>
70+
</ProjectReference>
71+
<ProjectReference Include="..\IntegrationEngine\IntegrationEngine.csproj">
72+
<Project>{7D49353D-A68C-4ACA-A6A5-40B1C314C30E}</Project>
73+
<Name>IntegrationEngine</Name>
74+
</ProjectReference>
75+
</ItemGroup>
76+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
// Information about this assembly is defined by the following attributes.
5+
// Change them to the values specific to your project.
6+
7+
[assembly: AssemblyTitle("IntegrationServer.Tests")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("")]
12+
[assembly: AssemblyCopyright("ethanhann")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
18+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
19+
20+
[assembly: AssemblyVersion("1.0.*")]
21+
22+
// The following attributes are used to specify the signing key for the assembly,
23+
// if desired. See the Mono documentation for more information about signing.
24+
25+
//[assembly: AssemblyDelaySign(false)]
26+
//[assembly: AssemblyKeyFile("")]
27+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="BeekmanLabs.UnitTesting" version="0.0.0" targetFramework="net45" />
4+
<package id="Moq" version="4.2.1502.0911" targetFramework="net45" />
5+
<package id="NUnit" version="2.6.4" targetFramework="net45" />
6+
<package id="Unity" version="3.5.1404.0" targetFramework="net45" />
7+
</packages>

IntegrationServer/IntegrationJobs/SampleSqlReport/SampleSqlReportJobWithIntegrationPoints.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)