forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolicLinks.cs
More file actions
70 lines (58 loc) · 2.42 KB
/
Copy pathSymbolicLinks.cs
File metadata and controls
70 lines (58 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;
namespace System.IO.Tests
{
public class File_SymbolicLinks : BaseSymbolicLinks_FileSystem
{
protected override bool IsDirectoryTest => false;
protected override void CreateFileOrDirectory(string path, bool createOpposite = false)
{
if (!createOpposite)
{
File.Create(path).Dispose();
}
else
{
Directory.CreateDirectory(path);
}
}
protected override FileSystemInfo CreateSymbolicLink(string path, string pathToTarget) =>
File.CreateSymbolicLink(path, pathToTarget);
protected override FileSystemInfo ResolveLinkTarget(string linkPath, bool returnFinalTarget) =>
File.ResolveLinkTarget(linkPath, returnFinalTarget);
protected override void AssertIsCorrectTypeAndDirectoryAttribute(FileSystemInfo linkInfo)
{
if (linkInfo.Exists)
{
Assert.False(linkInfo.Attributes.HasFlag(FileAttributes.Directory));
}
Assert.True(linkInfo is FileInfo);
}
protected override void AssertLinkExists(FileSystemInfo link) =>
Assert.True(link.Exists);
[Fact]
public void ResolveLinkTarget_Throws_NotExists() =>
ResolveLinkTarget_Throws_NotExists_Internal<FileNotFoundException>();
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public void UnsupportedLink_ReturnsNull()
{
string unsupportedLinkPath = GetAppExecLinkPath();
if (unsupportedLinkPath is null)
{
return;
}
Assert.Null(File.ResolveLinkTarget(unsupportedLinkPath, false));
Assert.Null(File.ResolveLinkTarget(unsupportedLinkPath, true));
}
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void CreateSymbolicLink_PathToTarget_RelativeToLinkPath()
{
RemoteExecutor.Invoke(() => CreateSymbolicLink_PathToTarget_RelativeToLinkPath_Internal(false)).Dispose();
RemoteExecutor.Invoke(() => CreateSymbolicLink_PathToTarget_RelativeToLinkPath_Internal(true)).Dispose();
}
}
}