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.

Add overloads for constraints without optional arguments

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ursenzlercommented, Apr 23, 2021

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.

1reaction
zetrootcommented, Apr 23, 2021

@ursenzler very nice! Thank you! Thanks a lot, guys! I just wanted to be helpful for such great project

Read more comments on GitHub >

github_iconTop 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 >

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