Exemple #1
0
        public void CopyFiles_WhenDestinationFolderNotExists_CreateFoldersAndCopyFiles()
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);

            var sourcePath      = Path.Combine(_userFolder, "Source");
            var destinationPath = Path.Combine(_userFolder, "Destination");

            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.Is <string>(s => s == sourcePath)))
            .Returns(true);
            _fileSystemMock
            .Setup(fs => fs.GetFiles(sourcePath, null, SearchOption.AllDirectories))
            .Returns(new[] { "/Users/user/Source/NotExist/File1.txt" });
            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.Is <string>(s => s.Contains("NotExist"))))
            .Returns(false);
            _fileSystemMock
            .Setup(fs => fs.GetDirectoryName(It.Is <string>(s => s.Contains("NotExist"))))
            .Returns("/Users/user/Destination/NotExist/");
            _fileSystemMock.Setup(fs => fs.CreateDirectory(It.IsAny <string>())).Verifiable();
            _fileSystemMock.Setup(fs => fs.CopyFile(It.IsAny <string>(), It.IsAny <string>(), false)).Verifiable();
            //Act
            creator.CopyFiles(sourcePath, destinationPath);
            //Assert
            _fileSystemMock.Verify(fs => fs.CreateDirectory(It.IsAny <string>()), Times.Exactly(1));
            _fileSystemMock.VerifyAll();
        }
Exemple #2
0
        public void CopyFiles_WhenPathNotFound_ReturnsException()
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);

            string sourcePath      = Path.Combine(_userFolder, "NotExist");
            string destinationPath = Path.Combine(_userFolder, "NotMatters");

            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.Is <string>(s => s == sourcePath)))
            .Returns(false);

            //Act
            Action result = () => creator.CopyFiles(sourcePath, destinationPath);

            //Assert
            Assert.Throws <DirectoryNotFoundException>(result);
            _fileSystemMock.VerifyAll();
        }
Exemple #3
0
        public void CopyFiles_WhenSourceIsEmpty_CopyAnything()
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);

            var sourcePath      = Path.Combine(_userFolder, "Source");
            var destinationPath = Path.Combine(_userFolder, "Destination");

            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.Is <string>(s => s == sourcePath)))
            .Returns(true);
            _fileSystemMock
            .Setup(fs => fs.GetFiles(sourcePath, null, SearchOption.AllDirectories))
            .Returns(Enumerable.Empty <string>);
            //Act
            creator.CopyFiles(sourcePath, destinationPath);
            //Assert
            _fileSystemMock.Verify(fs => fs.DirectoryExists(It.IsAny <string>()), Times.Exactly(1));
            _fileSystemMock.VerifyAll();
        }