1
Vote

Mocking not working on Interface with C# Optional Paramaters

description

Hi,

I am currently using NMock3 as the Mocking Framework. I ran into an issue where we have an Interface clearly indicated with Optional parameters. But the unit tests are forcing to pass those optional parameters.

Below is a example snippet:
public interface IApiFactory
    {
        ApiWebService GetApiWebServiceInstance(string url, uint? sendTimeout = null, uint? 
               receiveTimeout = null, uint? openTimeout = null, uint? closeTimeout = null);
    }
Unit test:
_mockApiFactory.Expects.One.Method(v => v.GetApiWebServiceInstance(""))
                .With(Is.TypeOf(typeof(string)))
                .WillReturn(_mockApiWebService.MockObject);
I get compile errors as below:
An expression tree may not contain a call or invocation that uses optional arguments

Is this an issue seen by others Or is there other alternatives?

Thank you,
Kiran

comments