public async Task WhenWriteSourceToImgDestinationThenReadDataIsIdentical()
        {
            // arrange
            var sourcePath              = $"{Guid.NewGuid()}.img";
            var destinationPath         = $"{Guid.NewGuid()}.img";
            var fakeCommandHelper       = new FakeCommandHelper(new[] { sourcePath }, new [] { destinationPath });
            var cancellationTokenSource = new CancellationTokenSource();

            // act - write source img to destination img
            var writeCommand =
                new WriteCommand(new NullLogger <WriteCommand>(), fakeCommandHelper, new List <IPhysicalDrive>(), sourcePath, destinationPath);
            DataProcessedEventArgs dataProcessedEventArgs = null;

            writeCommand.DataProcessed += (_, args) =>
            {
                dataProcessedEventArgs = args;
            };
            var result = await writeCommand.Execute(cancellationTokenSource.Token);

            Assert.True(result.IsSuccess);

            Assert.NotNull(dataProcessedEventArgs);
            Assert.NotEqual(0, dataProcessedEventArgs.PercentComplete);
            Assert.NotEqual(0, dataProcessedEventArgs.BytesProcessed);
            Assert.Equal(0, dataProcessedEventArgs.BytesRemaining);
            Assert.NotEqual(0, dataProcessedEventArgs.BytesTotal);

            // assert data is identical
            var sourceBytes      = fakeCommandHelper.GetMedia(sourcePath).GetBytes();
            var destinationBytes = fakeCommandHelper.GetMedia(destinationPath).GetBytes();

            Assert.Equal(sourceBytes, destinationBytes);
        }
Пример #2
0
 public static void Present(DataProcessedEventArgs args)
 {
     Console.WriteLine(
         $"{args.PercentComplete:F1}% ({args.BytesProcessed} / {args.BytesTotal} bytes)");
 }