Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 提供对FluentAssertions的扩展_C#_Unit Testing_Fluent Assertions - Fatal编程技术网

C# 提供对FluentAssertions的扩展

C# 提供对FluentAssertions的扩展,c#,unit-testing,fluent-assertions,C#,Unit Testing,Fluent Assertions,因为我有一些角度,我想检查360°的角度模数: double angle = 0; double expectedAngle = 360; angle.Should().BeApproximatelyModulus360(expectedAngle, 0.01); 我已经编写了Fluent断言框架的扩展 以下是教程: 因为我还使用: aDouble.Should().BeApproximately(1, 0.001); 我发现以下编译错误: 在'FluentAsse

因为我有一些角度,我想检查360°的角度模数:

    double angle = 0;
    double expectedAngle = 360;
    angle.Should().BeApproximatelyModulus360(expectedAngle, 0.01);
我已经编写了Fluent断言框架的扩展 以下是教程:

因为我还使用:

 aDouble.Should().BeApproximately(1, 0.001);
我发现以下编译错误:
在'FluentAssertions.AssertionExtensions.Should(double)'和'MyProjectAssertions.DoubleExtensions.Should(double)'之间的调用不明确

如何更改我的代码以扩展标准数值分区(或其他合适的类),使我的
近似模块360
位于标准
近似模块360
旁边


谢谢

如果您想直接访问
double
对象上的扩展方法,而不是
DoubleAssertion
对象上的扩展方法,为什么还要引入创建新类型
DoubleAssertion
的复杂性呢。相反,直接为
numeriassertions
定义扩展方法


如果要直接访问
double
对象上的扩展方法,而不是
DoubleAssertion
对象上的扩展方法,为什么还要引入创建新类型
DoubleAssertion
的复杂性呢。相反,直接为
numeriassertions
定义扩展方法


删除其中一个名称空间的
using…
语句,或者直接调用该方法
MyProjectAssertions.DoubleExtensions.Should(yourDouble)
!你说得对。但我希望能有一个更短的写作方式。因为它使我的调用类似于FluentAssertions.DoubleExtensions.Should(luminanceComputation.Beta).BeApproximatelyModulus360(0,0.01);-要与以下内容进行比较:Assert.True(MathHelper.AreCloseNoughModules360(0,luminanceComputation.Beta,0.01));-这已经不是很流畅了。事实上,我刚刚遇到了一些其他命名冲突,这些冲突阻止我使用新的断言Api标准FluentAssertion ONER为其中一个名称空间删除
使用…
语句,或者直接调用方法
MyProjectAssertions.DoubleExtensions.Should(yourDouble)
当然可以!你说得对。但我希望能有一个更短的写作方式。因为它使我的调用类似于FluentAssertions.DoubleExtensions.Should(luminanceComputation.Beta).BeApproximatelyModulus360(0,0.01);-要与以下内容进行比较:Assert.True(MathHelper.AreCloseNoughModules360(0,luminanceComputation.Beta,0.01));-事实上,我刚刚经历了一些其他命名冲突,这些冲突阻止了我使用新的断言Api标准的流断言oneThank you very marshall,you帮我找到了我丢失的清晰性谢谢you very marshall,you帮我找到了我丢失的清晰性
using FluentAssertions;
using MyProjectAssertions;
 aDouble.Should().BeApproximately(1, 0.001);
  public static class DoubleAssertionsExtensions
    {
        public static AndConstraint<NumericAssertions<double>> BeApproximatelyModulus360(this NumericAssertions<double> parent,
            double targetValue, double precision, string because = "", params object[] becauseArgs)
        {
            Execute.Assertion
                .Given(() => parent.Subject)
                .ForCondition(v => MathHelper.AreCloseEnoughModulus360(targetValue, (double)v, precision))
                .FailWith(
                    $"Expected value {parent.Subject}] should be approximatively {targetValue} with {precision} modulus 360");
            return new AndConstraint<NumericAssertions<double>>(parent);
        }
    }
 public class Test
    {
        public Test()
        {
            double aDouble = 4;

            aDouble.Should().BeApproximately(1, 0.001);
            aDouble.Should().BeApproximatelyModulus360(0, 0.1);

        }
    }