Reputation: 39
I am using mock.record()
and I am checking the length of a filename..
The test code is:
MockRepository mock = new MockRepository();
IExtension ext = mock.StrictMock<IExtension>();
using (mock.Record())
{
ext.LogError("filename not valid");
}
LogAnalyser log = new LogAnalyser(ext);
string shortfilename = "jjh.df";
log.IsValid(shortfilename);
mock.Verify(ext);
and the production code is:
public void IsValid(string filename)
{
if(filename.Length<8)
{
extension.LogError("filename is short:" + filename);
}
}
On debugging, the extension.logerror
in production gives an exception:
IExtension.LogError("filename is short:jjh.df"); Expected #0, Actual #1.
IExtension.LogError("filename not valid"); Expected #1, Actual #0.
please provide some solution.
Upvotes: 1
Views: 131
Reputation: 14677
You're using a StrictMock which means only calls specifically set up by you are allowed -- and that includes the values of the parameters. You set an expectation that a call would be made to LogError with the string:
filename not valid
But what actually happened during execution was a call was made with the string:
filename is short:jjh.df
So Rhino.Mocks gives you the two exceptions (one because it found a call that wasn't expected and the other because an expected call was not found).
@Ivo's response of using "IgnoreArguments" should work. If it's not, please include more details as to what version of .NET and Rhino.Mocks you're using.
Upvotes: 0
Reputation: 3436
The LogError is hit more then one time. Add the following:
ext.LogError("filename not valid").IgnoreArguments().Repeat.Any();
I am not 100% sure if you need the
Upvotes: 1