chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
What is the correct usage of ExpectUnmockedCall in the code below? I thought that either call to Mock.Verify would fail or MockManager.Verify would fail. But the test completes succesfully if I remove the call to Assert mockTable.GetCallCount() equal to 1.

[Test]
public void TestDataTableSelect2() {
MockManager.Init();
Mock<DataTable> mockTable = MockManager.MockAll<DataTable>(Constructor.NotMocked);

mockTable.ExpectUnmockedCall("Select", 1, null); //Expect that DataTable.Select is only called once.
DataTable tbl = new DataTable();
tbl.Columns.Add("dummy1");
tbl.Columns.Add("dummy2");

tbl.Select(string.Empty, "dummy2");
tbl.Select(string.Empty, "dummy1");

mockTable.Verify();
Assert.AreEqual(1, mockTable.GetCallCount("Select"));
MockManager.Verify();
}
asked by ksummerlin (4k points)

2 Answers

0 votes
Kelly Hi,

By default verify does not fail if too much calls were made.
(It only fails if not enough calls are made)
Excessive calls are just not mocked, and passed to the reeal class normaly.

Of course this defualt can be changed by using:
mockTable.Strict = true;

Which will cause an exception to be thrown if unexpected calls are made.

:!: if you choose to set the strict to true. an expectation to the ctor call also need to be added:

mockTable.ExpectConstructor();
answered by lior (13.2k points)
0 votes
OK that makes sense. I've been using mostly the natural mocks for my tests up until now and I just wasn't quite sure what the "best practice" was for this.

Thanks.
answered by ksummerlin (4k points)
...