Mocks & New IRoboCommand for non-windows platforms#217
Mocks & New IRoboCommand for non-windows platforms#217PCAssistSoftware merged 41 commits intoPCAssistSoftware:devfrom
Conversation
- This new IRoboCommand utilizes the IFileCopierFactory to perform copy operations without creating a new RoboCopy process. This allows full control over the actual copy operation if desired, and allows for cross-platform targeting if needed. - Added IAuthenticator to allow customization of the FactoryCommand's authentication prior to starting the command. By default simply verifies it can access source and destination. - Adjusted helpers and extension methods as needed.
|
nice, I will keep following the progress of these changes. Thanks Robert |
- Since this new IRoboCommand is designed to be portable between platforms, the class name has been updated to reflect that.
Claude Suggested Fixes
|
Just an update to this, I've added a github action to my repo. It does basically the same thing as AppVeyor integration, but I find it provides more useful and more controlled behavior. I have it set up to build the solution, run the primary tests (against Robocommand), then run the extension tests. If all completes, it will package up the nuget packages and the compiled exe's (for backup app and console app) and upload as an artifact. This can also be set up to deploy to nuget automatically on a successful push to main (dev) if you wanted to implement that. I'm also reworking some unit tests to be more efficient, more isolated, and better for testing custom implementations (RoboMover and the new RoboCommandPortable which is a managed version of RoboCopy instead of calling a process). Note i do not plan to implement some advanced functions (scheduling, useFAT times, etc), but core functionality should be 1:1. |
|
Okay thanks for update. The idea of using github actions instead of appveyor is interesting and something I may consider at some point, but for now quite happy with appveyor and they have been very helpful recently in adding the VS 2026 and .NET 10 images for me to use for the most recent release. |
|
I just wanted to inform you of the addition. Something I’ve noticed is that AppVeyor is passing while the GitHub action is (correctly) failing the unit tests. |
|
I appreciate it, its certainly good to know of an alternative, as appveyor can sometimes be really problematic, and slow in supporting new .NET versions etc. So thank you |
- Provide a message to the log file if file logging is disabled via RoboSharpConfiguration
Rework CommandTests.cs since Claude.ai was not producing passing tests. Tests are passing locally using RoboCommand.
Trigger RoboCommandPortable to test against the RoboCommand test suite
6743a7a to
a296860
Compare
Fix for including 301_bytes file in output
|
Okay, I will give it a try out when I get a moment and then get back to you. Please bear with me though as currently stacked with work before going away for a few days, so it maybe when I get back |
|
No worries, I'm in absolutely no rush for this. I was more so finishing the original idea behind the extensions than anything, as well as implementing some nice-to-haves for unit testing that I found myself needing. |
There was a problem hiding this comment.
Pull request overview
Adds cross-platform and test-friendly infrastructure to RoboSharp by introducing a fully managed IRoboCommand implementation (RoboCommandPortable), plus a set of mocks in RoboSharp.Extensions to support DI/unit-testing scenarios.
Changes:
- Introduces
RoboCommandPortable(managed Robocopy-like execution) plus supporting factories/authenticators and updated extensions helpers. - Adds
RoboSharp.Extensions.Mocks(mockIRoboCommand, mockIFileCopier/pairs/factory) for unit tests and DI. - Refactors and modernizes unit tests (per-test temp destinations, async/timeout/cancellation), bumps MSTest, and adds a build-and-test GitHub Action.
Reviewed changes
Copilot reviewed 62 out of 62 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| RoboSharpUnitTesting/Test_Setup.cs | Refactors unit test setup to use per-test destinations + cancellation support. |
| RoboSharpUnitTesting/SerializationTests.cs | Uses per-test temp destination + cleanup. |
| RoboSharpUnitTesting/SelectionOptionsTests.cs | Updates assertion API usage for newer MSTest. |
| RoboSharpUnitTesting/RoboSharpUnitTesting.csproj | Bumps MSTest, sets LangVersion, ensures test file copy to output. |
| RoboSharpUnitTesting/RoboQueueEventTests.cs | Makes tests async and isolates destinations per test. |
| RoboSharpUnitTesting/RoboCommandParserTests.cs | Updates assertion API usage for newer MSTest. |
| RoboSharpUnitTesting/RoboCommandEventTests.cs | Makes tests async and isolates destinations per test. |
| RoboSharpUnitTesting/ProgressEstimatorTests.cs | Adds cancellation/timeout usage and per-test destinations; updates expected counts. |
| RoboSharpUnitTesting/LoggingOptionsTests.cs | Makes tests async and isolates destinations per test. |
| RoboSharpUnitTesting/JobOptionsTests.cs | Makes tests async and isolates destinations per test. |
| RoboSharp/VersionManager.cs | Adds platform guard annotation for Windows detection. |
| RoboSharp/SelectionOptions.cs | Improves XML documentation for selection flags. |
| RoboSharp/RoboSharpConfiguration.cs | Adjusts directory-class token defaults and adds directory mismatch mapping. |
| RoboSharp/RoboSharp.csproj | Bumps package version to 1.6.3. |
| RoboSharp/RoboCommand.cs | Ensures parsed ProcessedFileInfo attempts to set enum classification. |
| RoboSharp/RetryOptions.cs | Adds GetRetryWaitTime() helper. |
| RoboSharp/Results/ResultsBuilder.cs | Emits a log message when file logging is disabled after header parsing. |
| RoboSharp/Results/ProgressEstimator.cs | Adds directory mismatch handling and a new AddDirExtra pathway. |
| RoboSharp/ProcessedFileInfo.cs | Adds stored enum int + mapping helpers to translate log class strings to enums. |
| RoboSharp/ProcessedDirectoryFlag.cs | Adds MisMatch directory flag. |
| RoboSharp/DefaultConfigurations/RoboSharpConfig_EN.cs | Updates default existing-dir token. |
| RoboSharp/CopyOptions.cs | Improves XML documentation for /COPY: flags. |
| RoboSharp/Authentication.cs | Exposes internal directory check methods publicly. |
| RoboSharp.sln | Updates VS metadata and adds workflow file to solution items. |
| RoboSharp.Extensions/Windows/CopyFileExFactory.cs | Adds Windows-only guard in factory ctor. |
| RoboSharp.Extensions/Windows/CopyFileEx.cs | Adjusts overwrite behavior for hidden destination files. |
| RoboSharp.Extensions/StreamedCopier.cs | Adjusts attribute handling and hidden-file overwrite behavior. |
| RoboSharp.Extensions/RoboSharp.Extensions.csproj | Bumps package version and updates package documentation text. |
| RoboSharp.Extensions/RoboMover.cs | Ensures results header is created for mover runs. |
| RoboSharp.Extensions/RoboCommandPortableFactory.cs | Adds factory for creating RoboCommandPortable commands. |
| RoboSharp.Extensions/RoboCommandPortable.cs | Adds managed, cross-platform IRoboCommand implementation using IFileCopierFactory. |
| RoboSharp.Extensions/Options/SelectionExtensions.cs | Tightens newer-file exclusion checks to require destination existence. |
| RoboSharp.Extensions/Options/CopyExtensions.cs | Adds empty-directory evaluation + redefines purging logic on IRoboCommand. |
| RoboSharp.Extensions/Mocks/MockRoboCommandFactory.cs | Adds mock command factory for DI/testing. |
| RoboSharp.Extensions/Mocks/MockRoboCommand.cs | Adds mock IRoboCommand implementation returning completed tasks. |
| RoboSharp.Extensions/Mocks/MockProcessedFilePair.cs | Adds mutable processed file pair for tests/mocking. |
| RoboSharp.Extensions/Mocks/MockProcessedDirectoryPair.cs | Adds mutable processed directory pair for tests/mocking. |
| RoboSharp.Extensions/Mocks/MockIFileCopier.cs | Adds mock IFileCopier with delay/return customization. |
| RoboSharp.Extensions/Mocks/MockFileCopierFactory.cs | Adds mock copier factory that produces mock copiers. |
| RoboSharp.Extensions/IFilePairExtensions.cs | Moves/expands evaluation logic for file pairs + UTC timestamp compare. |
| RoboSharp.Extensions/IDirectoryPairExtensions.cs | Moves/expands evaluation logic for directory pairs + mismatch detection helper. |
| RoboSharp.Extensions/IAuthenticator.cs | Adds authenticator abstraction and default implementations for portable command. |
| RoboSharp.Extensions/Helpers/ResultsBuilder.cs | Adjusts logging behavior for extras/skipped + adds mismatch reporting and header suppression. |
| RoboSharp.Extensions/DirectoryPair.cs | Adds helper methods to create child pairs (NET6+). |
| RoboSharp.Extensions.UnitTests/Windows/SymbolicLinkTests.cs | Windows-gates symlink tests and adds admin-check behavior. |
| RoboSharp.Extensions.UnitTests/Windows/CopyFileExTests.cs | Major refactor of CopyFileEx tests to use shared copier test base + richer cases. |
| RoboSharp.Extensions.UnitTests/RoboSharp.Extensions.UnitTests.csproj | Adds targets and bumps MSTest package version. |
| RoboSharp.Extensions.UnitTests/RoboMoverTests.cs | Refactors tests onto shared CommandTests<T> suite + async flow. |
| RoboSharp.Extensions.UnitTests/RoboCommandPortableTests.cs | Adds full CommandTests<T> suite against RoboCommandPortable implementations. |
| RoboSharp.Extensions.UnitTests/Options/CopyExtensionsTests.cs | Updates asserts and messages for clearer failures. |
| RoboSharp.Extensions.UnitTests/IFileCopierTests.cs | Reworks copier tests into generic base + adds StreamedCopier test type. |
| RoboSharp.Extensions.UnitTests/Helpers/ResultsBuilderTests.cs | Updates builder setup + adjusts skipped logging expectations. |
| RoboSharp.Extensions.UnitTests/DirectoryPairTests.cs | Uses per-test temp destination + adds mismatch test coverage. |
| RoboSharp.Extensions.UnitTests/BatchCommandTests.cs | Uses per-test temp destination + cancellation token plumbing + timeouts. |
| RoboSharp.BackupApp/ViewModels/MainWindowViewModel.cs | Wires UI command generator to a selectable command factory. |
| RoboSharp.BackupApp/ViewModels/CommandGeneratorViewModel.cs | Switches to factory-created commands; copies option objects into created commands. |
| RoboSharp.BackupApp/RoboSharp.BackupApp.csproj | Drops net48 target, keeps Windows targets. |
| RoboSharp.BackupApp/MainWindow.xaml | Adds UI selector for command type (RoboCommand/Portable/Mover). |
| .github/workflows/build-and-test.yml | Adds CI workflow to restore/build/test/pack/publish artifacts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi Finally found some time to take a look at this. First question, why the change below as this breaks existing functionality in my apps? RoboSharp/DefaultConfigurations/RoboSharpConfig_EN.cs line 36 changed to And also related area to this e.g. RoboSharp/RoboSharpConfiguration.cs line 329 changed to |
|
any other breaking changes I need to be aware of? |
|
Good catch, I'll re-review. That should be the only one, but I agree with you and I'll revert it since its been there a long time. Robocopy doesn't emit a token there for existing dirs, so it was breaking my unit tests, if i recall correctly. But thats easy enough to handle with a custom configuration, so that is what I'll implement for the unit tests. |
Add support for Logging paths to the MainWindow
- RoboSharpConfig_EN had the 'Existing Directory' overridden, and some consumers rely on that functionality. Reverted back to previous value. - Added unit tests for to ensure this does not occur in future. - This required isolating and exposing the function that transforms a log line into a ProcessedFileInfo for a directory or file. `RoboCommand.ParseFileorDirectory`
Transformed GetDefaultConfiguration() to use [GeneratedRegex]
PCAssistSoftware
left a comment
There was a problem hiding this comment.
couple of comments left in the code, will test fully later
N.B. First time using submit review, so hopefully this works!
- Symbolic Link testing requires Admin privileges. - Instead of declaring the test passed, it will not properly communicate that the test has been ignored if run without admin privileges.
fixed typo
PCAssistSoftware
left a comment
There was a problem hiding this comment.
All looking good, the initial problem I encountered is now resolved. Will run some more thorough tests later today or tomorrow and then get back to you, but unless I find any issues with existing apps this should be good to merge
Normalize nuget package versions to 1.6.3.0
|
OK cool, I'm just did one last commit to normalize the version numbers, since I noticed I bumped extensions greater than robosharp. Both will be v1.6.3 (nuget is currently 1.6.2). (Extensions had been bumped more due to my messing around with an local nuget repository, but once its published I'll defer my stuff back to standard nuget) |
|
Okay, have now tested this release with all my apps and is working fine, also ran all the tests and had a look and test of new functionality via backup app and all looks good, so if nothing more you want to amend then I am more than happy to merge. Thanks again for all you do. |
|
I'm happy that its all working. As part of this commit I had buffed up some of the unit tests as well to be better testing of some things and allow easier testing of others. Part of that was isolating each test to a randomly generated folder instead of always using same source and destination, which previously (rare occasion) had some issues polluting between tests. Suffice to say, merge away! |
I required some mocks for my project, so I opted to add them into the Extensions package.
To make best use of the mocks, I'm also creating a new IRoboCommand to fully simulate the actions of RoboCopy via the IFileCopierFactory interfaces that were introduced a while back. This would allow full control of the copy and logging process by consumers that want it, and should also allow for cross-platform usage via custom IFileCopiers (like the StreamedFileCopier)
Overview
Base library changes:
RetryOptions.GetRetryWaitTime()to provide a TimeSpan based on the specified wait timeProcessedFileInfoAdd RoboSharp.Extensions.RoboCommandPortable
Windows.CopyFileExorStreamedCopierfactories.RoboSharp.Extensions.Mocks
Unit Testing
BackupApp
Build-And-Test Github Action