Skip to content
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
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<ItemGroup>
<PackageVersion Include="AutoFixture.Xunit2" Version="4.18.0" />
<PackageVersion Include="FluentAssertions" Version="6.11.0" />
<PackageVersion Include="Moq" Version="4.20.69" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageVersion Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageVersion Include="xunit" Version="2.5.0" />
Expand All @@ -35,6 +34,7 @@
</ItemGroup>

<ItemGroup>
<PackageVersion Include="Testably.Abstractions" Version="2.3.4" />
<PackageVersion Include="Testably.Abstractions.Testing" Version="2.3.4" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Examples/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
</ItemGroup>

<ItemGroup Condition="'$(UseFileReferenceToTestablyLibraries)' != 'True'">
<PackageReference Include="Testably.Abstractions" />
<PackageReference Include="Testably.Abstractions.Testing" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoFixture.Xunit2" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Moq" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Xunit.SkippableFact" />
<PackageReference Include="xunit" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Testably.Abstractions.FileSystem;
using System.IO.Abstractions;
using Testably.Abstractions.Testing;
using Testably.Abstractions.Testing.FileSystem;

Expand Down
1 change: 0 additions & 1 deletion Tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<ItemGroup>
<PackageReference Include="AutoFixture.Xunit2" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Moq" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Xunit.SkippableFact" />
<PackageReference Include="xunit" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

<ItemGroup>
<PackageReference Remove="AutoFixture.Xunit2" />
<PackageReference Remove="Moq" />
<PackageReference Remove="Microsoft.NET.Test.Sdk" />
<PackageReference Remove="xunit" />
<PackageReference Remove="xunit.runner.visualstudio" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<ItemGroup>
<PackageReference Remove="AutoFixture.Xunit2" />
<PackageReference Remove="FluentAssertions" />
<PackageReference Remove="Moq" />
<PackageReference Remove="Microsoft.NET.Test.Sdk" />
<PackageReference Remove="Xunit.SkippableFact" />
<PackageReference Remove="xunit" />
Expand Down
297 changes: 287 additions & 10 deletions Tests/Testably.Abstractions.Testing.Tests/Helpers/PathHelperTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Moq;
using System.IO;
using System.IO;
using Testably.Abstractions.Testing.Helpers;
using Testably.Abstractions.Testing.Tests.TestHelpers;

Expand Down Expand Up @@ -75,18 +74,12 @@ public void
public void ThrowCommonExceptionsIfPathIsInvalid_WithInvalidCharacters(
char[] invalidChars)
{
Mock<IFileSystem> mockFileSystem = new();
Mock<IPath> pathSystemMock = new();
mockFileSystem.Setup(m => m.Path).Returns(pathSystemMock.Object);
pathSystemMock.Setup(m => m.GetInvalidPathChars()).Returns(invalidChars);
pathSystemMock
.Setup(m => m.GetFullPath(It.IsAny<string>()))
.Returns<string>(s => s);
FileSystemMockForPath mockFileSystem = new(invalidChars);
string path = invalidChars[0] + "foo";

Exception? exception = Record.Exception(() =>
{
path.EnsureValidFormat(mockFileSystem.Object);
path.EnsureValidFormat(mockFileSystem);
});

#if NETFRAMEWORK
Expand All @@ -97,4 +90,288 @@ public void ThrowCommonExceptionsIfPathIsInvalid_WithInvalidCharacters(
.Which.Message.Should().Contain($"'{path}'");
#endif
}

private sealed class FileSystemMockForPath : IFileSystem
{
public FileSystemMockForPath(char[] invalidChars)
{
Path = new PathMockWithInvalidChars(invalidChars);
}

#region IFileSystem Members

/// <inheritdoc />
public IDirectory Directory
=> throw new NotSupportedException();

/// <inheritdoc />
public IDirectoryInfoFactory DirectoryInfo
=> throw new NotSupportedException();

/// <inheritdoc />
public IDriveInfoFactory DriveInfo
=> throw new NotSupportedException();

/// <inheritdoc />
public IFile File
=> throw new NotSupportedException();

/// <inheritdoc />
public IFileInfoFactory FileInfo
=> throw new NotSupportedException();

/// <inheritdoc />
public IFileStreamFactory FileStream
=> throw new NotSupportedException();

/// <inheritdoc />
public IFileSystemWatcherFactory FileSystemWatcher
=> throw new NotSupportedException();

/// <inheritdoc />
public IPath Path { get; }

#endregion

private sealed class PathMockWithInvalidChars : IPath
{
private readonly char[] _invalidChars;

public PathMockWithInvalidChars(char[] invalidChars)
{
_invalidChars = invalidChars;
}

#region IPath Members

/// <inheritdoc />
public char AltDirectorySeparatorChar
=> throw new NotSupportedException();

/// <inheritdoc />
public char DirectorySeparatorChar
=> throw new NotSupportedException();

/// <inheritdoc />
public IFileSystem FileSystem
=> throw new NotSupportedException();

/// <inheritdoc />
public char PathSeparator
=> throw new NotSupportedException();

/// <inheritdoc />
public char VolumeSeparatorChar
=> throw new NotSupportedException();

/// <inheritdoc />
public string ChangeExtension(string? path, string? extension)
=> throw new NotSupportedException();

/// <inheritdoc />
public string Combine(string path1, string path2)
=> throw new NotSupportedException();

/// <inheritdoc />
public string Combine(string path1, string path2, string path3)
=> throw new NotSupportedException();

/// <inheritdoc />
public string Combine(string path1, string path2, string path3, string path4)
=> throw new NotSupportedException();

/// <inheritdoc />
public string Combine(params string[] paths)
=> throw new NotSupportedException();

#if FEATURE_PATH_ADVANCED
/// <inheritdoc />
public bool EndsInDirectorySeparator(ReadOnlySpan<char> path)
=> throw new NotSupportedException();

/// <inheritdoc />
public bool EndsInDirectorySeparator(string path)
=> throw new NotSupportedException();
#endif

/// <inheritdoc />
public bool Exists(string? path)
=> throw new NotSupportedException();

#if FEATURE_SPAN
/// <inheritdoc />
public ReadOnlySpan<char> GetDirectoryName(ReadOnlySpan<char> path)
=> throw new NotSupportedException();
#endif

/// <inheritdoc />
public string GetDirectoryName(string? path)
=> throw new NotSupportedException();

#if FEATURE_SPAN
/// <inheritdoc />
public ReadOnlySpan<char> GetExtension(ReadOnlySpan<char> path)
=> throw new NotSupportedException();
#endif

/// <inheritdoc />
public string GetExtension(string? path)
=> throw new NotSupportedException();

#if FEATURE_SPAN
/// <inheritdoc />
public ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
=> throw new NotSupportedException();
#endif

/// <inheritdoc />
public string GetFileName(string? path)
=> throw new NotSupportedException();

#if FEATURE_SPAN
/// <inheritdoc />
public ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path)
=> throw new NotSupportedException();
#endif

/// <inheritdoc />
public string GetFileNameWithoutExtension(string? path)
=> throw new NotSupportedException();

/// <inheritdoc />
public string GetFullPath(string path)
=> path;

#if FEATURE_PATH_RELATIVE
/// <inheritdoc />
public string GetFullPath(string path, string basePath)
=> throw new NotSupportedException();
#endif

/// <inheritdoc />
public char[] GetInvalidFileNameChars()
=> throw new NotSupportedException();

/// <inheritdoc />
public char[] GetInvalidPathChars()
=> _invalidChars;

#if FEATURE_SPAN
/// <inheritdoc />
public ReadOnlySpan<char> GetPathRoot(ReadOnlySpan<char> path)
=> throw new NotSupportedException();
#endif

/// <inheritdoc />
public string GetPathRoot(string? path)
=> throw new NotSupportedException();

/// <inheritdoc />
public string GetRandomFileName()
=> throw new NotSupportedException();

#if FEATURE_PATH_RELATIVE
/// <inheritdoc />
public string GetRelativePath(string relativeTo, string path)
=> throw new NotSupportedException();
#endif

/// <inheritdoc />
public string GetTempFileName()
=> throw new NotSupportedException();

/// <inheritdoc />
public string GetTempPath()
=> throw new NotSupportedException();

#if FEATURE_SPAN
/// <inheritdoc />
public bool HasExtension(ReadOnlySpan<char> path)
=> throw new NotSupportedException();
#endif

/// <inheritdoc />
public bool HasExtension(string? path)
=> throw new NotSupportedException();

#if FEATURE_PATH_RELATIVE
/// <inheritdoc />
public bool IsPathFullyQualified(ReadOnlySpan<char> path)
=> throw new NotSupportedException();
#endif

/// <inheritdoc />
public bool IsPathFullyQualified(string path)
=> throw new NotSupportedException();

#if FEATURE_SPAN
/// <inheritdoc />
public bool IsPathRooted(ReadOnlySpan<char> path)
=> throw new NotSupportedException();
#endif

/// <inheritdoc />
public bool IsPathRooted(string? path)
=> throw new NotSupportedException();

#if FEATURE_PATH_JOIN
/// <inheritdoc />
public string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2)
=> throw new NotSupportedException();

/// <inheritdoc />
public string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2,
ReadOnlySpan<char> path3)
=> throw new NotSupportedException();
#endif

#if FEATURE_PATH_ADVANCED
/// <inheritdoc />
public string Join(string? path1, string? path2)
=> throw new NotSupportedException();

/// <inheritdoc />
public string Join(string? path1, string? path2, string? path3)
=> throw new NotSupportedException();

/// <inheritdoc />
public string Join(params string?[] paths)
=> throw new NotSupportedException();

/// <inheritdoc />
public string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2,
ReadOnlySpan<char> path3, ReadOnlySpan<char> path4)
=> throw new NotSupportedException();

/// <inheritdoc />
public string Join(string? path1, string? path2, string? path3, string? path4)
=> throw new NotSupportedException();
#endif

#if FEATURE_PATH_ADVANCED
/// <inheritdoc />
public ReadOnlySpan<char> TrimEndingDirectorySeparator(ReadOnlySpan<char> path)
=> throw new NotSupportedException();

/// <inheritdoc />
public string TrimEndingDirectorySeparator(string path)
=> throw new NotSupportedException();
#endif

#if FEATURE_PATH_JOIN
/// <inheritdoc />
public bool TryJoin(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2,
Span<char> destination, out int charsWritten)
=> throw new NotSupportedException();

/// <inheritdoc />
public bool TryJoin(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2,
ReadOnlySpan<char> path3, Span<char> destination,
out int charsWritten)
=> throw new NotSupportedException();
#endif

#endregion
}
}
}
Loading