public void CopyAll_WhenCalls_CallsCopyDirectoriesAndFiles() { //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" }); _fileSystemMock .Setup(fs => fs.GetFiles(sourcePath, null, SearchOption.AllDirectories)) .Returns(new[] { "/Users/user/Source/Exist/File1.txt" }); _fileSystemMock .Setup(fs => fs.GetDirectoryName(It.IsAny <string>())) .Returns("/Users/user/Source/Exist/"); _fileSystemMock .Setup(fs => fs.CopyFile(It.IsAny <string>(), It.IsAny <string>(), false)) .Verifiable(); //Act creator.CopyAll(sourcePath, destinationPath); //Assert _fileSystemMock.Verify(fs => fs.CreateDirectory(It.IsAny <string>()), Times.Exactly(0)); _fileSystemMock.VerifyAll(); }
public void CopyAll_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.CopyAll(sourcePath, destinationPath); //Assert Assert.Throws <DirectoryNotFoundException>(result); _fileSystemMock.VerifyAll(); }