Skip to content

Migrate from FluentAssertions to Shouldly #666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Joy-less
Copy link
Contributor

@Joy-less Joy-less commented Feb 2, 2025

As stated in #661, FluentAssertions v8 changed their license from open source (Apache 2.0) to paid costing $130 per seat for commercial use.

This pull request migrates the tests in BitFaster.Caching to Shouldly, a similar library under the BSD-3-clause license.

Alternatively, you can continue using FluentAssertions without updates, but you must pin it at [7.0.0] or [7.1.0] to prevent accidental updates.

There was a huge amount to change here so I used this PowerShell script to help me out: galadril/Shouldly.FromFluentAssertions

@bitfaster
Copy link
Owner

Thanks - I hadn't noticed they had changed the terms.

It seems like because this is an open-source project, it is still legal to use v8 here. However, I dislike the change of license terms so would prefer to migrate. I will do some homework on Shouldly.

@Joy-less
Copy link
Contributor Author

Joy-less commented Feb 3, 2025

It seems like because this is an open-source project, it is still legal to use v8 here. However, I dislike the change of license terms so would prefer to migrate.

I think it's not legal to use even here because this project is under the MIT license, which technically allows this library to be re-published verbatim under a paid license. It would only be fine if this project was under GPL or another viral license.

@@ -25,13 +25,11 @@ public void SinceEpoch()
// On .NET Standard, only windows uses TickCount64
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Duration.SinceEpoch().raw.Should().BeCloseTo(Duration.GetTickCount64(), 15);
Duration.SinceEpoch().raw.ShouldBe(Duration.GetTickCount64());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per shouldly/shouldly#274, looks like you can give the tolerance like this:

Duration.SinceEpoch().raw.ShouldBe(Duration.GetTickCount64(), 15);

Not sure if that applies to all data types or just DateTime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it only applies to DateTime and TimeSpan. Although there is ShouldBeInRange. Another solution could be to use TimeSpan.FromTicks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little bloated sadly but you can do this:

TimeSpan.FromTicks(Duration.SinceEpoch().raw).ShouldBe(TimeSpan.FromTicks(Stopwatch.GetTimestamp()), TimeSpan.FromTicks(15));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I fixed it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like your current commit fails to build.

The convoluted version converting to TimeSpan is a bit of a mess - will need to think on how that might be cleaned up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extension method maybe? I thought you wouldn't want to bloat the project with extension methods.

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.

2 participants