Skip to content

Commit 5a25790

Browse files
committed
Merge branch 'develop'
2 parents 625befb + bbdb048 commit 5a25790

File tree

91 files changed

+1966
-926
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1966
-926
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
using BeekmanLabs.UnitTesting;
2+
using IntegrationEngine.Model;
3+
using Newtonsoft.Json;
4+
using NUnit.Framework;
5+
using Moq;
6+
using RestSharp;
7+
using System;
8+
using System.Net;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
12+
namespace IntegrationEngine.Client.Tests
13+
{
14+
public class InEngineClientTest : TestBase<InEngineClient>
15+
{
16+
Mock<IRestClient> MockRestClient { get; set; }
17+
Mock<IJsonConvert> MockJsonConvert { get; set; }
18+
string ResourceStubName { get; set; }
19+
string HealthStatusName { get; set; }
20+
21+
[SetUp]
22+
public void Setup()
23+
{
24+
MockRestClient = new Mock<IRestClient>();
25+
Subject.RestClient = MockRestClient.Object;
26+
MockJsonConvert = new Mock<IJsonConvert>();
27+
Subject.JsonConvert = MockJsonConvert.Object;
28+
ResourceStubName = typeof(ResourceStub).Name;
29+
HealthStatusName = typeof(HealthStatus).Name;
30+
}
31+
32+
[Test]
33+
public void ShouldInstantiateWithDefaultApiUrl()
34+
{
35+
var expectedApiUrl = "http://localhost:9001/api/";
36+
var expected = new Uri(expectedApiUrl);
37+
MockRestClient.SetupGet(x => x.BaseUrl).Returns(expected);
38+
39+
var actual = Subject.ApiUrl;
40+
41+
Assert.That(actual.AbsoluteUri, Is.EqualTo(expected));
42+
}
43+
44+
[Test]
45+
public void ShouldQueryTheHealthStatusEndpointAndReturnStatusCodeWhenPinging()
46+
{
47+
var restResponse = new RestResponse() { StatusCode = HttpStatusCode.OK };
48+
MockRestClient.Setup(x => x.Execute(It.Is<RestRequest>(y => y.Resource == HealthStatusName))).Returns(restResponse);
49+
50+
var actual = Subject.Ping();
51+
52+
MockRestClient.Verify(x => x.Execute(It.Is<RestRequest>(y => y.Resource == HealthStatusName)), Times.Once);
53+
Assert.That(actual, Is.TypeOf(typeof(HttpStatusCode)));
54+
}
55+
56+
[Test]
57+
public void ShouldReturnHealthStatus()
58+
{
59+
var expected = new HealthStatus() {
60+
IsElasticsearchServerAvailable = true,
61+
IsMailServerAvailable = true,
62+
IsMessageQueueServerAvailable = true,
63+
};
64+
var content = JsonConvert.SerializeObject(expected);
65+
var restResponse = new RestResponse() { Content = content };
66+
MockRestClient.Setup(x => x.Execute(It.Is<RestRequest>(y => y.Resource == HealthStatusName)))
67+
.Returns(restResponse);
68+
MockJsonConvert.Setup(x => x.DeserializeObject<HealthStatus>(content))
69+
.Returns(expected);
70+
71+
var actual = Subject.GetHealthStatus();
72+
73+
Assert.That(actual, Is.EqualTo(expected));
74+
MockRestClient.Verify(x => x.Execute(It.Is<RestRequest>(y => y.Resource == HealthStatusName)), Times.Once);
75+
MockJsonConvert.Verify(x => x.DeserializeObject<HealthStatus>(content), Times.Once);
76+
}
77+
78+
79+
[Test]
80+
public void ShouldGetCollectionOfResourceStubs()
81+
{
82+
var expected = new List<ResourceStub>();
83+
var content = JsonConvert.SerializeObject(expected);
84+
var restResponse = new RestResponse() { Content = content };
85+
MockRestClient.Setup(x => x.Execute(It.Is<RestRequest>(y => y.Resource == ResourceStubName)))
86+
.Returns(restResponse);
87+
MockJsonConvert.Setup(x => x.DeserializeObject<IList<ResourceStub>>(content))
88+
.Returns(expected);
89+
90+
var actual = Subject.GetCollection<ResourceStub>();
91+
92+
Assert.That(actual.ToList(), Is.EquivalentTo(expected));
93+
MockRestClient.Verify(x => x.Execute(It.Is<RestRequest>(y => y.Resource == ResourceStubName)), Times.Once);
94+
MockJsonConvert.Verify(x => x.DeserializeObject<IList<ResourceStub>>(content), Times.Once);
95+
}
96+
97+
[Test]
98+
public void ShouldReturnResourceStubGivenAnId()
99+
{
100+
var id = "1";
101+
var resource = ResourceStubName + "/{id}";
102+
var expected = new ResourceStub();
103+
var content = JsonConvert.SerializeObject(expected);
104+
var restResponse = new RestResponse() { Content = content };
105+
MockRestClient.Setup(x => x.Execute(It.Is<RestRequest>(y => y.Resource == resource)))
106+
.Returns(restResponse);
107+
MockJsonConvert.Setup(x => x.DeserializeObject<ResourceStub>(content))
108+
.Returns(expected);
109+
110+
var actual = Subject.Get<ResourceStub>(id);
111+
112+
Assert.That(actual, Is.EqualTo(expected));
113+
MockRestClient.Verify(x => x.Execute(It.Is<RestRequest>(y => y.Resource == resource)), Times.Once);
114+
MockJsonConvert.Verify(x => x.DeserializeObject<ResourceStub>(content), Times.Once);
115+
}
116+
117+
[Test]
118+
public void ShouldCreateAndReturnResourceStub()
119+
{
120+
var expected = new ResourceStub();
121+
var content = JsonConvert.SerializeObject(expected);
122+
var restResponse = new RestResponse() { Content = content };
123+
MockRestClient.Setup(x => x.Execute(It.Is<RestRequest>(y => y.Resource == ResourceStubName)))
124+
.Returns(restResponse);
125+
MockJsonConvert.Setup(x => x.DeserializeObject<ResourceStub>(content))
126+
.Returns(expected);
127+
128+
var actual = Subject.Create(expected);
129+
130+
Assert.That(actual, Is.EqualTo(expected));
131+
MockRestClient.Verify(x => x.Execute(It.Is<RestRequest>(y => y.Resource == ResourceStubName)), Times.Once);
132+
MockJsonConvert.Verify(x => x.DeserializeObject<ResourceStub>(content), Times.Once);
133+
}
134+
135+
[Test]
136+
public void ShouldUpdateAndReturnResourceStub()
137+
{
138+
var resource = ResourceStubName + "/{id}";
139+
var expected = new ResourceStub();
140+
var content = JsonConvert.SerializeObject(expected);
141+
var restResponse = new RestResponse() { Content = content };
142+
MockRestClient.Setup(x => x.Execute(It.Is<RestRequest>(y => y.Resource == resource)))
143+
.Returns(restResponse);
144+
MockJsonConvert.Setup(x => x.DeserializeObject<ResourceStub>(content))
145+
.Returns(expected);
146+
147+
var actual = Subject.Update(expected);
148+
149+
Assert.That(actual, Is.EqualTo(expected));
150+
MockRestClient.Verify(x => x.Execute(It.Is<RestRequest>(y => y.Resource == resource)), Times.Once);
151+
MockJsonConvert.Verify(x => x.DeserializeObject<ResourceStub>(content), Times.Once);
152+
}
153+
154+
[Test]
155+
public void ShouldDeleteAndReturnResourceStub()
156+
{
157+
var id = "1";
158+
var resource = ResourceStubName + "/{id}";
159+
var expected = new ResourceStub();
160+
var content = JsonConvert.SerializeObject(expected);
161+
var restResponse = new RestResponse() { Content = content };
162+
MockRestClient.Setup(x => x.Execute(It.Is<RestRequest>(y => y.Resource == resource)))
163+
.Returns(restResponse);
164+
MockJsonConvert.Setup(x => x.DeserializeObject<ResourceStub>(content))
165+
.Returns(expected);
166+
167+
var actual = Subject.Delete<ResourceStub>(id);
168+
169+
Assert.That(actual, Is.EqualTo(expected));
170+
MockRestClient.Verify(x => x.Execute(It.Is<RestRequest>(y => y.Resource == resource)), Times.Once);
171+
MockJsonConvert.Verify(x => x.DeserializeObject<ResourceStub>(content), Times.Once);
172+
}
173+
}
174+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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>{8F491136-6C38-4A8E-BFEA-9234FB981414}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<RootNamespace>IntegrationEngine.Client.Tests</RootNamespace>
9+
<AssemblyName>IntegrationEngine.Client.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.1409.1722\lib\net40\Moq.dll</HintPath>
40+
</Reference>
41+
<Reference Include="RestSharp">
42+
<HintPath>..\packages\RestSharp.105.0.1\lib\net4\RestSharp.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Newtonsoft.Json">
45+
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
46+
</Reference>
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="Properties\AssemblyInfo.cs" />
50+
<Compile Include="InEngineClientTest.cs" />
51+
<Compile Include="ResourceStub.cs" />
52+
</ItemGroup>
53+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
54+
<ItemGroup>
55+
<None Include="packages.config" />
56+
</ItemGroup>
57+
<ItemGroup>
58+
<ProjectReference Include="..\IntegrationEngine.Client\IntegrationEngine.Client.csproj">
59+
<Project>{F3FCB706-F0DD-46C1-B121-785757FAE9B9}</Project>
60+
<Name>IntegrationEngine.Client</Name>
61+
</ProjectReference>
62+
<ProjectReference Include="..\IntegrationEngine.Model\IntegrationEngine.Model.csproj">
63+
<Project>{0B499FE4-0BDB-4080-BCB7-F8D4CE54A4FF}</Project>
64+
<Name>IntegrationEngine.Model</Name>
65+
</ProjectReference>
66+
</ItemGroup>
67+
<ItemGroup>
68+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
69+
</ItemGroup>
70+
</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("IntegrationEngine.Client.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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using IntegrationEngine.Model;
3+
4+
namespace IntegrationEngine.Client.Tests
5+
{
6+
public class ResourceStub : IHasStringId
7+
{
8+
public string Id { get; set; }
9+
}
10+
}
11+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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.1409.1722" targetFramework="net45" />
5+
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
6+
<package id="NUnit" version="2.6.4" targetFramework="net45" />
7+
<package id="RestSharp" version="105.0.1" targetFramework="net45" />
8+
</packages>

IntegrationEngine.Client.net40/IntegrationEngine.Client.net40.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@
5050
<Compile Include="..\configuration\SharedAssemblyInfo.cs">
5151
<Link>Properties\SharedAssemblyInfo.cs</Link>
5252
</Compile>
53-
<Compile Include="..\IntegrationEngine.Client\EndpointName.cs">
54-
<Link>EndpointName.cs</Link>
55-
</Compile>
5653
<Compile Include="..\IntegrationEngine.Client\IInEngineClient.cs">
5754
<Link>IInEngineClient.cs</Link>
5855
</Compile>
5956
<Compile Include="..\IntegrationEngine.Client\InEngineClient.cs">
6057
<Link>InEngineClient.cs</Link>
6158
</Compile>
6259
<Compile Include="Properties\AssemblyInfo.cs" />
60+
<Compile Include="..\IntegrationEngine.Client\IJsonConvert.cs">
61+
<Link>IJsonConvert.cs</Link>
62+
</Compile>
63+
<Compile Include="..\IntegrationEngine.Client\JsonConvertAdapter.cs">
64+
<Link>JsonConvertAdapter.cs</Link>
65+
</Compile>
6366
</ItemGroup>
6467
<ItemGroup>
6568
<None Include="packages.config" />

IntegrationEngine.Client/Endpoint.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace IntegrationEngine.Client
4+
{
5+
public enum Endpoint
6+
{
7+
CronTrigger,
8+
SimpleTrigger,
9+
JobType,
10+
LogEvent,
11+
HealthStatus,
12+
}
13+
}
14+

IntegrationEngine.Client/EndpointName.cs

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

IntegrationEngine.Client/IInEngineClient.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using InEngineTimeZone = IntegrationEngine.Model.TimeZone;
2-
using IntegrationEngine.Model;
1+
using IntegrationEngine.Model;
32
using System;
43
using System.Collections.Generic;
54
using System.Net;
@@ -8,7 +7,13 @@ namespace IntegrationEngine.Client
87
{
98
public interface IInEngineClient
109
{
10+
IJsonConvert JsonConvert { get; set; }
1111
HttpStatusCode Ping();
12+
IList<TItem> GetCollection<TItem>() where TItem : class;
13+
TItem Get<TItem>(string id) where TItem : class, IHasStringId;
14+
TItem Create<TItem>(TItem item);
15+
TItem Update<TItem>(TItem item) where TItem : class, IHasStringId;
16+
TItem Delete<TItem>(string id);
1217
IList<CronTrigger> GetCronTriggers();
1318
CronTrigger GetCronTriggerById(string id);
1419
CronTrigger CreateCronTrigger(CronTrigger cronTrigger);
@@ -19,7 +24,7 @@ public interface IInEngineClient
1924
SimpleTrigger CreateSimpleTrigger(SimpleTrigger simpleTrigger);
2025
SimpleTrigger UpdateSimpleTrigger(SimpleTrigger simpleTrigger);
2126
SimpleTrigger DeleteSimpleTrigger(string id);
22-
IList<InEngineTimeZone> GetTimeZones();
27+
IList<LogEvent> GetLogEvents();
2328
IList<JobType> GetJobTypes();
2429
HealthStatus GetHealthStatus();
2530
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace IntegrationEngine.Client
4+
{
5+
public interface IJsonConvert
6+
{
7+
T DeserializeObject<T>(string value);
8+
}
9+
}
10+

0 commit comments

Comments
 (0)