Hi,
I am trying to mock a method call which is inside a "using" statement. The method I wanted to mock is inside the class which I have used in using statement. The class used in using statement is a derived class. It seems I need to mock the Close() and/or Dispose method of base object. But I don't know how. Could you please suggest me something?
The Test script:
[Test, VerifyMocks]
public void SubmittedFormWithValidUserInput()
{
var dummy = Model.Client;
var fakeList = secQuestions;
var fakeErrorList = new Fault[]{};
using (var recorder = RecorderManager.StartRecording())
{
recorder.ExpectAndReturn(dummy.RegisterCustomerProfile(null), fakeErrorList).RepeatAlways();
}
setupListObject(fakeList);
m_presenter.view_Submit(this, EventArgs.Empty);
}
Method to test:
public void view_Submit(object sender, EventArgs e)
{
CustomerProfileRegistrationRequest custProfile = new CustomerProfileRegistrationRequest
{
Customer = m_view.customerBinder,
CustomerConfidential = m_view.ConfidentialBinder,
CustomerSurvey = m_view.SurveyBinder,
CustomerSecurity = m_view.SecurityBinder,
Address = m_view.addressBinder
};
//TODO using
using (var client = Model.Client)
{
if (client.RegisterCustomerProfile(custProfile).Length == 0)
{
m_view.Close();
}
else
{
m_view.ForwardTo<IUserIdCreateView>();
}
}
}
Error :
UserIdCreatePresenterTests.SubmittedFormWithValidUserInput : FailedSystem.NullReferenceException: Object reference not set to an instance of an object.
at System.ServiceModel.ClientBase`1.GetChannelFactory()
at System.ServiceModel.ClientBase`1.Close()
at System.ServiceModel.ClientBase`1.System.IDisposable.Dispose()
at InfoSpherix.HuFi.UI.Public.Presenters.UserIdCreatePresenter.view_Submit(Object sender, EventArgs e) in UserIdCreatePresenter.cs: line 115
at InfoSpherix.HuFi.UI.Public.UnitTests.UserIdCreatePresenterTests.SubmittedFormWithValidUserInput() in UserIdCreatePresenterTests.cs: line 142
at TypeMock.VerifyMocksAttribute.Execute()
at TypeMock.DecoratorAttribute.CallDecoratedMethod()
at TypeMock.ClearMocksAttribute.Execute()
at TypeMock.MethodDecorator.e()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at InfoSpherix.HuFi.UI.Public.UnitTests.UserIdCreatePresenterTests.SubmittedFormWithValidUserInput() in UserIdCreatePresenterTests.cs: line 133
Thanks,
Mukesh[/b]