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
Hello,

I am using Natural mocks to Unit test and I have been runnin into this below error.

When I run a test case with the Text Fixture I dont get any errors but when run independently I get an error called " has 1 More expected calls".

Below are my test case and Error thrown. ANy help would be greatly appreciated.

Code:

public void SubmitUnSuccessFullyByValidationDataState()
{
var presenter = new CustomerAddressPresenter(view);
using (var recorder = RecorderManager.StartRecording())
{
recorder.VerifyMode = VerifyMode.PassIfNotCalled;
recorder.ExpectAndReturn(view.StreetAndApt, "mock street #1");
recorder.ExpectAndReturn(view.City, "Mock City");
recorder.ExpectAndReturn(view.State, string.Empty);
recorder.ExpectAndReturn(view.Zipcode, "20170");
recorder.ExpectAndReturn(view.Country, "USA");
}
Assert.That(presenter.IsValidAddress, Is.False);
MockManager.Verify();
}

Output:

TestCase UnitTests.CustomerAddressPresenterTests.SubmitUnSuccessFullyByValidationDataState'
failed: TypeMock.VerifyException :
TypeMock Verification: Method UI.Public.Views.ICustomerAddressView.get_Country() has 1 more expected calls
Method InfoSpherix.HuFi.UI.Public.Views.ICustomerAddressView.get_Zipcode() has 1 more expected calls
at TypeMock.MockManager.Verify()
C:HuFi runkUIPublicInfoSpherix.HuFi.UI.Public.UnitTestsCu
asked by gopitype (800 points)

10 Answers

0 votes
Hi,

Im not sure what you mean by "running with the fixture"
do you mean when you run all tests together?

In any case I would start by investigating the independant run.
Try to see if during the execution of:
presenter.IsValidAddress


you actually call:
view.Zipcode
view.Country
answered by lior (13.2k points)
0 votes
Thanks for the reply.

What I meant to say was , when that particular test was run Independently , test was failing but when run along with all the tests in that Fixture that test is succeding.

Regards,
Gopi
answered by gopitype (800 points)
0 votes
Checked replacing the ones you have suggested but the test case is failing still.
answered by gopitype (800 points)
0 votes
My guess is this is some bug with the VerifyMode.PassIfNotCalled feature.

try the following (AlwaysReturn = expect 0 or more times)
[Test,VerifyMocks]
public void SubmitUnSuccessFullyByValidationDataState()
{
  var presenter = new CustomerAddressPresenter(view);  
  using (var recorder = RecorderManager.StartRecording())
  {
     recorder.AlwaysReturn(view.StreetAndApt, "mock street #1");
     recorder.AlwaysReturn(view.City, "Mock City");
     recorder.AlwaysReturn(view.State, string.Empty);
     recorder.AlwaysReturn(view.Zipcode, "20170");
     recorder.AlwaysReturn(view.Country, "USA");
  }
  Assert.That(presenter.IsValidAddress, Is.False);
} 
answered by eli (5.7k points)
0 votes
But there seems to be no method "AlwaysRecord" in the recordmanager class.
answered by gopitype (800 points)
0 votes
woops, :oops: that is what happens when you don't compile the code:

[Test,VerifyMocks]
public void SubmitUnSuccessFullyByValidationDataState()
{
  var presenter = new CustomerAddressPresenter(view); 
  using (var recorder = RecorderManager.StartRecording())
  {
     recorder.DefaultBehavior.RepeatAlways();

     recorder.ExpectAndReturn(view.StreetAndApt, "mock street #1");
     recorder.ExpectAndReturn(view.City, "Mock City");
     recorder.ExpectAndReturn(view.State, string.Empty);
     recorder.ExpectAndReturn(view.Zipcode, "20170");
     recorder.ExpectAndReturn(view.Country, "USA");
  }
  Assert.That(presenter.IsValidAddress, Is.False);
}
answered by eli (5.7k points)
0 votes
Do you mean that code wasnt Built from your side?
answered by gopitype (800 points)
0 votes
It was a typo on my part.
Did the code work?
answered by eli (5.7k points)
0 votes
Sorry Eli, the code doesnt work.
answered by gopitype (800 points)
0 votes
Hi
Are using Verify or ClearMocks for all the tests in the fixture?
If not this can be the reason why the test pass when running the fixture but fails when running alone.

Can you send me the code for presenter.IsValidAddress offline?
I will send you a mail with my address.
answered by ohad (35.4k points)
...