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
0 votes
Hello,
I'm trying to create a Mock Controller and an instance of that type in order to pass it to my tested class. However, when the mocked method is called I get an Exception:

Test method GestionNet.UnitTesting.UnitTest1.TestDocConfigProvider threw exception: TypeMock.TypeMockException:
*** Method GetDecimales<TipoCalculadorDocDecimales> in type GestionNet.CalculadorDocConfigProvider has no matching overload that returns System.Int32..


The signature of the Method GetDecimales is:

public int GetDecimales(TipoCalculadorDocDecimales tipoDecimales)


And the code I'm using:

MockManager.Init();
MockObject MockDocConfig = MockManager.MockObject(  typeof(CalculadorDocConfigProvider), Constructor.Mocked);            
MockDocConfig.ExpectAndReturn("GetDecimales",  2, typeof(TipoCalculadorDocDecimales));
CalculadorDocConfigProvider docConfig = MockDocConfig.Object as CalculadorDocConfigProvider;
docConfig.GetDecimales(TipoCalculadorDocDecimales.Coste);


What I'm doing wrong? I can't understand why I get this exception.

Thanks,
asked by rsaladrigas (1.8k points)

3 Answers

0 votes
Hi rsaladrigas,

The 3rd parameter in ExpectAndReturn is reserved for mocking generic methods. According to the signature you posted I don't think that's the case, so leaving out this parameter should solve this:

MockDocConfig.ExpectAndReturn("GetDecimales",  2); 


Let me know if this helps.

Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Hi Doron,

Yes, this helped a lot. The problem was with VS Intellisense as it only showed me the signature with 3 params, so I thougt I was forced to pass the type.

Thank you very much.
answered by rsaladrigas (1.8k points)
0 votes
Roger,

It was probably the exception message that threw you off, I'll make sure we clear that up in future versions.

Doron
Typemock Support Team
answered by doron (17.2k points)
...