question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`AllBeEquivalentTo` works on enums but not on strings

See original GitHub issue

Description

AllBeEquivalentTo works on enums but not on strings. This is very inconvenient

Complete minimal example reproducing the issue

E.g. testing the State property of a collection of objects all have the same enum value I can write

someCollection.Select(x => x.State)
    .Should()
    .AllBeEquivalentTo(StateEnum.Inactive);

Changing field State from StateEnum to string I had to rewrite my asserts to

someCollection.Select(x => x.State)
    .Distinct()  
    .Should()
    .BeEquivalentTo("Inactive");

which is less elegant than using AllBeEquivalentTo

Expected behavior:

be able to use AllBeEquivalentTo with strings

Actual behavior:

compiler error

Versions

  • Which version of Fluent Assertions are you using? 5.10.3

  • Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.1. core 3.1

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dennisdoomencommented, Aug 9, 2021

I see that v6 has been in the works for over a year - when do you expect the final will be released?

Very soon. I’m trying to fix the last bugs and have already prepared a blog post.

1reaction
kbilstedcommented, Feb 3, 2021

thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Associating Enums with string c# - Stack Overflow
Elegant code is typically described as simple, clean, terse with clear intent and optimally performant, I'm not seeing any of these traits ...
Read more >
String Enums in C#: Everything You Need to Know
Since C# doesn't support enum with string value, in this blog post, we'll look at alternatives and examples that you can use in...
Read more >
Enum.ToString Method (System)
Converts the value of this instance to its equivalent string representation.
Read more >
Collections
A collection object in .NET is so versatile that the number of assertions on them require the same level of versatility. Most, if...
Read more >
When are enums NOT a code smell?
When transmitting data enums are no code smell ... Strings may cause problems by variations in spelling and capitalisation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found