Rhino Mocks: How to match array arguments pending?
Back on the Knox Street rhino
mockUI.Expect( x => x.Update( new Frame[] {Frame.MakeIncompleteFrame(1, 5)} ) );
This is the exact argument that I need to match. Through trace statements, I have confirmed that this is the actual result, and for example the code behaves as expected but the test disagrees. RhinoMocks answers
TestBowlingScorer.TestGamePresenter.TestStart:
Rhino.Mocks.Exceptions.ExpectationViolationException : IScoreObserver.Update([Frame# 1, Score = 0 Rolls [ 5, PENDING, ]]); Expected #1, Actual #0.
The Frame object contains a few properties, but does not override Equals () yet (overridden by ToString () shown above). Update receives an array of frames; How do I set up this wait? I see the Is.Matching limitation .. not sure how to use it, or rather it is about its verbose nature.
I have a NUnit style Assert helper attribute
public static void AssertFramesAreEqual(Frame[] expectedFrames, Frame[] actualFrames)
{
// loop over both collections
// compare attributes
}
source to share
@Gishu, Yes it is. I just found out about the Arg <> static class, which should allow you to do something like this:
mockUI.Expect( x => x.Update(Arg<Frame[]>
.Matches(fs=>HelperPredicates.CheckFrames ( expected, fs)) ));
There is also a starting point for the Arg <> configuration. List which I haven't explored yet, but it might even be better for what you want.
source to share
Proven works .. don't know if this is the RhinoMocks way.
var expectedFrames = new Frame[] { Frame.MakeIncompleteFrame(1, 5) };
mockUI.Expect( x => x.Update(null) )
.IgnoreArguments()
.Constraints( Is.Matching<Frame[]>( frames => HelperPredicates.CheckFramesMatch(expectedFrames, frames) ) );
A helper predicate is just a function that returns a boolean value - True in exact match else false.
public static bool CheckFramesMatch(Frame[] expectedFrames, Frame[] actualFrames)
{
// return false if array lengths differ
// loop over corresponding elements
// return false if any attribute differs
// return true
}
source to share