77using FakeItEasy ;
88using FluentAssertions ;
99using Microsoft . Extensions . Logging ;
10+ using ByteSync . Common . Business . Synchronizations ;
1011
1112namespace ByteSync . ServerCommon . Tests . Commands . Synchronizations ;
1213
@@ -122,4 +123,49 @@ public async Task Handle_WhenRepositoryThrowsException_PropagatesException()
122123
123124 exception . Which . Should ( ) . Be ( expectedException ) ;
124125 }
125- }
126+
127+ [ Test ]
128+ public async Task Handle_UsesMetricsForLocalCopyTransferredVolume_WhenProvided ( )
129+ {
130+ // Arrange
131+ var sessionId = "session-metrics" ;
132+ var client = new Client { ClientInstanceId = "clientX" } ;
133+ var actionId = "group-metrics" ;
134+ var actionsGroupIds = new List < string > { actionId } ;
135+
136+ var transferredBytes = 1_234L ;
137+ var fileSize = 5_000L ;
138+
139+ var request = new LocalCopyIsDoneRequest ( sessionId , client , actionsGroupIds , "node-1" ,
140+ new Dictionary < string , SynchronizationActionMetrics >
141+ {
142+ [ actionId ] = new SynchronizationActionMetrics { TransferredBytes = transferredBytes }
143+ } ) ;
144+
145+ A . CallTo ( ( ) => _mockSynchronizationStatusCheckerService . CheckSynchronizationCanBeUpdated ( A < SynchronizationEntity > . _ ) )
146+ . Returns ( true ) ;
147+
148+ var trackingAction = new TrackingActionEntity
149+ {
150+ ActionsGroupId = actionId ,
151+ TargetClientInstanceAndNodeIds =
152+ [ new ( ) { ClientInstanceId = client . ClientInstanceId , NodeId = request . NodeId ! } ] ,
153+ Size = fileSize
154+ } ;
155+ var synchronization = new SynchronizationEntity { Progress = new SynchronizationProgressEntity ( ) } ;
156+
157+ A . CallTo ( ( ) => _mockTrackingActionRepository . AddOrUpdate ( sessionId , actionsGroupIds , A < Func < TrackingActionEntity , SynchronizationEntity , bool > > . _ ) )
158+ . Invokes ( ( string _ , List < string > _ , Func < TrackingActionEntity , SynchronizationEntity , bool > func ) =>
159+ {
160+ func ( trackingAction , synchronization ) ;
161+ } )
162+ . Returns ( new TrackingActionResult ( true , [ trackingAction ] , synchronization ) ) ;
163+
164+ // Act
165+ await _localCopyIsDoneCommandHandler . Handle ( request , CancellationToken . None ) ;
166+
167+ // Assert
168+ synchronization . Progress . LocalCopyTransferredVolume . Should ( ) . Be ( transferredBytes ) ;
169+ synchronization . Progress . SynchronizedVolume . Should ( ) . Be ( fileSize ) ;
170+ }
171+ }
0 commit comments