Repository navigation
Expand file tree
/
Copy pathFileDiffResultListsTests.cs
More file actions
336 lines (281 loc) · 14.1 KB
/
Copy pathFileDiffResultListsTests.cs
File metadata and controls
336 lines (281 loc) · 14.1 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
using System;
using System.Linq;
using System.Threading.Tasks;
using FolderDiffIL4DotNet.Models;
using Xunit;
namespace FolderDiffIL4DotNet.Tests.Models
{
[Collection("FileDiffResultLists")]
public partial class FileDiffResultListsTests : IDisposable
{
private readonly FileDiffResultLists _sut = new();
public FileDiffResultListsTests()
{
ClearAll();
}
public void Dispose()
{
ClearAll();
}
private void ClearAll()
{
_sut.ResetAll();
}
[Fact]
public void RecordDiffDetail_NewEntry_Stored()
{
_sut.RecordDiffDetail("file.cs", FileDiffResultLists.DiffDetailResult.SHA256Match);
Assert.True(_sut.FileRelativePathToDiffDetailDictionary.ContainsKey("file.cs"));
Assert.Equal(FileDiffResultLists.DiffDetailResult.SHA256Match, _sut.FileRelativePathToDiffDetailDictionary["file.cs"]);
}
[Fact]
public void RecordDiffDetail_Overwrite_UpdatesValue()
{
_sut.RecordDiffDetail("file.cs", FileDiffResultLists.DiffDetailResult.SHA256Match);
_sut.RecordDiffDetail("file.cs", FileDiffResultLists.DiffDetailResult.ILMismatch);
Assert.Equal(FileDiffResultLists.DiffDetailResult.ILMismatch, _sut.FileRelativePathToDiffDetailDictionary["file.cs"]);
}
[Fact]
public void RecordDiffDetail_MultipleEntries_AllStored()
{
_sut.RecordDiffDetail("a.cs", FileDiffResultLists.DiffDetailResult.SHA256Match);
_sut.RecordDiffDetail("b.dll", FileDiffResultLists.DiffDetailResult.ILMatch);
_sut.RecordDiffDetail("c.txt", FileDiffResultLists.DiffDetailResult.TextMismatch);
Assert.Equal(3, _sut.FileRelativePathToDiffDetailDictionary.Count);
}
[Fact]
public void RecordDiffDetail_IlResult_WithDisassemblerLabel_Stored()
{
_sut.RecordDiffDetail("a.dll", FileDiffResultLists.DiffDetailResult.ILMismatch, "dotnet-ildasm (version: 0.12.0)");
Assert.True(_sut.FileRelativePathToIlDisassemblerLabelDictionary.ContainsKey("a.dll"));
Assert.Equal("dotnet-ildasm (version: 0.12.0)", _sut.FileRelativePathToIlDisassemblerLabelDictionary["a.dll"]);
}
[Fact]
public void RecordDiffDetail_NonIlResult_ClearsExistingDisassemblerLabel()
{
_sut.RecordDiffDetail("a.dll", FileDiffResultLists.DiffDetailResult.ILMatch, "dotnet-ildasm (version: 0.12.0)");
_sut.RecordDiffDetail("a.dll", FileDiffResultLists.DiffDetailResult.SHA256Match);
Assert.False(_sut.FileRelativePathToIlDisassemblerLabelDictionary.ContainsKey("a.dll"));
}
[Fact]
public void HasAnySha256Mismatch_Empty_ReturnsFalse()
{
Assert.False(_sut.HasAnySha256Mismatch);
}
[Fact]
public void HasAnySha256Mismatch_OnlyMatches_ReturnsFalse()
{
_sut.RecordDiffDetail("a.dll", FileDiffResultLists.DiffDetailResult.SHA256Match);
_sut.RecordDiffDetail("b.dll", FileDiffResultLists.DiffDetailResult.ILMatch);
Assert.False(_sut.HasAnySha256Mismatch);
}
[Fact]
public void HasAnySha256Mismatch_WithMismatch_ReturnsTrue()
{
_sut.RecordDiffDetail("a.dll", FileDiffResultLists.DiffDetailResult.SHA256Match);
_sut.RecordDiffDetail("b.dll", FileDiffResultLists.DiffDetailResult.SHA256Mismatch);
Assert.True(_sut.HasAnySha256Mismatch);
}
[Fact]
public void RecordIgnoredFile_OldOnly_StoresOldFlag()
{
_sut.RecordIgnoredFile("test.pdb", FileDiffResultLists.IgnoredFileLocation.Old);
Assert.True(_sut.IgnoredFilesRelativePathToLocation.ContainsKey("test.pdb"));
Assert.Equal(FileDiffResultLists.IgnoredFileLocation.Old, _sut.IgnoredFilesRelativePathToLocation["test.pdb"]);
}
[Fact]
public void RecordIgnoredFile_BothOldAndNew_FlagsCombined()
{
_sut.RecordIgnoredFile("test.pdb", FileDiffResultLists.IgnoredFileLocation.Old);
_sut.RecordIgnoredFile("test.pdb", FileDiffResultLists.IgnoredFileLocation.New);
var flags = _sut.IgnoredFilesRelativePathToLocation["test.pdb"];
Assert.True(flags.HasFlag(FileDiffResultLists.IgnoredFileLocation.Old));
Assert.True(flags.HasFlag(FileDiffResultLists.IgnoredFileLocation.New));
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void RecordIgnoredFile_NullOrWhitespace_ThrowsArgumentException(string path)
{
Assert.Throws<ArgumentException>(() =>
_sut.RecordIgnoredFile(path, FileDiffResultLists.IgnoredFileLocation.Old));
}
[Fact]
public void RecordIgnoredFile_CaseInsensitiveKey()
{
_sut.RecordIgnoredFile("Test.PDB", FileDiffResultLists.IgnoredFileLocation.Old);
_sut.RecordIgnoredFile("test.pdb", FileDiffResultLists.IgnoredFileLocation.New);
Assert.Equal(2, _sut.IgnoredFilesRelativePathToLocation.Count);
}
[Fact]
public void RecordDisassemblerToolVersion_Normal_Recorded()
{
_sut.RecordDisassemblerToolVersion("dotnet-ildasm", "1.0.0");
Assert.True(_sut.DisassemblerToolVersions.ContainsKey("dotnet-ildasm (version: 1.0.0)"));
}
[Fact]
public void RecordDisassemblerToolVersion_FromCache_RecordedInCacheDictionary()
{
_sut.RecordDisassemblerToolVersion("dotnet-ildasm", "1.0.0", fromCache: true);
Assert.Empty(_sut.DisassemblerToolVersions);
Assert.True(_sut.DisassemblerToolVersionsFromCache.ContainsKey("dotnet-ildasm (version: 1.0.0)"));
}
[Fact]
public void RecordDisassemblerToolVersion_NullOrWhitespace_Ignored()
{
_sut.RecordDisassemblerToolVersion(null, "1.0.0");
_sut.RecordDisassemblerToolVersion("", "1.0.0");
_sut.RecordDisassemblerToolVersion(" ", "1.0.0");
Assert.Empty(_sut.DisassemblerToolVersions);
}
[Fact]
public void RecordDisassemblerToolVersion_NoVersion_UsesToolNameOnly()
{
_sut.RecordDisassemblerToolVersion("ildasm", null);
Assert.True(_sut.DisassemblerToolVersions.ContainsKey("ildasm"));
}
[Fact]
public void RecordNewFileTimestampOlderThanOldWarning_NewEntry_Stored()
{
_sut.RecordNewFileTimestampOlderThanOldWarning("nested/file.txt", "2026-03-14 10:00:00", "2026-03-14 09:00:00");
Assert.True(_sut.HasAnyNewFileTimestampOlderThanOldWarning);
Assert.True(_sut.NewFileTimestampOlderThanOldWarnings.ContainsKey("nested/file.txt"));
Assert.Equal("2026-03-14 10:00:00", _sut.NewFileTimestampOlderThanOldWarnings["nested/file.txt"].OldTimestamp);
Assert.Equal("2026-03-14 09:00:00", _sut.NewFileTimestampOlderThanOldWarnings["nested/file.txt"].NewTimestamp);
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void RecordNewFileTimestampOlderThanOldWarning_NullOrWhitespace_ThrowsArgumentException(string path)
{
Assert.Throws<ArgumentException>(() =>
_sut.RecordNewFileTimestampOlderThanOldWarning(path, "old", "new"));
}
[Fact]
public void SetOldFilesAbsolutePath_ReplacesExistingEntries()
{
_sut.SetOldFilesAbsolutePath(new[] { "old-a.dll", "old-b.dll" });
_sut.SetOldFilesAbsolutePath(new[] { "old-c.dll" });
Assert.Single(_sut.OldFilesAbsolutePath);
Assert.Equal("old-c.dll", _sut.OldFilesAbsolutePath.Single());
}
[Fact]
public void AddUnchangedFileRelativePath_Parallel_AllEntriesRecorded()
{
const int total = 1000;
Parallel.For(0, total, i =>
{
_sut.AddUnchangedFileRelativePath($"unchanged-{i}.dll");
});
Assert.Equal(total, _sut.UnchangedFilesRelativePath.Count);
}
[Fact]
public void ResetAll_ClearsAllState()
{
_sut.SetOldFilesAbsolutePath(new[] { "old-a.dll" });
_sut.SetNewFilesAbsolutePath(new[] { "new-a.dll" });
_sut.AddUnchangedFileRelativePath("same.dll");
_sut.AddAddedFileAbsolutePath("added.dll");
_sut.AddRemovedFileAbsolutePath("removed.dll");
_sut.AddModifiedFileRelativePath("modified.dll");
_sut.RecordDiffDetail("same.dll", FileDiffResultLists.DiffDetailResult.SHA256Match);
_sut.RecordIgnoredFile("ignored.pdb", FileDiffResultLists.IgnoredFileLocation.Old);
_sut.RecordDisassemblerToolVersion("dotnet-ildasm", "1.0.0");
_sut.RecordDisassemblerToolVersion("dotnet-ildasm", "1.0.0", fromCache: true);
_sut.RecordNewFileTimestampOlderThanOldWarning("stale.txt", "old", "new");
_sut.ResetAll();
Assert.Empty(_sut.OldFilesAbsolutePath);
Assert.Empty(_sut.NewFilesAbsolutePath);
Assert.Empty(_sut.UnchangedFilesRelativePath);
Assert.Empty(_sut.AddedFilesAbsolutePath);
Assert.Empty(_sut.RemovedFilesAbsolutePath);
Assert.Empty(_sut.ModifiedFilesRelativePath);
Assert.Empty(_sut.FileRelativePathToDiffDetailDictionary);
Assert.Empty(_sut.FileRelativePathToIlDisassemblerLabelDictionary);
Assert.Empty(_sut.IgnoredFilesRelativePathToLocation);
Assert.Empty(_sut.DisassemblerToolVersions);
Assert.Empty(_sut.DisassemblerToolVersionsFromCache);
Assert.Empty(_sut.NewFileTimestampOlderThanOldWarnings);
}
/// <summary>
/// Verifies that SummaryStatistics returns all-zero fields when every queue is empty.
/// すべてのキューが空のとき SummaryStatistics が全フィールド 0 を返すことを確認します。
/// </summary>
[Fact]
public void SummaryStatistics_WhenEmpty_ReturnsAllZeros()
{
var stats = _sut.SummaryStatistics;
Assert.Equal(0, stats.AddedCount);
Assert.Equal(0, stats.RemovedCount);
Assert.Equal(0, stats.ModifiedCount);
Assert.Equal(0, stats.UnchangedCount);
Assert.Equal(0, stats.IgnoredCount);
}
/// <summary>
/// Verifies that SummaryStatistics reflects correct counts after adding files to each category.
/// 各分類にファイルを追加したあと SummaryStatistics が正確な件数を返すことを確認します。
/// </summary>
[Fact]
public void SummaryStatistics_AfterAddingFiles_ReflectsCorrectCounts()
{
_sut.AddAddedFileAbsolutePath("/new/a.dll");
_sut.AddAddedFileAbsolutePath("/new/b.dll");
_sut.AddRemovedFileAbsolutePath("/old/c.dll");
_sut.AddModifiedFileRelativePath("d.dll");
_sut.AddModifiedFileRelativePath("e.dll");
_sut.AddModifiedFileRelativePath("f.dll");
_sut.AddUnchangedFileRelativePath("g.dll");
_sut.RecordIgnoredFile("h.pdb", FileDiffResultLists.IgnoredFileLocation.Old);
_sut.RecordIgnoredFile("i.pdb", FileDiffResultLists.IgnoredFileLocation.New);
var stats = _sut.SummaryStatistics;
Assert.Equal(2, stats.AddedCount);
Assert.Equal(1, stats.RemovedCount);
Assert.Equal(3, stats.ModifiedCount);
Assert.Equal(1, stats.UnchangedCount);
Assert.Equal(2, stats.IgnoredCount);
}
/// <summary>
/// Verifies that SummaryStatistics returns all-zero fields after ResetAll.
/// ResetAll 後は SummaryStatistics が全フィールド 0 に戻ることを確認します。
/// </summary>
[Fact]
public void SummaryStatistics_AfterResetAll_ReturnsAllZeros()
{
_sut.AddAddedFileAbsolutePath("/new/a.dll");
_sut.AddRemovedFileAbsolutePath("/old/b.dll");
_sut.AddModifiedFileRelativePath("c.dll");
_sut.AddUnchangedFileRelativePath("d.dll");
_sut.RecordIgnoredFile("e.pdb", FileDiffResultLists.IgnoredFileLocation.Old);
_sut.ResetAll();
var stats = _sut.SummaryStatistics;
Assert.Equal(0, stats.AddedCount);
Assert.Equal(0, stats.RemovedCount);
Assert.Equal(0, stats.ModifiedCount);
Assert.Equal(0, stats.UnchangedCount);
Assert.Equal(0, stats.IgnoredCount);
}
/// <summary>
/// Verifies that IgnoredCount is 1 when the same path is recorded as ignored from both Old and New.
/// 同じパスを IgnoredFile として Old と New の両方から記録した場合、IgnoredCount が 1 であることを確認します。
/// </summary>
[Fact]
public void SummaryStatistics_IgnoredCount_DeduplicatesByRelativePath()
{
_sut.RecordIgnoredFile("same.pdb", FileDiffResultLists.IgnoredFileLocation.Old);
_sut.RecordIgnoredFile("same.pdb", FileDiffResultLists.IgnoredFileLocation.New);
Assert.Equal(1, _sut.SummaryStatistics.IgnoredCount);
}
[Fact]
public void ResultQueueProperties_AreReadOnly()
{
Assert.False(typeof(FileDiffResultLists).GetProperty(nameof(FileDiffResultLists.OldFilesAbsolutePath))?.CanWrite);
Assert.False(typeof(FileDiffResultLists).GetProperty(nameof(FileDiffResultLists.NewFilesAbsolutePath))?.CanWrite);
Assert.False(typeof(FileDiffResultLists).GetProperty(nameof(FileDiffResultLists.UnchangedFilesRelativePath))?.CanWrite);
Assert.False(typeof(FileDiffResultLists).GetProperty(nameof(FileDiffResultLists.AddedFilesAbsolutePath))?.CanWrite);
Assert.False(typeof(FileDiffResultLists).GetProperty(nameof(FileDiffResultLists.RemovedFilesAbsolutePath))?.CanWrite);
Assert.False(typeof(FileDiffResultLists).GetProperty(nameof(FileDiffResultLists.ModifiedFilesRelativePath))?.CanWrite);
}
}
}