This script was created to migrate FluentAssertions to Shouldly in a C# solution. The goal is to simplify the replacement process by automating common changes and reducing manual effort. 💻🔧
While the script aims to cover most cases, it's important to note that:
-
🛠️ It provides a best-effort approach and may not handle all edge cases or custom implementations.
-
⚠️ The solution might not be 100% buildable after running the script, so further manual verification and adjustments may be required.
-
Direct Mappings: Maps FluentAssertions methods to their equivalent in Shouldly.
-
AssertionScope Handling: Removes
using (new AssertionScope())
blocks while keeping the internal lines intact. -
**WithMessage**
Adjustments: Updates patterns like.ShouldThrow().WithMessage()
to the appropriate Shouldly equivalent. -
Duplicate Usings Cleanup: Removes duplicate
using
statements for a cleaner codebase. -
Package References Update: Replaces
FluentAssertions
withShouldly
inDirectory.Packages.props
or.csproj
files.
-
Make sure you have PowerShell installed.
-
Identify the root folder of your solution (where
.sln
and project files are located).
Run the script by providing the path to your solution folder:
param(
[Parameter(Mandatory=$true)]
[Alias("s")]
[string]$SolutionPath
)
For example:
.\Migrate-FluentAssertionsToShouldly.ps1 -SolutionPath "C:\MySolution\Solution.sln"
After running the script:
-
Open your solution in an IDE like Visual Studio.
-
🔍 Review the changes made to your
.cs
and.csproj
files. -
🧪 Run your tests to ensure everything works as expected.
-
The script assumes common patterns of FluentAssertions usage. Custom or complex cases may require manual adjustments. ✋
-
It does not refactor logic; only method and package replacements are performed.
-
Ensure that you commit your code before running the script to allow easy rollback if needed. 🗂️
This script was crafted with 💻 and ❤️ to make your migration journey easier. We hope it saves you time and effort. 🚀
If you have feedback or encounter issues, feel free to contribute or share suggestions. Happy coding! 🥳