Skip to content

Commit c90663b

Browse files
committed
PR review changes, added UT for GetWorkflowInstances
1 parent 56611a4 commit c90663b

File tree

3 files changed

+91
-8
lines changed

3 files changed

+91
-8
lines changed

src/WorkflowCore/Services/DefaultProviders/MemoryPersistenceProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public async Task<IEnumerable<WorkflowInstance>> GetWorkflowInstances(IEnumerabl
7070

7171
lock (_instances)
7272
{
73-
return _instances.Where(x => ids.Contains(x.Id, StringComparer.OrdinalIgnoreCase));
73+
return _instances.Where(x => ids.Contains(x.Id));
7474
}
7575
}
7676

src/providers/WorkflowCore.Persistence.MongoDB/Services/MongoPersistenceProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public async Task<IEnumerable<WorkflowInstance>> GetWorkflowInstances(IEnumerabl
121121
return new List<WorkflowInstance>();
122122
}
123123

124-
var result = await WorkflowInstances.FindAsync(x => ids.Contains(x.Id, StringComparer.OrdinalIgnoreCase));
124+
var result = await WorkflowInstances.FindAsync(x => ids.Contains(x.Id));
125125
return await result.ToListAsync();
126126
}
127127

test/WorkflowCore.UnitTests/BasePersistenceFixture.cs

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Text;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using FluentAssertions;
46
using WorkflowCore.Interface;
57
using WorkflowCore.Models;
6-
using Xunit;
7-
using FluentAssertions;
88
using WorkflowCore.TestAssets;
9-
using System.Threading.Tasks;
9+
using Xunit;
1010

1111
namespace WorkflowCore.UnitTests
1212
{
@@ -50,7 +50,7 @@ public void GetWorkflowInstance_should_retrieve_workflow()
5050
NextExecution = 0,
5151
Version = 1,
5252
WorkflowDefinitionId = "My Workflow",
53-
Reference = "My Reference"
53+
Reference = "My Reference"
5454
};
5555
workflow.ExecutionPointers.Add(new ExecutionPointer()
5656
{
@@ -69,6 +69,89 @@ public void GetWorkflowInstance_should_retrieve_workflow()
6969
.Scope.Should().ContainInOrder(workflow.ExecutionPointers.FindById("1").Scope);
7070
}
7171

72+
[Fact]
73+
public void GetWorkflowInstances_should_retrieve_workflows()
74+
{
75+
var workflow01 = new WorkflowInstance()
76+
{
77+
Data = new TestData() { Value1 = 7 },
78+
Description = "My Description",
79+
Status = WorkflowStatus.Runnable,
80+
NextExecution = 0,
81+
Version = 1,
82+
WorkflowDefinitionId = "My Workflow",
83+
Reference = "My Reference"
84+
};
85+
workflow01.ExecutionPointers.Add(new ExecutionPointer()
86+
{
87+
Id = "1",
88+
Active = true,
89+
StepId = 0,
90+
SleepUntil = new DateTime(2000, 1, 1).ToUniversalTime(),
91+
Scope = new List<string>() { "4", "3", "2", "1" }
92+
});
93+
var workflowId01 = Subject.CreateNewWorkflow(workflow01).Result;
94+
95+
var workflow02 = new WorkflowInstance()
96+
{
97+
Data = new TestData() { Value1 = 7 },
98+
Description = "My Description",
99+
Status = WorkflowStatus.Runnable,
100+
NextExecution = 0,
101+
Version = 1,
102+
WorkflowDefinitionId = "My Workflow",
103+
Reference = "My Reference"
104+
};
105+
workflow02.ExecutionPointers.Add(new ExecutionPointer()
106+
{
107+
Id = "1",
108+
Active = true,
109+
StepId = 0,
110+
SleepUntil = new DateTime(2000, 1, 1).ToUniversalTime(),
111+
Scope = new List<string>() { "4", "3", "2", "1" }
112+
});
113+
var workflowId02 = Subject.CreateNewWorkflow(workflow01).Result;
114+
115+
var workflow03 = new WorkflowInstance()
116+
{
117+
Data = new TestData() { Value1 = 7 },
118+
Description = "My Description",
119+
Status = WorkflowStatus.Runnable,
120+
NextExecution = 0,
121+
Version = 1,
122+
WorkflowDefinitionId = "My Workflow",
123+
Reference = "My Reference"
124+
};
125+
workflow03.ExecutionPointers.Add(new ExecutionPointer()
126+
{
127+
Id = "1",
128+
Active = true,
129+
StepId = 0,
130+
SleepUntil = new DateTime(2000, 1, 1).ToUniversalTime(),
131+
Scope = new List<string>() { "4", "3", "2", "1" }
132+
});
133+
var workflowId03 = Subject.CreateNewWorkflow(workflow01).Result;
134+
135+
var retrievedWorkflows = Subject.GetWorkflowInstances(new[] { workflowId01, workflowId02, workflowId03 }).Result;
136+
137+
retrievedWorkflows.Count().ShouldBeEquivalentTo(3);
138+
139+
var retrievedWorkflow01 = retrievedWorkflows.Single(o => o.Id == workflowId01);
140+
retrievedWorkflow01.ShouldBeEquivalentTo(workflow01);
141+
retrievedWorkflow01.ExecutionPointers.FindById("1")
142+
.Scope.Should().ContainInOrder(workflow01.ExecutionPointers.FindById("1").Scope);
143+
144+
var retrievedWorkflow02 = retrievedWorkflows.Single(o => o.Id == workflowId02);
145+
retrievedWorkflow02.ShouldBeEquivalentTo(workflow02);
146+
retrievedWorkflow02.ExecutionPointers.FindById("1")
147+
.Scope.Should().ContainInOrder(workflow02.ExecutionPointers.FindById("1").Scope);
148+
149+
var retrievedWorkflow03 = retrievedWorkflows.Single(o => o.Id == workflowId03);
150+
retrievedWorkflow03.ShouldBeEquivalentTo(workflow03);
151+
retrievedWorkflow03.ExecutionPointers.FindById("1")
152+
.Scope.Should().ContainInOrder(workflow03.ExecutionPointers.FindById("1").Scope);
153+
}
154+
72155
[Fact]
73156
public void PersistWorkflow()
74157
{
@@ -150,4 +233,4 @@ public class TestData
150233
{
151234
public int Value1 { get; set; }
152235
}
153-
}
236+
}

0 commit comments

Comments
 (0)