@@ -48,6 +48,7 @@ public BeforeUpdate_WithDbValues_Tests()
48
48
[ Fact ]
49
49
public void BeforeUpdate ( )
50
50
{
51
+ // arrange
51
52
var todoDiscovery = SetDiscoverableHooks < TodoItem > ( AllHooks , EnableDbValuesEverywhere ) ;
52
53
var personDiscovery = SetDiscoverableHooks < Person > ( AllHooks , EnableDbValuesEverywhere ) ;
53
54
( var contextMock , var hookExecutor , var todoResourceMock ,
@@ -63,56 +64,49 @@ public void BeforeUpdate()
63
64
It . IsAny < IUpdatedRelationshipHelper < Person > > ( ) ,
64
65
ResourceAction . Patch ) ,
65
66
Times . Once ( ) ) ;
66
-
67
67
ownerResourceMock . Verify ( rd => rd . BeforeImplicitUpdateRelationship (
68
68
It . Is < IUpdatedRelationshipHelper < Person > > ( rh => PersonCheck ( lastName + lastName , rh ) ) ,
69
69
ResourceAction . Patch ) ,
70
70
Times . Once ( ) ) ;
71
-
72
71
todoResourceMock . Verify ( rd => rd . BeforeImplicitUpdateRelationship (
73
72
It . Is < IUpdatedRelationshipHelper < TodoItem > > ( rh => TodoCheck ( rh , description + description ) ) ,
74
73
ResourceAction . Patch ) ,
75
74
Times . Once ( ) ) ;
76
-
77
75
VerifyNoOtherCalls ( todoResourceMock , ownerResourceMock ) ;
78
76
}
79
77
80
78
81
79
[ Fact ]
82
- public void BeforeUpdate_Deleting_Relationship ( ) // TODO l=3 implicit needs to be tested here too
80
+ public void BeforeUpdate_Deleting_Relationship ( )
83
81
{
82
+ // arrange
84
83
var todoDiscovery = SetDiscoverableHooks < TodoItem > ( AllHooks , EnableDbValuesEverywhere ) ;
85
84
var personDiscovery = SetDiscoverableHooks < Person > ( AllHooks , EnableDbValuesEverywhere ) ;
86
85
( var contextMock , var hookExecutor , var todoResourceMock ,
87
86
var ownerResourceMock ) = CreateTestObjects ( todoDiscovery , personDiscovery , repoDbContextOptions : options ) ;
88
-
89
87
var attr = ResourceGraph . Instance . GetContextEntity ( typeof ( TodoItem ) ) . Relationships . Single ( r => r . PublicRelationshipName == "one-to-one-person" ) ;
90
88
contextMock . Setup ( c => c . RelationshipsToUpdate ) . Returns ( new Dictionary < RelationshipAttribute , object > ( ) { { attr , new object ( ) } } ) ;
91
89
92
90
// act
93
91
var todoList = new List < TodoItem > ( ) { new TodoItem { Id = this . todoList [ 0 ] . Id } } ;
94
92
hookExecutor . BeforeUpdate ( todoList , ResourceAction . Patch ) ;
95
93
96
-
97
94
// assert
98
95
todoResourceMock . Verify ( rd => rd . BeforeUpdate ( It . Is < EntityDiff < TodoItem > > ( ( diff ) => TodoCheck ( diff , description ) ) , ResourceAction . Patch ) , Times . Once ( ) ) ;
99
-
100
-
101
96
ownerResourceMock . Verify ( rd => rd . BeforeImplicitUpdateRelationship (
102
97
It . Is < IUpdatedRelationshipHelper < Person > > ( rh => PersonCheck ( lastName + lastName , rh ) ) ,
103
98
ResourceAction . Patch ) ,
104
99
Times . Once ( ) ) ;
105
-
106
100
VerifyNoOtherCalls ( todoResourceMock , ownerResourceMock ) ;
107
101
}
108
102
109
103
110
104
[ Fact ]
111
105
public void BeforeUpdate_Without_Parent_Hook_Implemented ( )
112
106
{
107
+ // arrange
113
108
var todoDiscovery = SetDiscoverableHooks < TodoItem > ( NoHooks ) ;
114
109
var personDiscovery = SetDiscoverableHooks < Person > ( AllHooks , EnableDbValuesEverywhere ) ;
115
-
116
110
( var contextMock , var hookExecutor , var todoResourceMock ,
117
111
var ownerResourceMock ) = CreateTestObjects ( todoDiscovery , personDiscovery , repoDbContextOptions : options ) ;
118
112
@@ -125,33 +119,38 @@ public void BeforeUpdate_Without_Parent_Hook_Implemented()
125
119
It . IsAny < IUpdatedRelationshipHelper < Person > > ( ) ,
126
120
ResourceAction . Patch ) ,
127
121
Times . Once ( ) ) ;
128
-
129
122
ownerResourceMock . Verify ( rd => rd . BeforeImplicitUpdateRelationship (
130
123
It . Is < IUpdatedRelationshipHelper < Person > > ( rh => PersonCheck ( lastName + lastName , rh ) ) ,
131
124
ResourceAction . Patch ) ,
132
125
Times . Once ( ) ) ;
133
-
134
126
VerifyNoOtherCalls ( todoResourceMock , ownerResourceMock ) ;
135
127
}
136
128
137
129
[ Fact ]
138
- public void BeforeUpdate_Without_Child_Hook_Implemented ( ) // TODO l=3 implicit needs to be tested here too
130
+ public void BeforeUpdate_Without_Child_Hook_Implemented ( )
139
131
{
140
132
// arrange
141
133
var todoDiscovery = SetDiscoverableHooks < TodoItem > ( AllHooks , EnableDbValuesEverywhere ) ;
142
134
var personDiscovery = SetDiscoverableHooks < Person > ( NoHooks ) ;
143
-
144
135
( var contextMock , var hookExecutor , var todoResourceMock ,
145
136
var ownerResourceMock ) = CreateTestObjects ( todoDiscovery , personDiscovery , repoDbContextOptions : options ) ;
146
137
147
138
// act
148
139
hookExecutor . BeforeUpdate ( todoList , ResourceAction . Patch ) ;
140
+
141
+ // assert
142
+ todoResourceMock . Verify ( rd => rd . BeforeUpdate ( It . Is < EntityDiff < TodoItem > > ( ( diff ) => TodoCheck ( diff , description ) ) , ResourceAction . Patch ) , Times . Once ( ) ) ;
143
+ todoResourceMock . Verify ( rd => rd . BeforeImplicitUpdateRelationship (
144
+ It . Is < IUpdatedRelationshipHelper < TodoItem > > ( rh => TodoCheck ( rh , description + description ) ) ,
145
+ ResourceAction . Patch ) ,
146
+ Times . Once ( ) ) ;
147
+ VerifyNoOtherCalls ( todoResourceMock , ownerResourceMock ) ;
149
148
}
150
149
151
150
[ Fact ]
152
151
public void BeforeUpdate_NoImplicit ( )
153
152
{
154
-
153
+ // arrange
155
154
var todoDiscovery = SetDiscoverableHooks < TodoItem > ( AllHooksNoImplicit , new ResourceHook [ ] { ResourceHook . BeforeUpdate } ) ;
156
155
var personDiscovery = SetDiscoverableHooks < Person > ( AllHooksNoImplicit , new ResourceHook [ ] { ResourceHook . BeforeUpdateRelationship } ) ;
157
156
( var contextMock , var hookExecutor , var todoResourceMock ,
@@ -167,7 +166,6 @@ public void BeforeUpdate_NoImplicit()
167
166
It . IsAny < IUpdatedRelationshipHelper < Person > > ( ) ,
168
167
ResourceAction . Patch ) ,
169
168
Times . Once ( ) ) ;
170
-
171
169
VerifyNoOtherCalls ( todoResourceMock , ownerResourceMock ) ;
172
170
}
173
171
@@ -198,7 +196,6 @@ public void BeforeUpdate_NoImplicit_Without_Child_Hook_Implemented()
198
196
// arrange
199
197
var todoDiscovery = SetDiscoverableHooks < TodoItem > ( AllHooksNoImplicit , new ResourceHook [ ] { ResourceHook . BeforeUpdate } ) ;
200
198
var personDiscovery = SetDiscoverableHooks < Person > ( NoHooks ) ;
201
-
202
199
( var contextMock , var hookExecutor , var todoResourceMock ,
203
200
var ownerResourceMock ) = CreateTestObjects ( todoDiscovery , personDiscovery , repoDbContextOptions : options ) ;
204
201
0 commit comments