@@ -411,4 +411,76 @@ public void ToOperationKind_Invalid_Throws()
411411 act . Should ( ) . Throw < InvalidOperationException > ( ) ;
412412 }
413413 #endregion
414+
415+ #region LazyLoadingProxies Support
416+ [ Fact ]
417+ public async Task LLP_PushAsync_Addition_Works ( )
418+ {
419+ TestDbContext llpContext = CreateContext ( x => x . UseLazyLoadingProxies ( ) ) ;
420+ ClientMovie clientMovie = new ( TestData . Movies . BlackPanther ) { Id = Guid . NewGuid ( ) . ToString ( "N" ) } ;
421+ string clientMovieJson = DatasyncSerializer . Serialize ( clientMovie ) ;
422+ llpContext . Movies . Add ( clientMovie ) ;
423+ llpContext . SaveChanges ( ) ;
424+
425+ ClientMovie responseMovie = new ( TestData . Movies . BlackPanther ) { Id = clientMovie . Id , UpdatedAt = DateTimeOffset . UtcNow , Version = Guid . NewGuid ( ) . ToString ( ) } ;
426+ string expectedJson = DatasyncSerializer . Serialize ( responseMovie ) ;
427+ llpContext . Handler . AddResponseContent ( expectedJson , HttpStatusCode . Created ) ;
428+
429+ PushResult results = await llpContext . QueueManager . PushAsync ( [ typeof ( ClientMovie ) ] , new PushOptions ( ) ) ;
430+ results . IsSuccessful . Should ( ) . BeTrue ( ) ;
431+ results . CompletedOperations . Should ( ) . Be ( 1 ) ;
432+ results . FailedRequests . Should ( ) . BeEmpty ( ) ;
433+
434+ llpContext . DatasyncOperationsQueue . Should ( ) . BeEmpty ( ) ;
435+
436+ ClientMovie actualMovie = llpContext . Movies . SingleOrDefault ( x => x . Id == clientMovie . Id ) ;
437+ actualMovie . UpdatedAt ! . Should ( ) . BeCloseTo ( ( DateTimeOffset ) responseMovie . UpdatedAt , TimeSpan . FromMicroseconds ( 1000 ) ) ;
438+ actualMovie . Version . Should ( ) . Be ( responseMovie . Version ) ;
439+ }
440+
441+ [ Fact ]
442+ public async Task LLP_PushAsync_Removal_Works ( )
443+ {
444+ TestDbContext llpContext = CreateContext ( x => x . UseLazyLoadingProxies ( ) ) ;
445+ ClientMovie clientMovie = new ( TestData . Movies . BlackPanther ) { Id = Guid . NewGuid ( ) . ToString ( "N" ) } ;
446+ llpContext . Movies . Add ( clientMovie ) ;
447+ llpContext . SaveChanges ( acceptAllChangesOnSuccess : true , addToQueue : false ) ;
448+
449+ llpContext . Movies . Remove ( clientMovie ) ;
450+ llpContext . SaveChanges ( ) ;
451+ llpContext . Handler . AddResponse ( HttpStatusCode . NoContent ) ;
452+
453+ PushResult results = await llpContext . QueueManager . PushAsync ( [ typeof ( ClientMovie ) ] , new PushOptions ( ) ) ;
454+ results . IsSuccessful . Should ( ) . BeTrue ( ) ;
455+ results . CompletedOperations . Should ( ) . Be ( 1 ) ;
456+ results . FailedRequests . Should ( ) . BeEmpty ( ) ;
457+
458+ llpContext . DatasyncOperationsQueue . Should ( ) . BeEmpty ( ) ;
459+ llpContext . Movies . Find ( clientMovie . Id ) . Should ( ) . BeNull ( ) ;
460+ }
461+
462+ [ Fact ]
463+ public async Task LLP_PushAsync_Replacement_Works ( )
464+ {
465+ TestDbContext llpContext = CreateContext ( x => x . UseLazyLoadingProxies ( ) ) ;
466+ ClientMovie clientMovie = new ( TestData . Movies . BlackPanther ) { Id = Guid . NewGuid ( ) . ToString ( "N" ) } ;
467+ llpContext . Movies . Add ( clientMovie ) ;
468+ llpContext . SaveChanges ( acceptAllChangesOnSuccess : true , addToQueue : false ) ;
469+
470+ clientMovie . Title = "Foo" ;
471+ llpContext . Update ( clientMovie ) ;
472+ llpContext . SaveChanges ( ) ;
473+
474+ ClientMovie responseMovie = new ( TestData . Movies . BlackPanther ) { Id = clientMovie . Id , UpdatedAt = DateTimeOffset . UtcNow , Version = Guid . NewGuid ( ) . ToString ( ) } ;
475+ string expectedJson = DatasyncSerializer . Serialize ( responseMovie ) ;
476+ llpContext . Handler . AddResponseContent ( expectedJson , HttpStatusCode . OK ) ;
477+
478+ PushResult results = await llpContext . QueueManager . PushAsync ( [ typeof ( ClientMovie ) ] , new PushOptions ( ) ) ;
479+ results . IsSuccessful . Should ( ) . BeTrue ( ) ;
480+ results . CompletedOperations . Should ( ) . Be ( 1 ) ;
481+ results . FailedRequests . Should ( ) . BeEmpty ( ) ;
482+
483+ llpContext . DatasyncOperationsQueue . Should ( ) . BeEmpty ( ) ;
484+ }
485+ #endregion
414486}
0 commit comments