Because I have some angles, I would like to check for an angle modulus 360°:
double angle = 0;
double expectedAngle = 360;
angle.Should().BeApproximatelyModulus360(expectedAngle, 0.01);
I have written an extension to the Fluent Assertions framework following a tutorial : https://fluentassertions.com/extensibility/
public static class DoubleExtensions
{
public static DoubleAssertions Should(this double d)
{
return new DoubleAssertions(d);
}
}
public class DoubleAssertions : NumericAssertions<double>
{
public DoubleAssertions(double d) : base(d)
{
}
public AndConstraint<DoubleAssertions> BeApproximatelyModulus360(
double targetValue, double precision, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.Given(() => Subject)
.ForCondition(v => MathHelper.AreCloseEnoughModulus360(targetValue, (double)v, precision))
.FailWith($"Expected value {Subject}] should be approximatively {targetValue} with {precision} modulus 360");
return new AndConstraint<DoubleAssertions>(this);
}
When I use both namespaces :
using FluentAssertions;
using MyProjectAssertions;
Because I also use :
aDouble.Should().BeApproximately(1, 0.001);
I get following compilation error :
Ambiguous call between 'FluentAssertions.AssertionExtensions.Should(double)' and 'MyProjectAssertions.DoubleExtensions.Should(double)'
How to change my code to extend the standard NumericAssertions (or other suitable class) to have my BeApproximatelyModulus360
next to the standard BeApproximately
?
Thanks
using...
statement for one of namespaces or call the method directlyMyProjectAssertions.DoubleExtensions.Should(yourDouble)
– Shelbashelbi