Skip to content

Commit 0d37d34

Browse files
committed
Fix issues where es repo update and delete
* The mothods were not calling SelectById with an Id.
1 parent 437c273 commit 0d37d34

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

IntegrationEngine.Client.Tests/IntegrationEngine.Client.Tests.csproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -8,6 +8,8 @@
88
<RootNamespace>IntegrationEngine.Client.Tests</RootNamespace>
99
<AssemblyName>IntegrationEngine.Client.Tests</AssemblyName>
1010
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
12+
<RestorePackages>true</RestorePackages>
1113
</PropertyGroup>
1214
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1315
<DebugSymbols>true</DebugSymbols>
@@ -59,4 +61,14 @@
5961
<Name>IntegrationEngine.Client</Name>
6062
</ProjectReference>
6163
</ItemGroup>
64+
<ItemGroup>
65+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
66+
</ItemGroup>
67+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
68+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
69+
<PropertyGroup>
70+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
71+
</PropertyGroup>
72+
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
73+
</Target>
6274
</Project>

IntegrationEngine.Core/Storage/ElasticsearchRepository.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,22 @@ public TItem SelectById<TItem>(object id) where TItem : class, IHasStringId
4040

4141
public TItem Insert<TItem>(TItem item) where TItem : class, IHasStringId
4242
{
43-
return SelectById<TItem>(ElasticClient.Index<TItem>(item));
43+
var indexResponse = ElasticClient.Index<TItem>(item);
44+
return SelectById<TItem>(indexResponse.Id);
4445
}
4546

4647
public TItem Update<TItem>(TItem item) where TItem : class, IHasStringId
4748
{
48-
return SelectById<TItem>(ElasticClient.Update<TItem>(x => x
49+
var updateResponse = ElasticClient.Update<TItem>(x => x
4950
.Id(item.Id)
5051
.Doc(item)
51-
));
52+
);
53+
return SelectById<TItem>(updateResponse.Id);
5254
}
5355

5456
public void Delete<TItem>(object id) where TItem : class
5557
{
5658
ElasticClient.Delete<TItem>(x => x.Id(id.ToString()));
57-
5859
}
5960

6061
public bool Exists<TItem>(object id) where TItem : class

IntegrationEngine.Tests/Api/TriggerControllerBaseTest.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,19 @@ public void ShouldReturnBadRequestIfIdsDoNotMatchWhenUpdatingTrigger()
8787
public void ShouldScheduleJobWhenTriggerIsCreated()
8888
{
8989
var jobType = "MyProject.MyIntegrationJob";
90+
var triggerWithoutId = new TriggerStub() { JobType = jobType };
9091
var expected = new TriggerStub() {
91-
JobType = jobType
92+
JobType = jobType,
93+
Id = TriggerDocumentId,
9294
};
95+
MockElasticRepo.Setup(x => x.Insert(triggerWithoutId)).Returns(expected);
9396
MockEngineScheduler.Setup(x => x.ScheduleJobWithTrigger(expected));
94-
MockElasticRepo.Setup(x => x.Insert(expected)).Returns(expected);
9597

96-
Subject.Post(expected);
98+
Subject.Post(triggerWithoutId);
9799

100+
MockElasticRepo.Verify(x => x.Insert(triggerWithoutId), Times.Once);
98101
MockEngineScheduler.Verify(x => x
99-
.ScheduleJobWithTrigger(It.Is<TriggerStub>(y => y.JobType == jobType)), Times.Once);
102+
.ScheduleJobWithTrigger(It.Is<TriggerStub>(y => y.JobType == jobType && y.Id == TriggerDocumentId)), Times.Once);
100103
}
101104

102105
[Test]

IntegrationEngine/Api/TriggerControllerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public IHttpActionResult Post(T trigger)
5555
if (!ModelState.IsValid)
5656
BadRequest(ModelState);
5757
var triggerWithId = Repository.Insert(trigger);
58-
EngineScheduler.ScheduleJobWithTrigger(trigger);
58+
EngineScheduler.ScheduleJobWithTrigger(triggerWithId);
5959
return CreatedAtRoute("DefaultApi", new { id = triggerWithId.Id }, triggerWithId);
6060
}
6161

0 commit comments

Comments
 (0)