Skip to content

Commit b5216ad

Browse files
committed
[fix] Copilot comments & remove all getfrompath from tests
1 parent cadf6ad commit b5216ad

6 files changed

Lines changed: 138 additions & 185 deletions

File tree

tests/ByteSync.Client.IntegrationTests/Services/Communications/Transfers/R2DownloadResume_Tests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public void SetUp()
6060
public void TearDown()
6161
{
6262
_clientScope.Dispose();
63+
64+
if (TestDirectory?.Exists == true)
65+
{
66+
TestDirectory.Delete(true);
67+
}
6368
}
6469

6570
[Test]

tests/ByteSync.Client.UnitTests/Services/Comparisons/InventoryComparerIncompletePartsFlatTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,29 @@
88
using ByteSync.Models.Inventories;
99
using ByteSync.Services.Comparisons;
1010
using FluentAssertions;
11+
using ByteSync.TestsCommon;
1112
using NUnit.Framework;
1213

1314
namespace ByteSync.Client.UnitTests.Services.Comparisons;
1415

1516
[TestFixture]
16-
public class InventoryComparerIncompletePartsFlatTests
17+
public class InventoryComparerIncompletePartsFlatTests : AbstractTester
1718
{
1819
private string _tempDirectory = null!;
1920

2021
[SetUp]
2122
public void Setup()
2223
{
23-
_tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
24-
Directory.CreateDirectory(_tempDirectory);
24+
CreateTestDirectory();
25+
_tempDirectory = TestDirectory.FullName;
2526
}
2627

2728
[TearDown]
2829
public void TearDown()
2930
{
30-
if (Directory.Exists(_tempDirectory))
31+
if (TestDirectory?.Exists == true)
3132
{
32-
Directory.Delete(_tempDirectory, true);
33+
TestDirectory.Delete(true);
3334
}
3435
}
3536

tests/ByteSync.Client.UnitTests/Services/Comparisons/InventoryComparerPropagateAccessIssuesTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public void Setup()
2424
CreateTestDirectory();
2525
_tempDirectory = TestDirectory.FullName;
2626
}
27+
28+
[TearDown]
29+
public void TearDown()
30+
{
31+
if (TestDirectory?.Exists == true)
32+
{
33+
TestDirectory.Delete(true);
34+
}
35+
}
2736

2837

2938
private static string CreateInventoryZipFile(string directory, Inventory inventory)

tests/ByteSync.Client.UnitTests/Services/Inventories/FileSystemInspectorTests.cs

Lines changed: 62 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -2,214 +2,163 @@
22
using ByteSync.Common.Business.Misc;
33
using ByteSync.Interfaces.Controls.Inventories;
44
using ByteSync.Services.Inventories;
5+
using ByteSync.TestsCommon;
56
using FluentAssertions;
67
using Moq;
78
using NUnit.Framework;
89

910
namespace ByteSync.Client.UnitTests.Services.Inventories;
1011

11-
public class FileSystemInspectorTests
12+
public class FileSystemInspectorTests : AbstractTester
1213
{
14+
[SetUp]
15+
public void SetUp()
16+
{
17+
CreateTestDirectory();
18+
}
19+
20+
[TearDown]
21+
public void TearDown()
22+
{
23+
if (TestDirectory?.Exists == true)
24+
{
25+
TestDirectory.Delete(true);
26+
}
27+
}
28+
1329
[Test]
1430
public void ClassifyEntry_ReturnsDirectory_ForDirectoryInfo()
1531
{
1632
var posix = new Mock<IPosixFileTypeClassifier>(MockBehavior.Strict);
1733
posix.Setup(p => p.ClassifyPosixEntry(It.IsAny<string>())).Returns(FileSystemEntryKind.Unknown);
1834
var inspector = new FileSystemInspector(posix.Object);
19-
var tempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
20-
21-
try
22-
{
23-
var result = inspector.ClassifyEntry(tempDirectory);
24-
25-
result.Should().Be(FileSystemEntryKind.Directory);
26-
}
27-
finally
28-
{
29-
Directory.Delete(tempDirectory.FullName, true);
30-
}
35+
var tempDirectory = Directory.CreateDirectory(Path.Combine(TestDirectory.FullName, Guid.NewGuid().ToString("N")));
36+
37+
var result = inspector.ClassifyEntry(tempDirectory);
38+
39+
result.Should().Be(FileSystemEntryKind.Directory);
3140
}
32-
41+
3342
[Test]
3443
public void ClassifyEntry_ReturnsRegularFile_ForFileInfo()
3544
{
3645
var posix = new Mock<IPosixFileTypeClassifier>(MockBehavior.Strict);
3746
posix.Setup(p => p.ClassifyPosixEntry(It.IsAny<string>())).Returns(FileSystemEntryKind.Unknown);
3847
var inspector = new FileSystemInspector(posix.Object);
39-
var tempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
48+
var tempDirectory = Directory.CreateDirectory(Path.Combine(TestDirectory.FullName, Guid.NewGuid().ToString("N")));
4049
var tempFilePath = Path.Combine(tempDirectory.FullName, "file.txt");
4150
File.WriteAllText(tempFilePath, "x");
4251
var fileInfo = new FileInfo(tempFilePath);
43-
44-
try
45-
{
46-
var result = inspector.ClassifyEntry(fileInfo);
47-
48-
result.Should().Be(FileSystemEntryKind.RegularFile);
49-
}
50-
finally
51-
{
52-
Directory.Delete(tempDirectory.FullName, true);
53-
}
52+
53+
var result = inspector.ClassifyEntry(fileInfo);
54+
55+
result.Should().Be(FileSystemEntryKind.RegularFile);
5456
}
55-
57+
5658
[Test]
5759
public void ClassifyEntry_ReturnsSymlink_WhenLinkTargetExists()
5860
{
5961
var posix = new Mock<IPosixFileTypeClassifier>(MockBehavior.Strict);
6062
posix.Setup(p => p.ClassifyPosixEntry(It.IsAny<string>())).Returns(FileSystemEntryKind.Unknown);
6163
var inspector = new FileSystemInspector(posix.Object);
62-
var tempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
64+
var tempDirectory = Directory.CreateDirectory(Path.Combine(TestDirectory.FullName, Guid.NewGuid().ToString("N")));
6365
var targetPath = Path.Combine(tempDirectory.FullName, "target.txt");
6466
File.WriteAllText(targetPath, "x");
6567
var linkPath = Path.Combine(tempDirectory.FullName, "link.txt");
66-
68+
6769
try
6870
{
69-
try
70-
{
71-
File.CreateSymbolicLink(linkPath, targetPath);
72-
}
73-
catch (Exception ex)
74-
{
75-
Assert.Ignore($"Symbolic link creation failed: {ex.GetType().Name}");
76-
}
77-
78-
var result = inspector.ClassifyEntry(new FileInfo(linkPath));
79-
80-
result.Should().Be(FileSystemEntryKind.Symlink);
71+
File.CreateSymbolicLink(linkPath, targetPath);
8172
}
82-
finally
73+
catch (Exception ex)
8374
{
84-
Directory.Delete(tempDirectory.FullName, true);
75+
Assert.Ignore($"Symbolic link creation failed: {ex.GetType().Name}");
8576
}
77+
78+
var result = inspector.ClassifyEntry(new FileInfo(linkPath));
79+
80+
result.Should().Be(FileSystemEntryKind.Symlink);
8681
}
87-
82+
8883
[Test]
8984
[Platform(Include = "Linux,MacOsX")]
9085
public void ClassifyEntry_ReturnsPosixSpecialKind_WhenClassifierProvidesOne()
9186
{
9287
var posix = new Mock<IPosixFileTypeClassifier>(MockBehavior.Strict);
9388
posix.Setup(p => p.ClassifyPosixEntry(It.IsAny<string>())).Returns(FileSystemEntryKind.Fifo);
9489
var inspector = new FileSystemInspector(posix.Object);
95-
var tempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
90+
var tempDirectory = Directory.CreateDirectory(Path.Combine(TestDirectory.FullName, Guid.NewGuid().ToString("N")));
9691
var tempFilePath = Path.Combine(tempDirectory.FullName, "file.txt");
9792
File.WriteAllText(tempFilePath, "x");
9893
var fileInfo = new FileInfo(tempFilePath);
99-
100-
try
101-
{
102-
var result = inspector.ClassifyEntry(fileInfo);
103-
104-
result.Should().Be(FileSystemEntryKind.Fifo);
105-
}
106-
finally
107-
{
108-
Directory.Delete(tempDirectory.FullName, true);
109-
}
94+
95+
var result = inspector.ClassifyEntry(fileInfo);
96+
97+
result.Should().Be(FileSystemEntryKind.Fifo);
11098
}
111-
99+
112100
[Test]
113101
[Platform(Include = "Linux,MacOsX")]
114102
public void ClassifyEntry_FallsBackToRegularFile_WhenPosixClassifierThrows()
115103
{
116104
var posix = new Mock<IPosixFileTypeClassifier>(MockBehavior.Strict);
117105
posix.Setup(p => p.ClassifyPosixEntry(It.IsAny<string>())).Throws(new InvalidOperationException("boom"));
118106
var inspector = new FileSystemInspector(posix.Object);
119-
var tempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
107+
var tempDirectory = Directory.CreateDirectory(Path.Combine(TestDirectory.FullName, Guid.NewGuid().ToString("N")));
120108
var tempFilePath = Path.Combine(tempDirectory.FullName, "file.txt");
121109
File.WriteAllText(tempFilePath, "x");
122110
var fileInfo = new FileInfo(tempFilePath);
123-
124-
try
125-
{
126-
var result = inspector.ClassifyEntry(fileInfo);
127-
128-
result.Should().Be(FileSystemEntryKind.RegularFile);
129-
}
130-
finally
131-
{
132-
Directory.Delete(tempDirectory.FullName, true);
133-
}
111+
112+
var result = inspector.ClassifyEntry(fileInfo);
113+
114+
result.Should().Be(FileSystemEntryKind.RegularFile);
134115
}
135116

136117
[Test]
137118
public void IsNoiseDirectoryName_ShouldReturnTrue_ForKnownNoiseDirectory()
138119
{
139120
var inspector = new FileSystemInspector();
140-
var tempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
141-
var noiseDirectory = Directory.CreateDirectory(Path.Combine(tempDirectory.FullName, "$RECYCLE.BIN"));
121+
var noiseDirectory = Directory.CreateDirectory(Path.Combine(TestDirectory.FullName, "$RECYCLE.BIN"));
142122

143-
try
144-
{
145-
var result = inspector.IsNoiseDirectoryName(noiseDirectory, OSPlatforms.Windows);
123+
var result = inspector.IsNoiseDirectoryName(noiseDirectory, OSPlatforms.Windows);
146124

147-
result.Should().BeTrue();
148-
}
149-
finally
150-
{
151-
Directory.Delete(tempDirectory.FullName, true);
152-
}
125+
result.Should().BeTrue();
153126
}
154127

155128
[Test]
156129
public void IsNoiseDirectoryName_ShouldReturnFalse_ForUnknownDirectory()
157130
{
158131
var inspector = new FileSystemInspector();
159-
var tempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
160-
var regularDirectory = Directory.CreateDirectory(Path.Combine(tempDirectory.FullName, "regular"));
132+
var regularDirectory = Directory.CreateDirectory(Path.Combine(TestDirectory.FullName, "regular"));
161133

162-
try
163-
{
164-
var result = inspector.IsNoiseDirectoryName(regularDirectory, OSPlatforms.Windows);
134+
var result = inspector.IsNoiseDirectoryName(regularDirectory, OSPlatforms.Windows);
165135

166-
result.Should().BeFalse();
167-
}
168-
finally
169-
{
170-
Directory.Delete(tempDirectory.FullName, true);
171-
}
136+
result.Should().BeFalse();
172137
}
173138

174139
[Test]
175140
public void IsNoiseFileName_ShouldReturnTrue_ForKnownNoiseFile()
176141
{
177142
var inspector = new FileSystemInspector();
178-
var tempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
179-
var filePath = Path.Combine(tempDirectory.FullName, "thumbs.db");
143+
var filePath = Path.Combine(TestDirectory.FullName, "thumbs.db");
180144
File.WriteAllText(filePath, "x");
181145
var fileInfo = new FileInfo(filePath);
182146

183-
try
184-
{
185-
var result = inspector.IsNoiseFileName(fileInfo, OSPlatforms.Windows);
147+
var result = inspector.IsNoiseFileName(fileInfo, OSPlatforms.Windows);
186148

187-
result.Should().BeTrue();
188-
}
189-
finally
190-
{
191-
Directory.Delete(tempDirectory.FullName, true);
192-
}
149+
result.Should().BeTrue();
193150
}
194151

195152
[Test]
196153
public void IsNoiseFileName_ShouldReturnFalse_ForUnknownFile()
197154
{
198155
var inspector = new FileSystemInspector();
199-
var tempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
200-
var filePath = Path.Combine(tempDirectory.FullName, "regular.txt");
156+
var filePath = Path.Combine(TestDirectory.FullName, "regular.txt");
201157
File.WriteAllText(filePath, "x");
202158
var fileInfo = new FileInfo(filePath);
203159

204-
try
205-
{
206-
var result = inspector.IsNoiseFileName(fileInfo, OSPlatforms.Windows);
160+
var result = inspector.IsNoiseFileName(fileInfo, OSPlatforms.Windows);
207161

208-
result.Should().BeFalse();
209-
}
210-
finally
211-
{
212-
Directory.Delete(tempDirectory.FullName, true);
213-
}
162+
result.Should().BeFalse();
214163
}
215164
}

tests/ByteSync.Client.UnitTests/Services/Inventories/InventoryLoaderIncompleteFlagTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,29 @@
77
using ByteSync.Models.Inventories;
88
using ByteSync.Services.Inventories;
99
using FluentAssertions;
10+
using ByteSync.TestsCommon;
1011
using NUnit.Framework;
1112

1213
namespace ByteSync.Client.UnitTests.Services.Inventories;
1314

1415
[TestFixture]
15-
public class InventoryLoaderIncompleteFlagTests
16+
public class InventoryLoaderIncompleteFlagTests : AbstractTester
1617
{
1718
private string _tempDirectory = null!;
1819

1920
[SetUp]
2021
public void Setup()
2122
{
22-
_tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
23-
Directory.CreateDirectory(_tempDirectory);
23+
CreateTestDirectory();
24+
_tempDirectory = TestDirectory.FullName;
2425
}
2526

2627
[TearDown]
2728
public void TearDown()
2829
{
29-
if (Directory.Exists(_tempDirectory))
30+
if (TestDirectory?.Exists == true)
3031
{
31-
Directory.Delete(_tempDirectory, true);
32+
TestDirectory.Delete(true);
3233
}
3334
}
3435

0 commit comments

Comments
 (0)