public async Task TestMoveOperation() { var directoryServiceMock = new Mock <IDirectoryService>(); var filesServiceMock = new Mock <IFileService>(); filesServiceMock .Setup(m => m.CopyAsync(SourceFile, DestinationFile)) .Verifiable(); filesServiceMock .Setup(m => m.Remove(SourceFile)) .Verifiable(); var operationsFactory = new OperationsFactory( _taskPool, directoryServiceMock.Object, filesServiceMock.Object, _pathService); var moveOperation = operationsFactory.CreateMoveOperation( new[] { new BinaryFileOperationSettings(SourceFile, DestinationFile) }); var callbackCalled = false; moveOperation.OperationFinished += (sender, args) => callbackCalled = true; await moveOperation.RunAsync(); Assert.True(callbackCalled); filesServiceMock.Verify(m => m.CopyAsync(SourceFile, DestinationFile), Times.Once()); filesServiceMock.Verify(m => m.Remove(SourceFile), Times.Once()); }
public async Task TestMoveOperation(bool copyThrows, bool deleteThrows, OperationState state) { var directoryServiceMock = new Mock <IDirectoryService>(); var filesServiceMock = new Mock <IFileService>(); var copySetup = filesServiceMock .Setup(m => m.CopyAsync(SourceName, DestinationName, false)); if (copyThrows) { copySetup.ThrowsAsync(new AccessViolationException()).Verifiable(); } else { copySetup.Verifiable(); } var deleteSetup = filesServiceMock .Setup(m => m.Remove(SourceName)); if (deleteThrows) { deleteSetup.Throws(new AccessViolationException()).Verifiable(); } else { deleteSetup.Verifiable(); } var operationsFactory = new OperationsFactory( _taskPool, directoryServiceMock.Object, filesServiceMock.Object, _pathService, _fileNameGenerationService); var settings = new BinaryFileSystemOperationSettings( new string[] { }, new[] { SourceName }, new string[] { }, new[] { SourceName }, new Dictionary <string, string> { [SourceName] = DestinationName }, new string[] { } ); var moveOperation = operationsFactory.CreateMoveOperation(settings); Assert.Equal(OperationState.NotStarted, moveOperation.State); var callbackCalled = false; moveOperation.StateChanged += (sender, args) => callbackCalled = true; await moveOperation.RunAsync(); Assert.Equal(state, moveOperation.State); Assert.True(callbackCalled); filesServiceMock.Verify(m => m.CopyAsync(SourceName, DestinationName, false), Times.Once()); filesServiceMock.Verify(m => m.Remove(SourceName), copyThrows ? Times.Never() : Times.Once()); }
public async Task TestMoveOperation() { var directoryServiceMock = new Mock <IDirectoryService>(); var filesServiceMock = new Mock <IFileService>(); filesServiceMock .Setup(m => m.CopyAsync(SourceName, DestinationName, false)) .Verifiable(); filesServiceMock .Setup(m => m.Remove(SourceName)) .Verifiable(); var operationsFactory = new OperationsFactory( _taskPool, directoryServiceMock.Object, filesServiceMock.Object, _pathService, _fileNameGenerationService); var settings = new BinaryFileSystemOperationSettings( new string[] { }, new[] { SourceName }, new string[] { }, new[] { SourceName }, new Dictionary <string, string> { [SourceName] = DestinationName } ); var moveOperation = operationsFactory.CreateMoveOperation(settings); Assert.Equal(OperationState.NotStarted, moveOperation.State); var callbackCalled = false; moveOperation.StateChanged += (sender, args) => callbackCalled = true; await moveOperation.RunAsync(); Assert.Equal(OperationState.Finished, moveOperation.State); Assert.True(callbackCalled); filesServiceMock.Verify(m => m.CopyAsync(SourceName, DestinationName, false), Times.Once()); filesServiceMock.Verify(m => m.Remove(SourceName), Times.Once()); }