Repository navigation
Expand file tree
/
Copy pathNetworkPathDetectorTests.cs
More file actions
144 lines (131 loc) · 5.82 KB
/
Copy pathNetworkPathDetectorTests.cs
File metadata and controls
144 lines (131 loc) · 5.82 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System.Runtime.InteropServices;
using FolderDiffIL4DotNet.Core.IO;
using FolderDiffIL4DotNet.Services;
using Xunit;
namespace FolderDiffIL4DotNet.Tests.Core.IO
{
/// <summary>
/// Tests for <see cref="NetworkPathDetector"/> UNC path detection and
/// <see cref="DiffExecutionContext"/> network share optimization flags.
/// <see cref="NetworkPathDetector"/> の UNC パス検出および
/// <see cref="DiffExecutionContext"/> のネットワーク共有最適化フラグのテスト。
/// </summary>
[Trait("Category", "Unit")]
public sealed class NetworkPathDetectorTests
{
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void IsLikelyNetworkPath_NullOrEmpty_ReturnsFalse(string? path)
{
Assert.False(NetworkPathDetector.IsLikelyNetworkPath(path!));
}
[Theory]
[InlineData(@"\\server\share")]
[InlineData(@"\\server\share\subfolder")]
[InlineData(@"\\?\UNC\server\share")]
[InlineData("//server/share")]
public void IsLikelyNetworkPath_UncPaths_ReturnsTrue_OnWindows(string path)
{
// UNC path detection is reliable only on Windows where the OS natively
// supports UNC paths. On Linux/macOS, network detection uses mount point
// analysis instead.
// UNC パス検出は Windows でのみ確実。Linux/macOS ではマウントポイント分析を使用。
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// On non-Windows, UNC-style strings are not recognized as network paths
// because the OS uses /proc/mounts (Linux) or statfs (macOS) instead.
// 非 Windows では UNC 形式文字列はネットワークパスとして認識されない
Assert.False(NetworkPathDetector.IsLikelyNetworkPath(path));
return;
}
Assert.True(NetworkPathDetector.IsLikelyNetworkPath(path));
}
[Theory]
[InlineData(@"C:\Users\Build")]
[InlineData("/home/user/builds")]
[InlineData("/tmp/diff")]
public void IsLikelyNetworkPath_LocalPaths_ReturnsFalse(string path)
{
// Local paths should not be detected as network shares
// ローカルパスはネットワーク共有として検出されないこと
Assert.False(NetworkPathDetector.IsLikelyNetworkPath(path));
}
}
/// <summary>
/// Tests for <see cref="DiffExecutionContext"/> construction and network share flag propagation.
/// <see cref="DiffExecutionContext"/> のコンストラクタおよびネットワーク共有フラグ伝播のテスト。
/// </summary>
[Trait("Category", "Unit")]
public sealed class DiffExecutionContextNetworkTests
{
[Fact]
public void Constructor_SetsNetworkOptimizationFlags()
{
var ctx = new DiffExecutionContext(
oldFolderAbsolutePath: "/old",
newFolderAbsolutePath: "/new",
reportsFolderAbsolutePath: "/reports",
optimizeForNetworkShares: true,
detectedNetworkOld: true,
detectedNetworkNew: false);
Assert.True(ctx.OptimizeForNetworkShares);
Assert.True(ctx.DetectedNetworkOld);
Assert.False(ctx.DetectedNetworkNew);
}
[Fact]
public void Constructor_DefaultOptimizationDisabled()
{
var ctx = new DiffExecutionContext(
oldFolderAbsolutePath: "/old",
newFolderAbsolutePath: "/new",
reportsFolderAbsolutePath: "/reports",
optimizeForNetworkShares: false,
detectedNetworkOld: false,
detectedNetworkNew: false);
Assert.False(ctx.OptimizeForNetworkShares);
Assert.False(ctx.DetectedNetworkOld);
Assert.False(ctx.DetectedNetworkNew);
}
[Fact]
public void Constructor_BothFoldersDetectedAsNetwork()
{
var ctx = new DiffExecutionContext(
oldFolderAbsolutePath: @"\\server\old",
newFolderAbsolutePath: @"\\server\new",
reportsFolderAbsolutePath: "/reports",
optimizeForNetworkShares: true,
detectedNetworkOld: true,
detectedNetworkNew: true);
Assert.True(ctx.DetectedNetworkOld);
Assert.True(ctx.DetectedNetworkNew);
Assert.Equal(@"\\server\old", ctx.OldFolderAbsolutePath);
Assert.Equal(@"\\server\new", ctx.NewFolderAbsolutePath);
}
[Fact]
public void Constructor_NullPaths_ThrowsArgumentNullException()
{
Assert.Throws<System.ArgumentNullException>(() =>
new DiffExecutionContext(null!, "/new", "/reports", false, false, false));
Assert.Throws<System.ArgumentNullException>(() =>
new DiffExecutionContext("/old", null!, "/reports", false, false, false));
Assert.Throws<System.ArgumentNullException>(() =>
new DiffExecutionContext("/old", "/new", null!, false, false, false));
}
[Fact]
public void Constructor_DerivesIlOutputPaths()
{
var ctx = new DiffExecutionContext(
oldFolderAbsolutePath: "/old",
newFolderAbsolutePath: "/new",
reportsFolderAbsolutePath: "/reports",
optimizeForNetworkShares: false,
detectedNetworkOld: false,
detectedNetworkNew: false);
Assert.Contains("IL", ctx.IlOutputFolderAbsolutePath);
Assert.Contains("old", ctx.IlOldFolderAbsolutePath);
Assert.Contains("new", ctx.IlNewFolderAbsolutePath);
}
}
}