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

Add internal, parameterless ctors for generated proxies #359

Merged
merged 5 commits into from
Oct 8, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 86 additions & 2 deletions System.IO.Abstractions.TestingHelpers.Tests/FileSystemTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#if NET40

using NUnit.Framework;

namespace System.IO.Abstractions.TestingHelpers.Tests
{
[TestFixture]
public class FileSystemTests
{
#if NET40
[Test]
public void Is_Serializable()
{
Expand All @@ -17,6 +18,89 @@ public void Is_Serializable()

Assert.That(memoryStream.Length > 0, "Length didn't increase after serialization task.");
}
#endif

#if NETCOREAPP2_0
[Test]
public void Mock_File_Succeeds()
{
var fileSystemMock = new Moq.Mock<IFileSystem>();

Assert.DoesNotThrow(() =>
fileSystemMock.Setup(x => x.File.ToString()).Returns("")
);
}

[Test]
public void Mock_Directory_Succeeds()
{
var fileSystemMock = new Moq.Mock<IFileSystem>();

Assert.DoesNotThrow(() =>
fileSystemMock.Setup(x => x.Directory.ToString()).Returns("")
);
}

[Test]
public void Mock_FileInfo_Succeeds()
{
var fileSystemMock = new Moq.Mock<IFileSystem>();

Assert.DoesNotThrow(() =>
fileSystemMock.Setup(x => x.FileInfo.ToString()).Returns("")
);
}

[Test]
public void Mock_FileStream_Succeeds()
{
var fileSystemMock = new Moq.Mock<IFileSystem>();

Assert.DoesNotThrow(() =>
fileSystemMock.Setup(x => x.FileStream.ToString()).Returns("")
);
}

[Test]
public void Mock_Path_Succeeds()
{
var fileSystemMock = new Moq.Mock<IFileSystem>();

Assert.DoesNotThrow(() =>
fileSystemMock.Setup(x => x.Path.ToString()).Returns("")
);
}

[Test]
public void Mock_DirectoryInfo_Succeeds()
{
var fileSystemMock = new Moq.Mock<IFileSystem>();

Assert.DoesNotThrow(() =>
fileSystemMock.Setup(x => x.DirectoryInfo.ToString()).Returns("")
);
}

[Test]
public void Mock_DriveInfo_Succeeds()
{
var fileSystemMock = new Moq.Mock<IFileSystem>();

Assert.DoesNotThrow(() =>
fileSystemMock.Setup(x => x.DirectoryInfo.ToString()).Returns("")
);
}

[Test]
public void Mock_FileSystemWatcher_Succeeds()
{
var fileSystemMock = new Moq.Mock<IFileSystem>();

Assert.DoesNotThrow(() =>
fileSystemMock.Setup(x => x.FileSystemWatcher.ToString()).Returns("")
);
}
#endif

}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

<ItemGroup Condition="'$(TargetFramework)' != 'net40'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="Moq" Version="4.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions System.IO.Abstractions/DirectoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ protected DirectoryBase(IFileSystem fileSystem)
FileSystem = fileSystem;
}

[Obsolete("This constructor only exists to support mocking libraries.", error: true)]
internal DirectoryBase() { }

/// <summary>
/// Exposes the underlying filesystem implementation. This is useful for implementing extension methods.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions System.IO.Abstractions/DirectoryInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ protected DirectoryInfoBase(IFileSystem fileSystem) : base(fileSystem)
{
}

[Obsolete("This constructor only exists to support mocking libraries.", error: true)]
internal DirectoryInfoBase() { }

/// <inheritdoc cref="DirectoryInfo.Create()"/>
public abstract void Create();
#if NET40
Expand Down
3 changes: 3 additions & 0 deletions System.IO.Abstractions/DriveInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ protected DriveInfoBase(IFileSystem fileSystem)
FileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
}

[Obsolete("This constructor only exists to support mocking libraries.", error: true)]
internal DriveInfoBase() { }

/// <summary>
/// Exposes the underlying filesystem implementation. This is useful for implementing extension methods.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions System.IO.Abstractions/FileBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ protected FileBase(IFileSystem fileSystem)
FileSystem = fileSystem;
}

[Obsolete("This constructor only exists to support mocking libraries.", error: true)]
internal FileBase() { }

/// <summary>
/// Exposes the underlying filesystem implementation. This is useful for implementing extension methods.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions System.IO.Abstractions/FileInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ protected FileInfoBase(IFileSystem fileSystem) : base(fileSystem)
{
}

[Obsolete("This constructor only exists to support mocking libraries.", error: true)]
internal FileInfoBase() { }

/// <inheritdoc cref="FileInfo.AppendText"/>
public abstract StreamWriter AppendText();

Expand Down
3 changes: 3 additions & 0 deletions System.IO.Abstractions/FileSystemInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ protected FileSystemInfoBase(IFileSystem fileSystem)
FileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
}

[Obsolete("This constructor only exists to support mocking libraries.", error: true)]
internal FileSystemInfoBase() { }

/// <summary>
/// Exposes the underlying filesystem implementation. This is useful for implementing extension methods.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions System.IO.Abstractions/PathBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ protected PathBase(IFileSystem fileSystem)
this.FileSystem = fileSystem;
}

[Obsolete("This constructor only exists to support mocking libraries.", error: true)]
internal PathBase() { }

/// <summary>
/// Exposes the underlying filesystem implementation. This is useful for implementing extension methods.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions System.IO.Abstractions/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#if DEBUG
[assembly: InternalsVisibleTo("System.IO.Abstractions.TestingHelpers.Tests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
#else
[assembly: InternalsVisibleTo("System.IO.Abstractions.TestingHelpers.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001160c7a0f907c400c5392975b66d2f3752fb82625d5674d386b83896d4d4ae8d0ef8319ef391fbb3466de0058ad2f361b8f5cb8a32ecb4e908bece5c519387552cedd2ca0250e36b59c6d6dc3dc260ca73a7e27c3add4ae22d5abaa562225d7ba34d427e8f3f52928a46a674deb0208eca7d379aa22712355b91a55a5ce521d2")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
#endif