-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCorrelationStoreTests.cs
More file actions
115 lines (92 loc) · 5.03 KB
/
CorrelationStoreTests.cs
File metadata and controls
115 lines (92 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System.Linq;
using System.Threading.Tasks;
using Cleipnir.ResilientFunctions.Helpers;
using Cleipnir.ResilientFunctions.Storage;
using Cleipnir.ResilientFunctions.Tests.Utils;
using Shouldly;
namespace Cleipnir.ResilientFunctions.Tests.TestTemplates;
public abstract class CorrelationStoreTests
{
public abstract Task SunshineScenario();
public async Task SunshineScenario(Task<IFunctionStore> storeTask)
{
var correlationStore = await storeTask.SelectAsync(s => s.CorrelationStore);
var storedId = TestStoredId.Create();
await correlationStore.SetCorrelation(storedId, "SomeCorrelationId");
await correlationStore
.GetCorrelations(storedId.Type, correlationId: "SomeCorrelationId")
.SelectAsync(c => c.Single())
.ShouldBeAsync(storedId);
await correlationStore
.GetCorrelations(storedId)
.SelectAsync(c => c.Single())
.ShouldBeAsync("SomeCorrelationId");
}
public abstract Task TwoDifferentFunctionsCanUseTheSameCorrelationId();
public async Task TwoDifferentFunctionsCanUseTheSameCorrelationId(Task<IFunctionStore> storeTask)
{
var correlationStore = await storeTask.SelectAsync(s => s.CorrelationStore);
var storedId1 = TestStoredId.Create();
var storedId2 = TestStoredId.Create();
await correlationStore.SetCorrelation(storedId1, correlationId: "TwoDifferentFunctionsCanUseTheSameCorrelationId");
await correlationStore.SetCorrelation(storedId2, correlationId: "TwoDifferentFunctionsCanUseTheSameCorrelationId");
var instances = await correlationStore
.GetCorrelations(storedId1.Type, correlationId: "TwoDifferentFunctionsCanUseTheSameCorrelationId");
instances.Count.ShouldBe(1);
instances.Single().ShouldBe(storedId1);
instances = await correlationStore
.GetCorrelations(storedId2.Type, correlationId: "TwoDifferentFunctionsCanUseTheSameCorrelationId");
instances.Count.ShouldBe(1);
instances.Single().ShouldBe(storedId2);
}
public abstract Task FunctionCorrelationsCanBeDeleted();
public async Task FunctionCorrelationsCanBeDeleted(Task<IFunctionStore> storeTask)
{
var correlationStore = await storeTask.SelectAsync(s => s.CorrelationStore);
var functionId = TestStoredId.Create();
await correlationStore.SetCorrelation(functionId, "SomeCorrelationId1");
await correlationStore.SetCorrelation(functionId, "SomeCorrelationId2");
await correlationStore.RemoveCorrelations(functionId);
(await correlationStore.GetCorrelations(functionId)).ShouldBeEmpty();
}
public abstract Task SingleFunctionCorrelationCanBeDeleted();
public async Task SingleFunctionCorrelationCanBeDeleted(Task<IFunctionStore> storeTask)
{
var correlationStore = await storeTask.SelectAsync(s => s.CorrelationStore);
var functionId = TestStoredId.Create();
await correlationStore.SetCorrelation(functionId, "SomeCorrelationId1");
await correlationStore.SetCorrelation(functionId, "SomeCorrelationId2");
await correlationStore.RemoveCorrelation(functionId, "SomeCorrelationId1");
await correlationStore
.GetCorrelations(functionId)
.SelectAsync(c => c.Single())
.ShouldBeAsync("SomeCorrelationId2");
}
public abstract Task SingleFunctionCanHaveMultipleCorrelations();
public async Task SingleFunctionCanHaveMultipleCorrelations(Task<IFunctionStore> storeTask)
{
var correlationStore = await storeTask.SelectAsync(s => s.CorrelationStore);
var functionId = TestStoredId.Create();
await correlationStore.SetCorrelation(functionId, "SomeCorrelationId1");
await correlationStore.SetCorrelation(functionId, "SomeCorrelationId2");
var correlations = await correlationStore.GetCorrelations(functionId);
correlations.Count.ShouldBe(2);
correlations.Any(c => c == "SomeCorrelationId1").ShouldBeTrue();
correlations.Any(c => c == "SomeCorrelationId2").ShouldBeTrue();
}
public abstract Task FunctionInstancesCanBeFetchedForFunctionTypeAndCorrelation();
public async Task FunctionInstancesCanBeFetchedForFunctionTypeAndCorrelation(Task<IFunctionStore> storeTask)
{
var correlationStore = await storeTask.SelectAsync(s => s.CorrelationStore);
var storedId1 = TestStoredId.Create();
var storedId2 = TestStoredId.Create(storedId1.Type);
var storedId3 = TestStoredId.Create();
await correlationStore.SetCorrelation(storedId1, "SomeCorrelationId1");
await correlationStore.SetCorrelation(storedId2, "SomeCorrelationId1");
await correlationStore.SetCorrelation(storedId3, "SomeCorrelationId1");
var instances = await correlationStore.GetCorrelations(storedId1.Type, "SomeCorrelationId1");
instances.Count.ShouldBe(2);
instances.Any(i => i == storedId1).ShouldBeTrue();
instances.Any(i => i == storedId2).ShouldBeTrue();
}
}