Skip to content

Commit d3e28f3

Browse files
committed
Add a few more repo tests
1 parent 8143549 commit d3e28f3

File tree

4 files changed

+133
-1
lines changed

4 files changed

+133
-1
lines changed

IntegrationEngine.Core.Tests/IntegrationEngine.Core.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<Compile Include="StubElasticClient.cs" />
5555
<Compile Include="StubSearchResponse.cs" />
5656
<Compile Include="StubHit.cs" />
57+
<Compile Include="StubGetResponse.cs" />
5758
</ItemGroup>
5859
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
5960
<ItemGroup>

IntegrationEngine.Core.Tests/Storage/ElasticsearchRepositoryTest.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,36 @@ public void ShouldReturnListOfDocumentsWithIdsFromElasticsearch()
3434
Assert.That(actual, Is.Not.Empty);
3535
Assert.That(actual.First().Id, Is.EqualTo(expectedId));
3636
}
37+
38+
[Test]
39+
public void ShouldReturnNullIfDocumentIsNotFoundById()
40+
{
41+
var elasticClient = new Mock<StubElasticClient>();
42+
var getResponse = new Mock<StubGetResponse<CronTrigger>>();
43+
elasticClient.Setup(x => x.Get<CronTrigger>(It.IsAny<Func<GetDescriptor<CronTrigger>, GetDescriptor<CronTrigger>>>()))
44+
.Returns(getResponse.Object);
45+
Subject.ElasticClient = elasticClient.Object;
46+
47+
var actual = Subject.SelectById<CronTrigger>("1");
48+
49+
Assert.That(actual, Is.Null);
50+
}
51+
52+
[Test]
53+
public void ShouldReturnSingleDocumentGivenAnId()
54+
{
55+
var elasticClient = new Mock<StubElasticClient>();
56+
var getResponse = new Mock<StubGetResponse<CronTrigger>>();
57+
var expectedId = "1";
58+
getResponse.SetupGet(x => x.Id).Returns(() => expectedId);
59+
getResponse.SetupGet(x => x.Source).Returns(() => new CronTrigger());
60+
elasticClient.Setup(x => x.Get<CronTrigger>(It.IsAny<Func<GetDescriptor<CronTrigger>, GetDescriptor<CronTrigger>>>()))
61+
.Returns(getResponse.Object);
62+
Subject.ElasticClient = elasticClient.Object;
63+
64+
var actual = Subject.SelectById<CronTrigger>(expectedId);
65+
66+
Assert.That(actual.Id, Is.EqualTo(expectedId));
67+
}
3768
}
3869
}

IntegrationEngine.Core.Tests/StubElasticClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ public System.Threading.Tasks.Task<T> SourceAsync<T>(ISourceRequest sourceReques
11371137
throw new NotImplementedException();
11381138
}
11391139

1140-
public IGetResponse<T> Get<T>(Func<GetDescriptor<T>, GetDescriptor<T>> getSelector) where T : class
1140+
public virtual IGetResponse<T> Get<T>(Func<GetDescriptor<T>, GetDescriptor<T>> getSelector) where T : class
11411141
{
11421142
throw new NotImplementedException();
11431143
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
using Nest;
3+
4+
namespace IntegrationEngine.Core.Tests
5+
{
6+
public class StubGetResponse<TItem> : IGetResponse<TItem> where TItem : class
7+
{
8+
public StubGetResponse()
9+
{
10+
}
11+
12+
#region IGetResponse implementation
13+
14+
public bool Found {
15+
get {
16+
throw new NotImplementedException();
17+
}
18+
}
19+
20+
public string Index {
21+
get {
22+
throw new NotImplementedException();
23+
}
24+
}
25+
26+
public string Type {
27+
get {
28+
throw new NotImplementedException();
29+
}
30+
}
31+
32+
public virtual string Id {
33+
get {
34+
throw new NotImplementedException();
35+
}
36+
}
37+
38+
public string Version {
39+
get {
40+
throw new NotImplementedException();
41+
}
42+
}
43+
44+
public virtual TItem Source {
45+
get {
46+
throw new NotImplementedException();
47+
}
48+
}
49+
50+
public Nest.Domain.FieldSelection<TItem> Fields {
51+
get {
52+
throw new NotImplementedException();
53+
}
54+
}
55+
56+
#endregion
57+
58+
#region IResponse implementation
59+
60+
public bool IsValid {
61+
get {
62+
throw new NotImplementedException();
63+
}
64+
}
65+
66+
public Elasticsearch.Net.IElasticsearchResponse ConnectionStatus {
67+
get {
68+
throw new NotImplementedException();
69+
}
70+
}
71+
72+
public ElasticInferrer Infer {
73+
get {
74+
throw new NotImplementedException();
75+
}
76+
}
77+
78+
public Elasticsearch.Net.ElasticsearchServerError ServerError {
79+
get {
80+
throw new NotImplementedException();
81+
}
82+
}
83+
84+
#endregion
85+
86+
#region IResponseWithRequestInformation implementation
87+
88+
public Elasticsearch.Net.IElasticsearchResponse RequestInformation {
89+
get {
90+
throw new NotImplementedException();
91+
}
92+
set {
93+
throw new NotImplementedException();
94+
}
95+
}
96+
97+
#endregion
98+
}
99+
}
100+

0 commit comments

Comments
 (0)