Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: null-handling in Wrap-Method in factories for IDriveInfo or IFileSystemWatcher #977

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public IDriveInfo New(string driveName)
/// <inheritdoc />
public IDriveInfo Wrap(DriveInfo driveInfo)
{
if (driveInfo == null)
{
return null;
}

return New(driveInfo.Name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public IFileSystemWatcher New(string path, string filter)

/// <inheritdoc />
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"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public IDriveInfo New(string driveName)
/// <inheritdoc />
public IDriveInfo Wrap(DriveInfo driveInfo)
{
if (driveInfo == null)
{
return null;
}

return new DriveInfoWrapper(fileSystem, driveInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public IFileSystemWatcher New(string path, string filter)

/// <inheritdoc />
public IFileSystemWatcher Wrap(FileSystemWatcher fileSystemWatcher)
=> new FileSystemWatcherWrapper(FileSystem, fileSystemWatcher);
{
if (fileSystemWatcher == null)
{
return null;
}

return new FileSystemWatcherWrapper(FileSystem, fileSystemWatcher);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,15 @@ public void MockFileSystemWatcherFactory_FromPath_ShouldThrowNotImplementedExcep
var factory = new MockFileSystemWatcherFactory(new MockFileSystem());
Assert.Throws<NotImplementedException>(() => factory.New(path));
}

[Test]
public void MockFileSystemWatcherFactory_Wrap_WithNull_ShouldReturnNull()
{
var fileSystem = new MockFileSystem();

var result = fileSystem.FileSystemWatcher.Wrap(null);

Assert.IsNull(result);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}