Hi,
I have hit this problem a few times and can't see what I am doing
wrong.
1) I mock a function that returns some items.
2) I then mock a later function that is called on each of those items
and I want to make sure the correct data is passed to that function.
I have the simplest version I could think of below.
It makes sense to me but it fails with:
Test method TestProject1.RhinoTests.TestMethod1 threw exception:
Rhino.Mocks.Exceptions.ExpectationViolationException: MockedClass.SetId
(Predicate (<>c__DisplayClass3.<TestMethod1>b__1(obj);)); Expected #1,
Actual #0..
If I replace the foreach in the test with the commented out code above
it that'll test how many times the function was called and a
constraint but it doesn't allow me to test the variable part of the
fucntion argument which is what I want.
Can anyone see what I am doing wrong?
Thanks, Vin
///// Test method
[TestMethod]
public void TestMethod1()
{
// assemble
MockRepository mocks = new MockRepository();
MockedClass mocked = mocks.DynamicMock<MockedClass>();
List<string> ids = new List<string> { "id1", "id2" };
Expect.Call(mocked.GetList()).Return(ids);
//mocked.SetId(null);
//LastCall.IgnoreArguments().Constraints(Is.Matching<string>
(idString => idString.Contains("ID:"))).Repeat.Times(2);
foreach (string id in ids)
{
mocked.SetId(null);
LastCall.IgnoreArguments().Constraints(Is.Matching<string>
(idString => idString.Contains(id)));
}
mocks.ReplayAll();
// act
TestingClass.ProcessEvents(mocked);
// assert
mocks.VerifyAll();
}
// Method being tested
public static void ProcessEvents(MockedClass Mocked)
{
List<string> ids = Mocked.GetList();
foreach (string id in ids)
{
string idString = string.Format("ID: {0}", id);
Mocked.SetId(idString);
}
}
// Mocked class definition
public class MockedClass
{
public virtual List<string> GetList()
{
throw new NotImplementedException();
}
public virtual void SetId(string idString)
{
throw new NotImplementedException();
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en
-~----------~----~----~----~------~----~------~--~---