[refactor] Replace Path.GetTempPath() with AbstractTester.TestDirectory in tests
Description
Currently, several test classes use Path.GetTempPath() to create temporary directories. To improve consistency and avoid dependency on the system temporary directory, we should refactor these classes to use AbstractTester and its TestDirectory property instead.
Context
A similar refactoring has already been successfully applied to InventoryBuilderPublicTests.cs (see recent commit). This pattern should be applied to all similar test classes.
Classes to refactor
Unit tests (high priority)
-
InventoryBuilderInspectorTests.cs
- File:
tests/ByteSync.Client.UnitTests/Services/Inventories/InventoryBuilderInspectorTests.cs
- Pattern: Uses
Path.GetTempPath() in SetUp() to create _rootTemp
- Action: Inherit from
AbstractTester, replace _rootTemp with TestDirectory.FullName
-
InventoryComparerPropagateAccessIssuesTests.cs
- File:
tests/ByteSync.Client.UnitTests/Services/Comparisons/InventoryComparerPropagateAccessIssuesTests.cs
- Pattern: Uses
Path.GetTempPath() in SetUp() to create _tempDirectory
- Action: Inherit from
AbstractTester, replace _tempDirectory with TestDirectory.FullName
-
LocalApplicationDataManagerTests.cs
- File:
tests/ByteSync.Client.UnitTests/Services/Configurations/LocalApplicationDataManagerTests.cs
- Pattern: Uses
Path.GetTempPath() in multiple individual tests (lines 84, 134, 183, 246)
- Action: Inherit from
AbstractTester, use TestDirectory in each test
-
SynchronizationDownloadFinalizerTests.cs
- File:
tests/ByteSync.Client.UnitTests/Services/Communications/Transfers/Downloading/SynchronizationDownloadFinalizerTests.cs
- Pattern: Uses
Path.GetTempPath() in helper methods (GetTempFilePath(), GetNewTempPath())
- Action: Inherit from
AbstractTester, use TestDirectory in helper methods
Special cases (to evaluate)
DataNodeSourcesViewModelTests.cs - Uses Path.GetTempPath() only as a mock value (may not be necessary)
E2E_Environment_Setup.cs - End-to-end integration tests (special case)
R2UploadDownload_Tests.cs and R2DownloadResume_Tests.cs - Use Path.GetTempPath() as mock values
Benefits of refactoring
- ✅ No more dependency on system temporary directory
- ✅ Use of a dedicated directory in user folder (
ByteSync_Automated_Tests)
- ✅ Consistency with other tests in the project that already use
AbstractTester
- ✅ Simplified and more maintainable code
- ✅ Automatic cleanup management via
AbstractTester
Reference
The refactoring has been successfully applied to InventoryBuilderPublicTests.cs as a reference example.
Checklist
[refactor] Replace Path.GetTempPath() with AbstractTester.TestDirectory in tests
Description
Currently, several test classes use
Path.GetTempPath()to create temporary directories. To improve consistency and avoid dependency on the system temporary directory, we should refactor these classes to useAbstractTesterand itsTestDirectoryproperty instead.Context
A similar refactoring has already been successfully applied to
InventoryBuilderPublicTests.cs(see recent commit). This pattern should be applied to all similar test classes.Classes to refactor
Unit tests (high priority)
InventoryBuilderInspectorTests.cstests/ByteSync.Client.UnitTests/Services/Inventories/InventoryBuilderInspectorTests.csPath.GetTempPath()inSetUp()to create_rootTempAbstractTester, replace_rootTempwithTestDirectory.FullNameInventoryComparerPropagateAccessIssuesTests.cstests/ByteSync.Client.UnitTests/Services/Comparisons/InventoryComparerPropagateAccessIssuesTests.csPath.GetTempPath()inSetUp()to create_tempDirectoryAbstractTester, replace_tempDirectorywithTestDirectory.FullNameLocalApplicationDataManagerTests.cstests/ByteSync.Client.UnitTests/Services/Configurations/LocalApplicationDataManagerTests.csPath.GetTempPath()in multiple individual tests (lines 84, 134, 183, 246)AbstractTester, useTestDirectoryin each testSynchronizationDownloadFinalizerTests.cstests/ByteSync.Client.UnitTests/Services/Communications/Transfers/Downloading/SynchronizationDownloadFinalizerTests.csPath.GetTempPath()in helper methods (GetTempFilePath(),GetNewTempPath())AbstractTester, useTestDirectoryin helper methodsSpecial cases (to evaluate)
DataNodeSourcesViewModelTests.cs- UsesPath.GetTempPath()only as a mock value (may not be necessary)E2E_Environment_Setup.cs- End-to-end integration tests (special case)R2UploadDownload_Tests.csandR2DownloadResume_Tests.cs- UsePath.GetTempPath()as mock valuesBenefits of refactoring
ByteSync_Automated_Tests)AbstractTesterAbstractTesterReference
The refactoring has been successfully applied to
InventoryBuilderPublicTests.csas a reference example.Checklist
InventoryBuilderInspectorTests.csInventoryComparerPropagateAccessIssuesTests.csLocalApplicationDataManagerTests.csSynchronizationDownloadFinalizerTests.cs