diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs index d9b31436f..b0a1d6046 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs @@ -56,6 +56,11 @@ public IDriveInfo New(string driveName) /// public IDriveInfo Wrap(DriveInfo driveInfo) { + if (driveInfo == null) + { + return null; + } + return New(driveInfo.Name); } diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs index 86ad883f3..9a65d4b04 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs @@ -43,6 +43,13 @@ public IFileSystemWatcher New(string path, string filter) /// public IFileSystemWatcher Wrap(FileSystemWatcher fileSystemWatcher) - => throw new NotImplementedException(StringResources.Manager.GetString("FILE_SYSTEM_WATCHER_NOT_IMPLEMENTED_EXCEPTION")); + { + if (fileSystemWatcher == null) + { + return null; + } + + throw new NotImplementedException(StringResources.Manager.GetString("FILE_SYSTEM_WATCHER_NOT_IMPLEMENTED_EXCEPTION")); + } } } diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs index 3f8cf7478..f08453bd9 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs @@ -38,6 +38,11 @@ public IDriveInfo New(string driveName) /// public IDriveInfo Wrap(DriveInfo driveInfo) { + if (driveInfo == null) + { + return null; + } + return new DriveInfoWrapper(fileSystem, driveInfo); } diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs index 347c1c43b..2b62e5dbd 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs @@ -42,6 +42,13 @@ public IFileSystemWatcher New(string path, string filter) /// public IFileSystemWatcher Wrap(FileSystemWatcher fileSystemWatcher) - => new FileSystemWatcherWrapper(FileSystem, fileSystemWatcher); + { + if (fileSystemWatcher == null) + { + return null; + } + + return new FileSystemWatcherWrapper(FileSystem, fileSystemWatcher); + } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoFactoryTests.cs index cc73f4733..0035ac96e 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoFactoryTests.cs @@ -97,5 +97,15 @@ public void MockDriveInfoFactory_New_WithPathShouldReturnDrive() // Assert Assert.That(actualResult.Name, Is.EquivalentTo(@"Z:\")); } + + [Test] + public void MockDriveInfoFactory_Wrap_WithNull_ShouldReturnNull() + { + var fileSystem = new MockFileSystem(); + + var result = fileSystem.DriveInfo.Wrap(null); + + Assert.IsNull(result); + } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemWatcherFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemWatcherFactoryTests.cs index 6f10dcdc4..8def87d9e 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemWatcherFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemWatcherFactoryTests.cs @@ -37,5 +37,15 @@ public void MockFileSystemWatcherFactory_FromPath_ShouldThrowNotImplementedExcep var factory = new MockFileSystemWatcherFactory(new MockFileSystem()); Assert.Throws(() => factory.New(path)); } + + [Test] + public void MockFileSystemWatcherFactory_Wrap_WithNull_ShouldReturnNull() + { + var fileSystem = new MockFileSystem(); + + var result = fileSystem.FileSystemWatcher.Wrap(null); + + Assert.IsNull(result); + } } } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DriveInfoFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DriveInfoFactoryTests.cs new file mode 100644 index 000000000..cfa892845 --- /dev/null +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DriveInfoFactoryTests.cs @@ -0,0 +1,18 @@ +using NUnit.Framework; + +namespace System.IO.Abstractions.Tests +{ + [TestFixture] + public class DriveInfoFactoryTests + { + [Test] + public void Wrap_WithNull_ShouldReturnNull() + { + var fileSystem = new FileSystem(); + + var result = fileSystem.DriveInfo.Wrap(null); + + Assert.IsNull(result); + } + } +} diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemWatcherFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemWatcherFactoryTests.cs new file mode 100644 index 000000000..a63d4b9a3 --- /dev/null +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemWatcherFactoryTests.cs @@ -0,0 +1,18 @@ +using NUnit.Framework; + +namespace System.IO.Abstractions.Tests +{ + [TestFixture] + public class FileSystemWatcherFactoryTests + { + [Test] + public void Wrap_WithNull_ShouldReturnNull() + { + var fileSystem = new FileSystem(); + + var result = fileSystem.FileSystemWatcher.Wrap(null); + + Assert.IsNull(result); + } + } +}