8
8
using Backbone . ConsumerApi . Tests . Integration . Configuration ;
9
9
using Backbone . ConsumerApi . Tests . Integration . Extensions ;
10
10
using Backbone . ConsumerApi . Tests . Integration . Helpers ;
11
- using Backbone . ConsumerApi . Tests . Integration . Support ;
12
11
using Backbone . Crypto ;
13
12
using Backbone . DevelopmentKit . Identity . ValueObjects ;
14
13
using Backbone . UnitTestTools . Data ;
@@ -20,63 +19,40 @@ namespace Backbone.ConsumerApi.Tests.Integration.StepDefinitions;
20
19
[ Binding ]
21
20
[ Scope ( Feature = "POST Message" ) ]
22
21
[ Scope ( Feature = "GET Messages" ) ]
23
- internal class MessagesStepDefinitions
22
+ internal class MessagesStepDefinitions : BaseStepDefinitions
24
23
{
25
- private readonly ClientCredentials _clientCredentials ;
26
- private readonly HttpClient _httpClient ;
27
-
28
- private readonly Dictionary < string , Client > _identities = new ( ) ;
29
24
private readonly Dictionary < string , Relationship > _relationships = new ( ) ;
30
25
private readonly Dictionary < string , Message > _messages = new ( ) ;
31
26
private ApiResponse < ListMessagesResponse > ? _getMessagesResponse ;
32
27
private ApiResponse < SendMessageResponse > ? _sendMessageResponse ;
33
28
private IResponse ? _whenResponse ;
34
29
35
- public MessagesStepDefinitions ( HttpClientFactory factory , IOptions < HttpConfiguration > httpConfiguration )
36
- {
37
- _httpClient = factory . CreateClient ( ) ;
38
- _clientCredentials = new ClientCredentials ( httpConfiguration . Value . ClientCredentials . ClientId , httpConfiguration . Value . ClientCredentials . ClientSecret ) ;
39
- }
30
+ public MessagesStepDefinitions ( HttpClientFactory factory , IOptions < HttpConfiguration > httpConfiguration ) : base ( factory , httpConfiguration ) { }
40
31
41
32
#region Given
42
33
43
- [ Given ( @"Identities (i[a-zA-Z0-9]*) and (i[a-zA-Z0-9]*)" ) ]
44
- public void Given2Identities ( string identity1Name , string identity2Name )
45
- {
46
- _identities [ identity1Name ] = Client . CreateForNewIdentity ( _httpClient , _clientCredentials , Constants . DEVICE_PASSWORD ) . Result ;
47
- _identities [ identity2Name ] = Client . CreateForNewIdentity ( _httpClient , _clientCredentials , Constants . DEVICE_PASSWORD ) . Result ;
48
- }
49
-
50
- [ Given ( @"Identities (i[a-zA-Z0-9]*), (i[a-zA-Z0-9]*) and (i[a-zA-Z0-9]*)" ) ]
51
- public void Given3Identities ( string identity1Name , string identity2Name , string identity3Name )
52
- {
53
- _identities [ identity1Name ] = Client . CreateForNewIdentity ( _httpClient , _clientCredentials , Constants . DEVICE_PASSWORD ) . Result ;
54
- _identities [ identity2Name ] = Client . CreateForNewIdentity ( _httpClient , _clientCredentials , Constants . DEVICE_PASSWORD ) . Result ;
55
- _identities [ identity3Name ] = Client . CreateForNewIdentity ( _httpClient , _clientCredentials , Constants . DEVICE_PASSWORD ) . Result ;
56
- }
57
-
58
34
[ Given ( @"a Relationship (r[a-zA-Z0-9]*) between (i[a-zA-Z0-9]*) and (i[a-zA-Z0-9]*)" ) ]
59
35
public async Task GivenARelationshipRBetweenIAndI ( string relationshipName , string identity1Name , string identity2Name )
60
36
{
61
- var relationship = await Utils . EstablishRelationshipBetween ( _identities [ identity1Name ] , _identities [ identity2Name ] ) ;
37
+ var relationship = await Utils . EstablishRelationshipBetween ( Identities [ identity1Name ] , Identities [ identity2Name ] ) ;
62
38
_relationships [ relationshipName ] = relationship ;
63
39
}
64
40
65
41
[ Given ( @"(i[a-zA-Z0-9]*) has sent a Message (m[a-zA-Z0-9]*) to (i[a-zA-Z0-9]*)" ) ]
66
42
public async Task GivenIHasSentMessageTo1Recipient ( string senderName , string messageName , string recipientName )
67
43
{
68
- var sender = _identities [ senderName ] ;
69
- var recipient = _identities [ recipientName ] ;
44
+ var sender = Identities [ senderName ] ;
45
+ var recipient = Identities [ recipientName ] ;
70
46
71
47
_messages [ messageName ] = await Utils . SendMessage ( sender , recipient ) ;
72
48
}
73
49
74
50
[ Given ( @"(i[a-zA-Z0-9]*) has sent a Message (m[a-zA-Z0-9]*) to (i[a-zA-Z0-9]*) and (i[a-zA-Z0-9]*)" ) ]
75
51
public async Task GivenIHasSentMessageTo2Recipients ( string senderName , string messageName , string recipient1Name , string recipient2Name )
76
52
{
77
- var sender = _identities [ senderName ] ;
78
- var recipient1 = _identities [ recipient1Name ] ;
79
- var recipient2 = _identities [ recipient2Name ] ;
53
+ var sender = Identities [ senderName ] ;
54
+ var recipient1 = Identities [ recipient1Name ] ;
55
+ var recipient2 = Identities [ recipient2Name ] ;
80
56
81
57
_messages [ messageName ] = await Utils . SendMessage ( sender , recipient1 , recipient2 ) ;
82
58
}
@@ -85,7 +61,7 @@ public async Task GivenIHasSentMessageTo2Recipients(string senderName, string me
85
61
public async Task GivenRIsTerminated ( string terminatorName , string relationshipName )
86
62
{
87
63
var relationship = _relationships [ relationshipName ] ;
88
- var terminator = _identities [ terminatorName ] ;
64
+ var terminator = Identities [ terminatorName ] ;
89
65
90
66
var terminateRelationshipResponse = await terminator . Relationships . TerminateRelationship ( relationship . Id ) ;
91
67
terminateRelationshipResponse . Should ( ) . BeASuccess ( ) ;
@@ -94,7 +70,7 @@ public async Task GivenRIsTerminated(string terminatorName, string relationshipN
94
70
[ Given ( @"(i[a-zA-Z0-9]*) has decomposed (r[a-zA-Z0-9]*)" ) ]
95
71
public async Task GivenIHasDecomposedItsRelationshipToI ( string decomposerName , string relationshipName )
96
72
{
97
- var decomposer = _identities [ decomposerName ] ;
73
+ var decomposer = Identities [ decomposerName ] ;
98
74
var relationship = _relationships [ relationshipName ] ;
99
75
100
76
var decomposeRelationshipResponse = await decomposer . Relationships . DecomposeRelationship ( relationship . Id ) ;
@@ -106,7 +82,7 @@ public async Task GivenIHasDecomposedItsRelationshipToI(string decomposerName, s
106
82
[ Given ( "(i[a-zA-Z0-9]*) is in status \" ToBeDeleted\" " ) ]
107
83
public async Task GivenIdentityIIsToBeDeleted ( string identityName )
108
84
{
109
- var identity = _identities [ identityName ] ;
85
+ var identity = Identities [ identityName ] ;
110
86
var startDeletionProcessResponse = await identity . Identities . StartDeletionProcess ( ) ;
111
87
startDeletionProcessResponse . Should ( ) . BeASuccess ( ) ;
112
88
}
@@ -118,16 +94,16 @@ public async Task GivenIdentityIIsToBeDeleted(string identityName)
118
94
[ When ( @"(i[a-zA-Z0-9]*) sends a GET request to the /Messages endpoint" ) ]
119
95
public async Task WhenISendsAGETRequestToTheMessagesEndpoint ( string senderName )
120
96
{
121
- var sender = _identities [ senderName ] ;
97
+ var sender = Identities [ senderName ] ;
122
98
var getMessagesResponse = await sender . Messages . ListMessages ( ) ;
123
99
_whenResponse = _getMessagesResponse = getMessagesResponse ;
124
100
}
125
101
126
102
[ When ( "(i[a-zA-Z0-9]*) sends a POST request to the /Messages endpoint with (i[a-zA-Z0-9]*) as recipient" ) ]
127
103
public async Task WhenAPostRequestIsSentToTheMessagesEndpoint ( string senderName , string recipientName )
128
104
{
129
- var sender = _identities [ senderName ] ;
130
- var recipient = _identities [ recipientName ] ;
105
+ var sender = Identities [ senderName ] ;
106
+ var recipient = Identities [ recipientName ] ;
131
107
132
108
var sendMessageRequest = new SendMessageRequest
133
109
{
@@ -184,7 +160,7 @@ public void ThenTheResponseContainsTheMessageM(string messageName)
184
160
[ Then ( @"the address of the recipient (i[a-zA-Z0-9]*) is anonymized" ) ]
185
161
public void ThenTheAddressOfIIsAnonymized ( string anonymizedIdentityName )
186
162
{
187
- var addressOfIdentityThatShouldBeAnonymized = _identities [ anonymizedIdentityName ] . IdentityData ! . Address ;
163
+ var addressOfIdentityThatShouldBeAnonymized = Identities [ anonymizedIdentityName ] . IdentityData ! . Address ;
188
164
189
165
ThrowIfNull ( _getMessagesResponse ) ;
190
166
@@ -225,7 +201,7 @@ public void ThenTheResponseContentIncludesAnErrorWithTheErrorCode(string errorCo
225
201
[ Then ( @"the error contains a list of Identities to be deleted that includes (i[a-zA-Z0-9]*)" ) ]
226
202
public void ThenTheErrorContainsAListOfIdentitiesToBeDeletedThatIncludesIdentityI2 ( string includedIdentityName )
227
203
{
228
- var includedIdentity = _identities [ includedIdentityName ] ;
204
+ var includedIdentity = Identities [ includedIdentityName ] ;
229
205
var data = _sendMessageResponse ! . Error ! . Data ? . As < PeersToBeDeletedErrorData > ( ) ;
230
206
data . Should ( ) . NotBeNull ( ) ;
231
207
data ! . PeersToBeDeleted . Contains ( includedIdentity . IdentityData ! . Address ) . Should ( ) . BeTrue ( ) ;
0 commit comments