Skip to content

Add CollectSFData.Tests unit test project and run it in CI - #185

Draft
Jason Gilbertson (jagilber) wants to merge 8 commits into
microsoft:masterfrom
jagilber:feature/test-project
Draft

Jason Gilbertson (jagilber) wants to merge 8 commits into
microsoft:masterfrom
jagilber:feature/test-project

Conversation

@jagilber

Copy link
Copy Markdown
Contributor

Summary

Adds the CollectSFData.Tests xUnit project (101 tests) and runs it in CI after the build. The repository previously had no unit tests.

Shipped code changes are limited to two lines in CollectSFDataDll:

  • ConfigurationOptions.ConvertToUtcTime is now virtual so tests can inject time.
  • FileManager.PopulateCollection throws ArgumentNullException for a null file object instead of a NullReferenceException.

What is in the test project

  • Configuration validation and precedence, time parsing and UTC conversion, upload configuration, file management and orchestration, CSV/JSON serialization and chunking, and basic API surface checks.
  • Test-only seams (ITimeProvider, IFileSystemAbstraction, TestableConfigurationOptions) live in the test project, not the shipped assembly.
  • Targets net48 and net8.0: one full-framework and one modern runtime for CollectSFDataDll, which targets net462/net48/net6.0/net8.0.
  • CollectSFData.Tests.runsettings disables parallelism and AppDomain reuse to avoid file-lock flakiness; docs/contributing.md explains how to run locally.
  • An optional audit fixture writes per-run metadata under the gitignored test-audits/ folder only when COLLECTSFDATA_TEST_AUDIT=1 is set. It records no machine or user names.

CI

workflow.yml gains a dotnet test step after the build that runs the project on net8.0 and net48 in Release. A test failure fails the run. Triggers and permissions are unchanged from #183.

Verification

  • dotnet test -c Release locally: 101 passed on net8.0 and 101 passed on net48, no build warnings.
  • node --test .github/tests/release-policy.test.cjs: 17 passed.
  • actionlint on the workflow: clean.

Notes for reviewers

  • Commits are ordered so the original test work is first, followed by the cleanup (removing local tooling files, moving helpers out of the DLL, opt-in audit output, warning fixes, CI step, retargeting).
  • docs/testing-roadmap.md is the phase plan this work follows; later phases are not part of this PR.
  • Observed while fixing a net48-only test failure, not changed here: FileObject.ExtractNodeName calls Path.GetDirectoryName on an empty string for a bare file name with a .zip extension, which throws on .NET Framework. Real blob URIs always contain directories, so the test now uses one. FileManager.SerializeCsv also trims the file name with TrimEnd(".csv".ToCharArray()), which strips trailing c, s, v and . characters from the base name (for example synthetic becomes syntheti). Both could be hardened in a follow-up.

🤖 Generated with Claude Code

- Add comprehensive testing roadmap (TESTING_ROADMAP.md)
- Create CollectSFData.Tests project with multi-target framework support (net462;net48;net6.0;net8.0)
- Implement 10 baseline unit tests for ConfigurationOptions class:
  * ConvertToUtcTime method (valid/invalid formats)
  * GatherType property behavior and FileType normalization
  * CleanTableName behavior via destination validation
- Add test dependencies: xUnit, FluentAssertions, Coverlet coverage collector
- Configure legacy framework compatibility (C# 7.3, conditional features)
- Tests passing on modern frameworks (net6.0, net8.0)
- Document known issue: strong name verification failures on legacy frameworks

Establishes foundation for progressive test coverage improvement per roadmap phases.
…tions

- Implemented tests for FileManagerProcess to validate handling of null file objects and unknown file data types.
- Added Phase4BasicAPIValidationTests to ensure correct behavior of API-related configurations and file object collections.
- Created SerializationTests to verify CSV and JSON serialization logic, including size constraints and segment splitting.
- Developed TestAuditFixture for lightweight audit metadata generation during test runs.
- Introduced TimeValidationTests to validate time-related configurations and edge cases.
- Added UploadConfigurationTests to check upload configuration scenarios.
- Established IFileSystemAbstraction and ITimeProvider interfaces for better dependency injection and testing.
- Created TestableConfigurationOptions to facilitate testing with mockable dependencies.
Drop the personal MCP server config, session logs, and learn-candidate
capture that were committed alongside the test project. Move the testing
roadmap under docs/, keep only the test project entry in the solution,
and ignore IDE .lscache files.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ITimeProvider, IFileSystemAbstraction and TestableConfigurationOptions
are used only by the test project, so keep them out of the shipped
assembly and NuGet package. The only production changes left are making
ConfigurationOptions.ConvertToUtcTime virtual and a null guard in
FileManager.PopulateCollection.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
TestAuditFixture now writes nothing unless COLLECTSFDATA_TEST_AUDIT=1 is
set, and no longer records machine or user names. Remove an unused
field and variable and replace a blocking Task.Wait in an async test.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Add a dotnet test step after the build that runs CollectSFData.Tests on
net8.0 and net48 in Release using the repository runsettings. Document
the CI test step and the opt-in test audit output.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The test project never compiled for net462 or net48: TestAuditFixture
uses nullable annotations and C# 8 syntax that the full-framework
LangVersion 7.3 pin rejected. Target one full-framework and one modern
runtime, enable the same language settings for both, add the
System.Text.Json reference net48 needs, and annotate the moved helper
types for nullable analysis.

Give the synthetic CSV test file a directory path: a bare name makes
FileObject call Path.GetDirectoryName on an empty string after
compression, which throws on .NET Framework but not on .NET.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant