@@ -104,14 +104,87 @@ public async Task PushAsync_Complex_Situation()
104
104
this . context . DatasyncOperationsQueue . Should ( ) . BeEmpty ( ) ;
105
105
106
106
// Now use PullAsync() again - these should all be pulled down again
107
- PullResult pullResults = await this . context . PullAsync ( ) ;
107
+ PullResult pullResults = await this . context . Movies . PullAsync ( ) ;
108
108
pullResults . IsSuccessful . Should ( ) . BeTrue ( ) ;
109
109
pullResults . Additions . Should ( ) . Be ( 0 ) ;
110
110
pullResults . Deletions . Should ( ) . Be ( 0 ) ;
111
111
// The service always replaces additions and replacements - updating the last updatedAt.
112
112
pullResults . Replacements . Should ( ) . Be ( moviesToReplace . Count + 1 ) ;
113
113
}
114
114
115
+ [ Fact ]
116
+ public async Task PushAsync_ByteVersion ( )
117
+ {
118
+ ResetInMemoryMovies ( ) ;
119
+
120
+ PullResult initialPullResults = await this . context . ByteMovies . PullAsync ( ) ;
121
+ initialPullResults . IsSuccessful . Should ( ) . BeTrue ( ) ;
122
+ initialPullResults . Additions . Should ( ) . Be ( 248 ) ;
123
+ initialPullResults . Deletions . Should ( ) . Be ( 0 ) ;
124
+ initialPullResults . Replacements . Should ( ) . Be ( 0 ) ;
125
+ this . context . ByteMovies . Should ( ) . HaveCount ( 248 ) ;
126
+
127
+ // Let's add some new movies
128
+ ByteVersionMovie blackPanther = new ( TestCommon . TestData . Movies . BlackPanther ) { Id = Guid . NewGuid ( ) . ToString ( "N" ) } ;
129
+ this . context . ByteMovies . Add ( blackPanther ) ;
130
+ await this . context . SaveChangesAsync ( ) ;
131
+
132
+ // And remove any movie that matches some criteria
133
+ List < ByteVersionMovie > moviesToDelete = await this . context . ByteMovies . Where ( x => x . Duration > 180 ) . ToListAsync ( ) ;
134
+ this . context . ByteMovies . RemoveRange ( moviesToDelete ) ;
135
+ await this . context . SaveChangesAsync ( ) ;
136
+
137
+ // Then replace all the Unrated movies with a rating of NC17
138
+ List < ByteVersionMovie > moviesToReplace = await this . context . ByteMovies . Where ( x => x . Rating == MovieRating . Unrated ) . ToListAsync ( ) ;
139
+ moviesToReplace . ForEach ( r =>
140
+ {
141
+ r . Rating = MovieRating . NC17 ;
142
+ r . Title = r . Title . PadLeft ( '-' ) ;
143
+ this . context . ByteMovies . Update ( r ) ;
144
+ } ) ;
145
+ await this . context . SaveChangesAsync ( ) ;
146
+
147
+ // Check the queue.
148
+ List < DatasyncOperation > operations = await this . context . DatasyncOperationsQueue . ToListAsync ( ) ;
149
+ operations . Count . Should ( ) . Be ( 1 + moviesToDelete . Count + moviesToReplace . Count ) ;
150
+ operations . Count ( x => x . Kind is OperationKind . Add ) . Should ( ) . Be ( 1 ) ;
151
+ operations . Count ( x => x . Kind is OperationKind . Delete ) . Should ( ) . Be ( moviesToDelete . Count ) ;
152
+ operations . Count ( x => x . Kind is OperationKind . Replace ) . Should ( ) . Be ( moviesToReplace . Count ) ;
153
+
154
+ // Now push the results and check what we did
155
+ PushResult pushResults = await this . context . PushAsync ( ) ;
156
+
157
+ // This little snippet of code is to aid debugging if this test fails
158
+ if ( ! pushResults . IsSuccessful )
159
+ {
160
+ foreach ( KeyValuePair < string , ServiceResponse > failedRequest in pushResults . FailedRequests )
161
+ {
162
+ string id = failedRequest . Key ;
163
+ ServiceResponse response = failedRequest . Value ;
164
+ string jsonContent = string . Empty ;
165
+ if ( response . HasContent )
166
+ {
167
+ using StreamReader reader = new ( response . ContentStream ) ;
168
+ jsonContent = reader . ReadToEnd ( ) ;
169
+ }
170
+
171
+ Console . WriteLine ( $ "FAILED REQUEST FOR ID: { id } : { response . StatusCode } \n { jsonContent } ") ;
172
+ }
173
+ }
174
+
175
+ pushResults . IsSuccessful . Should ( ) . BeTrue ( ) ;
176
+ pushResults . CompletedOperations . Should ( ) . Be ( 1 + moviesToDelete . Count + moviesToReplace . Count ) ;
177
+ this . context . DatasyncOperationsQueue . Should ( ) . BeEmpty ( ) ;
178
+
179
+ // Now use PullAsync() again - these should all be pulled down again
180
+ PullResult pullResults = await this . context . ByteMovies . PullAsync ( ) ;
181
+ pullResults . IsSuccessful . Should ( ) . BeTrue ( ) ;
182
+ pullResults . Additions . Should ( ) . Be ( 0 ) ;
183
+ pullResults . Deletions . Should ( ) . Be ( 0 ) ;
184
+ // The service always replaces additions and replacements - updating the last updatedAt.
185
+ pullResults . Replacements . Should ( ) . Be ( moviesToReplace . Count + 1 ) ;
186
+ }
187
+
115
188
[ Fact ]
116
189
public async Task PushAsync_Multithreaded ( )
117
190
{
@@ -176,7 +249,7 @@ public async Task PushAsync_Multithreaded()
176
249
this . context . DatasyncOperationsQueue . Should ( ) . BeEmpty ( ) ;
177
250
178
251
// Now use PullAsync() again - these should all be pulled down again
179
- PullResult pullResults = await this . context . PullAsync ( ) ;
252
+ PullResult pullResults = await this . context . Movies . PullAsync ( ) ;
180
253
pullResults . IsSuccessful . Should ( ) . BeTrue ( ) ;
181
254
pullResults . Additions . Should ( ) . Be ( 0 ) ;
182
255
pullResults . Deletions . Should ( ) . Be ( 0 ) ;
0 commit comments