Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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# Rhino Mocks:如何匹配期望中的数组参数?_C#_Rhino Mocks - Fatal编程技术网

C# Rhino Mocks:如何匹配期望中的数组参数?

C# Rhino Mocks:如何匹配期望中的数组参数?,c#,rhino-mocks,C#,Rhino Mocks,又一次在犀牛嘲笑诺布墙 mockUI.Expect( x => x.Update( new Frame[] {Frame.MakeIncompleteFrame(1, 5)} ) ); 这正是我需要匹配的论点。通过跟踪语句,我已经验证了这也是实际输出,也就是说,代码的行为符合预期,但测试不同意。犀牛的反应是 TestBowlingScorer.TestGamePresenter.TestStart: Rhino.Mocks.Exceptions.ExpectationViolationE

又一次在犀牛嘲笑诺布墙

mockUI.Expect( x => x.Update( new Frame[] {Frame.MakeIncompleteFrame(1, 5)} ) );
这正是我需要匹配的论点。通过跟踪语句,我已经验证了这也是实际输出,也就是说,代码的行为符合预期,但测试不同意。犀牛的反应是

TestBowlingScorer.TestGamePresenter.TestStart:
Rhino.Mocks.Exceptions.ExpectationViolationException : IScoreObserver.Update([Frame# 1, Score =  0 Rolls [  5,  PENDING,  ]]); Expected #1, Actual #0.
框架对象包含很少的属性,但尚未覆盖Equals()(如上所示,已覆盖ToString()。Update接收帧数组; 如何设置此期望?我看到一个Is.匹配约束。。不知道如何使用它,或者更确切地说,我关心它的冗长本质

我有一个助手NUnit样式的自定义断言

public static void AssertFramesAreEqual(Frame[] expectedFrames, Frame[] actualFrames)
{
  // loop over both collections
     // compare attributes
}

经核实的作品。。不知道这是不是犀牛的方式

var expectedFrames = new Frame[] { Frame.MakeIncompleteFrame(1, 5) };
mockUI.Expect( x => x.Update(null) )
            .IgnoreArguments()
            .Constraints( Is.Matching<Frame[]>( frames => HelperPredicates.CheckFramesMatch(expectedFrames, frames) ) );
@吉舒, 是的,就是这样。我还了解了Arg static类,它应该允许您执行以下操作:

mockUI.Expect( x => x.Update(Arg<Frame[]>
           .Matches(fs=>HelperPredicates.CheckFrames ( expected, fs)) ));
mockUI.Expect(x=>x.Update(Arg
.Matches(fs=>HelperPredicates.CheckFrames(预期为fs));

还有Arg.List配置的起始点,我还没有探讨过,但是如果参数是
List
,其中T是类似
mockUI.Update(Arg.List.ContainsAll(预期帧列表))的结构,它可能会更好地满足您的需求不适用于我的
Frame[]
案例,其中Frame是一个不重写Equals()的类-没有在它上面花费太多时间。
mockUI.Expect( x => x.Update(Arg<Frame[]>
           .Matches(fs=>HelperPredicates.CheckFrames ( expected, fs)) ));