Exemple #1
0
        public void CopyDirectories_WhenDestinationNotExists_CreateFolders()
        {
            //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.GetDirectories(sourcePath, null, SearchOption.AllDirectories))
            .Returns(new[] { "/Users/user/Source/NotExist" });
            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.Is <string>(s => s.Contains("NotExist"))))
            .Returns(false);
            _fileSystemMock
            .Setup(fs => fs.CreateDirectory(It.IsAny <string>()))
            .Verifiable();
            //Act
            creator.CopyDirectories(sourcePath, destinationPath);
            //Assert
            _fileSystemMock.Verify(fs => fs.CreateDirectory(It.IsAny <string>()), Times.Exactly(1));
            _fileSystemMock.VerifyAll();
        }
Exemple #2
0
        public void CopyDirectories_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.CopyDirectories(sourcePath, destinationPath);

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

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

            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.IsAny <string>()))
            .Returns(true);
            _fileSystemMock
            .Setup(fs => fs.GetDirectories(sourcePath, null, SearchOption.AllDirectories))
            .Returns(new[] { "/Users/user/Source/Exist" });
            //Act
            creator.CopyDirectories(sourcePath, destinationPath);
            //Assert
            _fileSystemMock.VerifyAll();
        }
Exemple #4
0
        public void CopyDirectories_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.GetDirectories(sourcePath, null, SearchOption.AllDirectories))
            .Returns(Enumerable.Empty <string>);
            //Act
            creator.CopyDirectories(sourcePath, destinationPath);
            //Assert
            _fileSystemMock.Verify(fs => fs.DirectoryExists(It.IsAny <string>()), Times.Exactly(1));
            _fileSystemMock.VerifyAll();
        }