Skip to content

Commit 40aa35e

Browse files
committed
Use DocumentStub instead of CronTrigger in repo tests
1 parent 642fb22 commit 40aa35e

File tree

3 files changed

+48
-28
lines changed

3 files changed

+48
-28
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<Compile Include="Properties\AssemblyInfo.cs" />
5959
<Compile Include="Storage\ElasticsearchRepositoryTest.cs" />
6060
<Compile Include="Mail\MailClientTest.cs" />
61+
<Compile Include="Storage\DocumentStub.cs" />
6162
</ItemGroup>
6263
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
6364
<ItemGroup>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using IntegrationEngine.Model;
2+
using System;
3+
4+
namespace IntegrationEngine.Core.Tests.Storage
5+
{
6+
public class DocumentStub : IHasStringId
7+
{
8+
#region IHasStringId implementation
9+
10+
public string Id { get; set; }
11+
12+
#endregion
13+
14+
public DocumentStub()
15+
{
16+
}
17+
}
18+
}
19+

IntegrationEngine.Core.Tests/Storage/ElasticsearchRepositoryTest.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,44 @@ public void Setup()
2929
[Test]
3030
public void ShouldReturnListOfDocumentsWithIdsFromElasticsearch()
3131
{
32-
var searchResponse = new Mock<ISearchResponse<CronTrigger>>();
33-
var hits = new List<IHit<CronTrigger>>();
34-
var cronTrigger = new CronTrigger();
35-
var hit = new Mock<IHit<CronTrigger>>();
32+
var searchResponse = new Mock<ISearchResponse<DocumentStub>>();
33+
var hits = new List<IHit<DocumentStub>>();
34+
var cronTrigger = new DocumentStub();
35+
var hit = new Mock<IHit<DocumentStub>>();
3636
var expectedId = "1";
3737
hit.SetupGet(x => x.Source).Returns(() => cronTrigger);
3838
hit.SetupGet(x => x.Id).Returns(() => expectedId);
3939
hits.Add(hit.Object);
4040
searchResponse.SetupGet(x => x.Hits).Returns(() => hits);
41-
ElasticClient.Setup(x => x.Search<CronTrigger>(It.IsAny<Func<SearchDescriptor<CronTrigger>, SearchDescriptor<CronTrigger>>>()))
41+
ElasticClient.Setup(x => x.Search<DocumentStub>(It.IsAny<Func<SearchDescriptor<DocumentStub>, SearchDescriptor<DocumentStub>>>()))
4242
.Returns(searchResponse.Object);
4343

44-
var actual = Subject.SelectAll<CronTrigger>();
44+
var actual = Subject.SelectAll<DocumentStub>();
4545

4646
Assert.That(actual, Is.Not.Empty);
4747
Assert.That(actual.First().Id, Is.EqualTo(expectedId));
48-
ElasticClient.Verify(x => x.Search(It.IsAny<Func<SearchDescriptor<CronTrigger>, SearchDescriptor<CronTrigger>>>()), Times.Once);
48+
ElasticClient.Verify(x => x.Search(It.IsAny<Func<SearchDescriptor<DocumentStub>, SearchDescriptor<DocumentStub>>>()), Times.Once);
4949
}
5050

5151
[Test]
5252
public void ShouldReturnNullIfDocumentIsNotFoundById()
5353
{
54-
var getResponse = new Mock<IGetResponse<CronTrigger>>();
55-
ElasticClient.Setup(x => x.Get(It.IsAny<Func<GetDescriptor<CronTrigger>, GetDescriptor<CronTrigger>>>()))
54+
var getResponse = new Mock<IGetResponse<DocumentStub>>();
55+
ElasticClient.Setup(x => x.Get(It.IsAny<Func<GetDescriptor<DocumentStub>, GetDescriptor<DocumentStub>>>()))
5656
.Returns(getResponse.Object);
5757

58-
var actual = Subject.SelectById<CronTrigger>("1");
58+
var actual = Subject.SelectById<DocumentStub>("1");
5959

6060
Assert.That(actual, Is.Null);
61-
ElasticClient.Verify(x => x.Get(It.IsAny<Func<GetDescriptor<CronTrigger>, GetDescriptor<CronTrigger>>>()), Times.Once);
61+
ElasticClient.Verify(x => x.Get(It.IsAny<Func<GetDescriptor<DocumentStub>, GetDescriptor<DocumentStub>>>()), Times.Once);
6262
}
6363

6464
void SetupForGetDocument(string id)
6565
{
66-
var getResponse = new Mock<IGetResponse<CronTrigger>>();
66+
var getResponse = new Mock<IGetResponse<DocumentStub>>();
6767
getResponse.SetupGet(x => x.Id).Returns(() => id);
68-
getResponse.SetupGet(x => x.Source).Returns(() => new CronTrigger());
69-
ElasticClient.Setup(x => x.Get(It.IsAny<Func<GetDescriptor<CronTrigger>, GetDescriptor<CronTrigger>>>()))
68+
getResponse.SetupGet(x => x.Source).Returns(() => new DocumentStub());
69+
ElasticClient.Setup(x => x.Get(It.IsAny<Func<GetDescriptor<DocumentStub>, GetDescriptor<DocumentStub>>>()))
7070
.Returns(getResponse.Object);
7171
}
7272

@@ -76,64 +76,64 @@ public void ShouldReturnSingleDocumentGivenAnId()
7676
var expectedId = "1";
7777
SetupForGetDocument(expectedId);
7878

79-
var actual = Subject.SelectById<CronTrigger>(expectedId);
79+
var actual = Subject.SelectById<DocumentStub>(expectedId);
8080

8181
Assert.That(actual.Id, Is.EqualTo(expectedId));
82-
ElasticClient.Verify(x => x.Get(It.IsAny<Func<GetDescriptor<CronTrigger>, GetDescriptor<CronTrigger>>>()), Times.Once);
82+
ElasticClient.Verify(x => x.Get(It.IsAny<Func<GetDescriptor<DocumentStub>, GetDescriptor<DocumentStub>>>()), Times.Once);
8383
}
8484

8585
[Test]
8686
public void ShouldInsertAndReturnDocument()
8787
{
8888
var expectedId = "1";
8989
SetupForGetDocument(expectedId);
90-
var expected = new CronTrigger() { Id = expectedId };
90+
var expected = new DocumentStub() { Id = expectedId };
9191
var indexResponse = new Mock<IIndexResponse>();
9292
indexResponse.SetupGet(x => x.Id).Returns(() => expected.Id);
93-
ElasticClient.Setup(x => x.Index(expected, It.IsAny<Func<IndexDescriptor<CronTrigger>, IndexDescriptor<CronTrigger>>>()))
93+
ElasticClient.Setup(x => x.Index(expected, It.IsAny<Func<IndexDescriptor<DocumentStub>, IndexDescriptor<DocumentStub>>>()))
9494
.Returns(indexResponse.Object);
9595

9696
var actual = Subject.Insert(expected);
9797

9898
Assert.That(actual.Id, Is.EqualTo(expected.Id));
99-
ElasticClient.Verify(x => x.Index(expected, It.IsAny<Func<IndexDescriptor<CronTrigger>, IndexDescriptor<CronTrigger>>>()), Times.Once);
99+
ElasticClient.Verify(x => x.Index(expected, It.IsAny<Func<IndexDescriptor<DocumentStub>, IndexDescriptor<DocumentStub>>>()), Times.Once);
100100
}
101101

102102
[Test]
103103
public void ShouldUpdateAndReturnDocument()
104104
{
105105
var expectedId = "1";
106106
SetupForGetDocument(expectedId);
107-
var expected = new CronTrigger() { Id = expectedId };
107+
var expected = new DocumentStub() { Id = expectedId };
108108
var updateResponse = new Mock<IUpdateResponse>();
109109
updateResponse.SetupGet(x => x.Id).Returns(() => expected.Id);
110-
ElasticClient.Setup(x => x.Update<CronTrigger>(It.IsAny<Func<UpdateDescriptor<CronTrigger, CronTrigger>, UpdateDescriptor<CronTrigger, CronTrigger>>>()))
110+
ElasticClient.Setup(x => x.Update<DocumentStub>(It.IsAny<Func<UpdateDescriptor<DocumentStub, DocumentStub>, UpdateDescriptor<DocumentStub, DocumentStub>>>()))
111111
.Returns(updateResponse.Object);
112112

113113
var actual = Subject.Update(expected);
114114

115115
Assert.That(actual.Id, Is.EqualTo(expected.Id));
116116
ElasticClient.Verify(
117-
x => x.Update<CronTrigger>(It.IsAny<Func<UpdateDescriptor<CronTrigger, CronTrigger>, UpdateDescriptor<CronTrigger, CronTrigger>>>()),
117+
x => x.Update<DocumentStub>(It.IsAny<Func<UpdateDescriptor<DocumentStub, DocumentStub>, UpdateDescriptor<DocumentStub, DocumentStub>>>()),
118118
Times.Once);
119119
}
120120

121121
[Test]
122122
public void ShouldDeleteDocument()
123123
{
124124
var id = "1";
125-
ElasticClient.Setup(x => x.Delete(It.IsAny<Func<DeleteDescriptor<CronTrigger>, DeleteDescriptor<CronTrigger>>>()));
125+
ElasticClient.Setup(x => x.Delete(It.IsAny<Func<DeleteDescriptor<DocumentStub>, DeleteDescriptor<DocumentStub>>>()));
126126

127-
Subject.Delete<CronTrigger>(id);
127+
Subject.Delete<DocumentStub>(id);
128128

129-
ElasticClient.Verify(x => x.Delete(It.IsAny<Func<DeleteDescriptor<CronTrigger>, DeleteDescriptor<CronTrigger>>>()), Times.Once);
129+
ElasticClient.Verify(x => x.Delete(It.IsAny<Func<DeleteDescriptor<DocumentStub>, DeleteDescriptor<DocumentStub>>>()), Times.Once);
130130
}
131131

132132
void SetupForDocumentExists(bool exists)
133133
{
134134
var existsResponse = new Mock<IExistsResponse>();
135135
existsResponse.SetupGet(x => x.Exists).Returns(exists);
136-
ElasticClient.Setup(x => x.DocumentExists(It.IsAny<Func<DocumentExistsDescriptor<CronTrigger>, DocumentExistsDescriptor<CronTrigger>>>()))
136+
ElasticClient.Setup(x => x.DocumentExists(It.IsAny<Func<DocumentExistsDescriptor<DocumentStub>, DocumentExistsDescriptor<DocumentStub>>>()))
137137
.Returns(existsResponse.Object);
138138
}
139139

@@ -142,7 +142,7 @@ public void ShouldReturnTrueIfDocumentExists()
142142
{
143143
SetupForDocumentExists(true);
144144

145-
var actual = Subject.Exists<CronTrigger>("does not exist");
145+
var actual = Subject.Exists<DocumentStub>("does not exist");
146146

147147
Assert.That(actual, Is.True);
148148
}
@@ -152,7 +152,7 @@ public void ShouldReturnFalseIfDocumentDoesNotExist()
152152
{
153153
SetupForDocumentExists(false);
154154

155-
var actual = Subject.Exists<CronTrigger>("does not exist");
155+
var actual = Subject.Exists<DocumentStub>("does not exist");
156156

157157
Assert.That(actual, Is.False);
158158
}

0 commit comments

Comments
 (0)