Skip to content

[refactor] Replace Path.GetTempPath() with AbstractTester.TestDirectory in tests #239

@paul-fresquet

Description

@paul-fresquet

[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)

  1. 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
  2. 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
  3. 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
  4. 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)

  1. DataNodeSourcesViewModelTests.cs - Uses Path.GetTempPath() only as a mock value (may not be necessary)
  2. E2E_Environment_Setup.cs - End-to-end integration tests (special case)
  3. 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 InventoryBuilderInspectorTests.cs
  • Refactor InventoryComparerPropagateAccessIssuesTests.cs
  • Refactor LocalApplicationDataManagerTests.cs
  • Refactor SynchronizationDownloadFinalizerTests.cs
  • Verify all tests pass after refactoring
  • Evaluate special cases and decide if they should be refactored

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions