@@ -104,14 +104,87 @@ public async Task PushAsync_Complex_Situation()
104104 this . context . DatasyncOperationsQueue . Should ( ) . BeEmpty ( ) ;
105105
106106 // 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 ( ) ;
108108 pullResults . IsSuccessful . Should ( ) . BeTrue ( ) ;
109109 pullResults . Additions . Should ( ) . Be ( 0 ) ;
110110 pullResults . Deletions . Should ( ) . Be ( 0 ) ;
111111 // The service always replaces additions and replacements - updating the last updatedAt.
112112 pullResults . Replacements . Should ( ) . Be ( moviesToReplace . Count + 1 ) ;
113113 }
114114
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+
115188 [ Fact ]
116189 public async Task PushAsync_Multithreaded ( )
117190 {
@@ -176,7 +249,7 @@ public async Task PushAsync_Multithreaded()
176249 this . context . DatasyncOperationsQueue . Should ( ) . BeEmpty ( ) ;
177250
178251 // 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 ( ) ;
180253 pullResults . IsSuccessful . Should ( ) . BeTrue ( ) ;
181254 pullResults . Additions . Should ( ) . Be ( 0 ) ;
182255 pullResults . Deletions . Should ( ) . Be ( 0 ) ;
0 commit comments