Ejemplo n.º 1
0
        public async Task TestFilesRemoving()
        {
            var operationsFactoryMock = new Mock <IOperationsFactory>();
            var operationMock         = new Mock <IOperation>();

            operationMock
            .Setup(m => m.RunAsync())
            .Verifiable();
            operationsFactoryMock
            .Setup(m => m.CreateDeleteOperation(It.IsAny <UnaryFileSystemOperationSettings>()))
            .Callback <UnaryFileSystemOperationSettings>(s =>
            {
                Assert.Equal(FileName, s.TopLevelFiles.Single());
            })
            .Returns(operationMock.Object);

            var directoryServiceMock   = new Mock <IDirectoryService>();
            var fileOpeningServiceMock = new Mock <IResourceOpeningService>();
            var fileServiceMock        = new Mock <IFileService>();

            fileServiceMock
            .Setup(m => m.CheckIfExists(FileName))
            .Returns(true)
            .Verifiable();
            var pathServiceMock = new Mock <IPathService>();
            var fileOperationsStateServiceMock = new Mock <IOperationsStateService>();

            fileOperationsStateServiceMock
            .Setup(m => m.AddOperation(operationMock.Object))
            .Verifiable();

            IOperationsService operationsService = new OperationsService(
                operationsFactoryMock.Object,
                directoryServiceMock.Object,
                fileOpeningServiceMock.Object,
                fileServiceMock.Object,
                pathServiceMock.Object,
                fileOperationsStateServiceMock.Object);

            await operationsService.RemoveAsync(new[] { FileName });

            operationMock.Verify(m => m.RunAsync(), Times.Once());
            fileServiceMock.Verify(m => m.CheckIfExists(FileName), Times.Once());
            fileOperationsStateServiceMock
            .Verify(m => m.AddOperation(operationMock.Object), Times.Once());
        }