@@ -1433,6 +1433,59 @@ public async Task DbSet_PushAsync_Throws_OnNonOfflineDbContext()
14331433 }
14341434 #endregion
14351435
1436+ #region SynchronizationProgress
1437+ [ Fact ]
1438+ public async Task SynchronizationProgress_Event_Works ( )
1439+ {
1440+ Page < ClientMovie > page1 = CreatePage ( 5 , 20 , "$skip=5" ) ;
1441+ Page < ClientMovie > page2 = CreatePage ( 5 , 20 , "$skip=10" ) ;
1442+ Page < ClientMovie > page3 = CreatePage ( 5 , 20 , "$skip=15" ) ;
1443+ Page < ClientMovie > page4 = CreatePage ( 5 , 20 ) ;
1444+
1445+ this . context . Handler . AddResponse ( HttpStatusCode . OK , page1 ) ;
1446+ this . context . Handler . AddResponse ( HttpStatusCode . OK , page2 ) ;
1447+ this . context . Handler . AddResponse ( HttpStatusCode . OK , page3 ) ;
1448+ this . context . Handler . AddResponse ( HttpStatusCode . OK , page4 ) ;
1449+
1450+ bool eventFiredForFetch = true ;
1451+ bool eventFiredForCommit = true ;
1452+ long currentItemsFetched = 0 ;
1453+ long currentItemsCommited = 0 ;
1454+
1455+ this . context . SynchronizationProgress += ( sender , args ) =>
1456+ {
1457+ sender . Should ( ) . Be ( this . context ) ;
1458+ args . EntityType . Should ( ) . Be < ClientMovie > ( ) ;
1459+ args . QueryId . Should ( ) . Be ( "CommunityToolkit.Datasync.TestCommon.Databases.ClientMovie" ) ;
1460+ args . TotalNrItems . Should ( ) . Be ( 20 ) ;
1461+ switch ( args . EventType )
1462+ {
1463+ case SynchronizationEventType . ItemsFetched :
1464+ currentItemsFetched += 5 ;
1465+ args . ItemsProcessed . Should ( ) . Be ( currentItemsFetched ) ;
1466+ eventFiredForFetch = true ;
1467+ break ;
1468+ case SynchronizationEventType . ItemsCommitted :
1469+ currentItemsCommited += 5 ;
1470+ args . ItemsProcessed . Should ( ) . Be ( currentItemsCommited ) ;
1471+ eventFiredForCommit = true ;
1472+ break ;
1473+ default :
1474+ Assert . Fail ( $ "Invalid event type: { args . EventType } ") ;
1475+ break ;
1476+ }
1477+ } ;
1478+
1479+ await this . context . Movies . PullAsync ( ) ;
1480+
1481+ eventFiredForFetch . Should ( ) . BeTrue ( ) ;
1482+ eventFiredForCommit . Should ( ) . BeTrue ( ) ;
1483+ currentItemsFetched . Should ( ) . Be ( 20 ) ;
1484+ currentItemsCommited . Should ( ) . Be ( 20 ) ;
1485+ }
1486+
1487+ #endregion
1488+
14361489 public class NotOfflineDbContext : DbContext
14371490 {
14381491 public NotOfflineDbContext ( ) : base ( )
0 commit comments