Add overloads for constraints without optional arguments
See original GitHub issueDescription
F# (at least in version 5.0) has difficulties consuming C#-defined functions with “optional” arguments with default value. So writing assertions in F# is not so clean as in C#:
Example
Excellent C# assertion looks like:
// Arrange
var x = 0;
// Act
++x;
// Assert
x.Should().Be(1);
But in F# you should write:
// Arrange
let mutable x = 0
// Act
x <- x+1
// Assert
x.Should().Be(1, "because you need to specify \"because argument\"");
What i would like to have
Just overloads for constraints. Something like this:
public AndConstraint<NumericAssertions<T>> Be(T expected) => this.Be(expected, "");
Versions
- Which version of Fluent Assertions are you using? 5.10.3
- Which .NET runtime and version are you targeting? .NET 5.0
Additional Information
I would like to handle this by myself, if nobody minds.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Why does C# allow overloads when the only difference is ...
A method-overload is not allowed to only differ on the return-type (as ... because there is no optional parameter defined for that method....
Read more >An implementation of function overloading, named ...
function overloading (typically found in C++/Java/C#) optional arguments (basic thing in Python) named arguments (basic thing in Python)
Read more >c# - Optional parameters or overloaded constructors
The reason for using multiple constructors is that the main one can just check if all parameters are not null and whether they...
Read more >Constraints on type parameters - C# Programming Guide
Learn about constraints on type parameters. Constraints tell the compiler what capabilities a type argument must have.
Read more >Function Overloading in C++ With Examples -2023
First, we define an add() function with the two parameters, and then we can overload it by again defining an add() function but...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I wrote some wrapper functions to make using FluentAssertions easier from F#. You can find them here: https://gist.github.com/ursenzler/293b9f23affe7543f8dac288f6fc199b
This works also great in cases when you need to add special configuration.
@ursenzler very nice! Thank you! Thanks a lot, guys! I just wanted to be helpful for such great project