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

feat: Add LinkTarget to FileSystemInfo for .NET 6 targets #790

Merged
Merged
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<DefineConstants Condition="'$(TargetFramework)' != 'net461'">$(DefineConstants);FEATURE_FILE_SYSTEM_ACL_EXTENSIONS</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net5.0' OR '$(TargetFramework)' == 'netcoreapp3.1' OR '$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS;FEATURE_ADVANCED_PATH_OPERATIONS;FEATURE_PATH_JOIN_WITH_SPAN</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net5.0'">$(DefineConstants);FEATURE_FILE_MOVE_WITH_OVERWRITE;FEATURE_SUPPORTED_OS_ATTRIBUTE;FEATURE_FILE_SYSTEM_WATCHER_FILTERS;FEATURE_ENDS_IN_DIRECTORY_SEPARATOR;FEATURE_PATH_JOIN_WITH_PARAMS;FEATURE_PATH_JOIN_WITH_FOUR_PATHS</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0'">$(DefineConstants);FEATURE_FILE_SYSTEM_INFO_LINK_TARGET</DefineConstants>
BrianMcBrayer marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.255">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ public override DateTime LastWriteTimeUtc
set { GetMockFileDataForWrite().LastWriteTime = value.ToLocalTime(); }
}

#if FEATURE_FILE_SYSTEM_INFO_LINK_TARGET
/// <inheritdoc />
public override string LinkTarget
{
get { return GetMockFileDataForRead().LinkTarget; }
}
#endif

/// <inheritdoc />
public override string Name
BrianMcBrayer marked this conversation as resolved.
Show resolved Hide resolved
{
get
Expand Down
10 changes: 10 additions & 0 deletions src/System.IO.Abstractions.TestingHelpers/MockFileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public MockFileData(MockFileData template)
CreationTime = template.CreationTime;
LastAccessTime = template.LastAccessTime;
LastWriteTime = template.LastWriteTime;
#if FEATURE_FILE_SYSTEM_INFO_LINK_TARGET
LinkTarget = template.LinkTarget;
#endif
}

/// <summary>
Expand Down Expand Up @@ -135,6 +138,13 @@ public string TextContents
/// </summary>
public DateTimeOffset LastWriteTime { get; set; } = new DateTimeOffset(2010, 01, 04, 00, 00, 00, TimeSpan.FromHours(4));

#if FEATURE_FILE_SYSTEM_INFO_LINK_TARGET
/// <summary>
/// Gets or sets the link target of the <see cref="MockFileData"/>.
/// </summary>
public string LinkTarget { get; set; } = null;
BrianMcBrayer marked this conversation as resolved.
Show resolved Hide resolved
#endif

/// <summary>
/// Casts a string into <see cref="MockFileData"/>.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions src/System.IO.Abstractions.TestingHelpers/MockFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ public override DateTime LastWriteTimeUtc
}
}

#if FEATURE_FILE_SYSTEM_INFO_LINK_TARGET
/// <inheritdoc />
public override string LinkTarget
{
get
{
var mockFileData = GetMockFileDataForWrite();
BrianMcBrayer marked this conversation as resolved.
Show resolved Hide resolved
return mockFileData.LinkTarget;
}
}
#endif

/// <inheritdoc />
public override string Name
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<AssemblyName>System.IO.Abstractions.TestingHelpers</AssemblyName>
<RootNamespace>System.IO.Abstractions.TestingHelpers</RootNamespace>
<Description>A set of pre-built mocks to help when testing file system interactions.</Description>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
BrianMcBrayer marked this conversation as resolved.
Show resolved Hide resolved
<PackageIcon>icon_256x256.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
Expand All @@ -16,6 +16,6 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Include="..\..\images\icon_256x256.png" Pack="true" PackagePath="\"/>
<None Include="..\..\images\icon_256x256.png" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions src/System.IO.Abstractions/DirectoryInfoWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ public override DateTime LastWriteTimeUtc
set { instance.LastWriteTimeUtc = value; }
}

#if FEATURE_FILE_SYSTEM_INFO_LINK_TARGET
/// <inheritdoc />
public override string LinkTarget
{
get { return instance.LinkTarget; }
}
#endif

/// <inheritdoc />
public override string Name
{
Expand Down
8 changes: 8 additions & 0 deletions src/System.IO.Abstractions/FileInfoWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public override DateTime LastWriteTimeUtc
set { instance.LastWriteTimeUtc = value; }
}

#if FEATURE_FILE_SYSTEM_INFO_LINK_TARGET
/// <inheritdoc />
public override string LinkTarget
{
get { return instance.LinkTarget; }
}
#endif

/// <inheritdoc />
public override string Name
{
Expand Down
5 changes: 5 additions & 0 deletions src/System.IO.Abstractions/FileSystemInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ internal FileSystemInfoBase() { }
/// <inheritdoc cref="FileSystemInfo.LastWriteTimeUtc"/>
public abstract DateTime LastWriteTimeUtc { get; set; }

#if FEATURE_FILE_SYSTEM_INFO_LINK_TARGET
/// <inheritdoc cref="FileSystemInfo.LinkTarget"/>
public abstract string LinkTarget { get; }
#endif

/// <inheritdoc cref="FileSystemInfo.Name"/>
public abstract string Name { get; }
}
Expand Down
6 changes: 3 additions & 3 deletions src/System.IO.Abstractions/System.IO.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<AssemblyName>System.IO.Abstractions</AssemblyName>
<RootNamespace>System.IO.Abstractions</RootNamespace>
<Description>A set of abstractions to help make file system interactions testable.</Description>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<PackageIcon>icon_256x256.png</PackageIcon>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.7.0"/>
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.7.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="5.0.0"/>
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net461" Version="1.0.2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private static IEnumerable<Action<IDirectory>> GetFileSystemActionsForArgumentNu
yield return ds => ds.EnumerateDirectories(null, "foo", SearchOption.AllDirectories);
}

[TestCaseSource("GetFileSystemActionsForArgumentNullException")]
[TestCaseSource(nameof(GetFileSystemActionsForArgumentNullException))]
BrianMcBrayer marked this conversation as resolved.
Show resolved Hide resolved
public void Operations_ShouldThrowArgumentNullExceptionIfPathIsNull(Action<IDirectory> action)
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
"System.IO.Abstractions.IFileSystemInfo ResolveLinkTarget(Boolean)",
"System.Object GetLifetimeService()",
"System.Object InitializeLifetimeService()",
"System.String LinkTarget",
"System.String get_LinkTarget()",
"Void .ctor(System.String)",
"Void CreateAsSymbolicLink(System.String)",
"Void GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
"System.IO.Abstractions.IFileSystemInfo ResolveLinkTarget(Boolean)",
"System.Object GetLifetimeService()",
"System.Object InitializeLifetimeService()",
"System.String LinkTarget",
"System.String get_LinkTarget()",
"Void .ctor(System.String)",
"Void CreateAsSymbolicLink(System.String)",
"Void GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)"
Expand Down