You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The only way to detect through reflection if a method parameter is a parameter array is by checking if the parameter has the ParamArrayAttribute attribute defined on it. However when you mock a method with a params array, the mock implementation looses this attribute.
This behavior can be shown by the below test - I'd expect the last assertion to pass, but it currently fails.
publicabstractclassBase{publicabstractstringParamsArray(paramsint[]args);}[Test]publicvoidParamsArrayLostOnMock(){varbaseMethodParam=typeof(Base).GetMethods()[0].GetParameters()[0];varmock=newMock<Base>();mock.Setup(x =>x.ParamsArray(1,2,3)).Returns("foo");varmockMethodParam=mock.Object.GetType().GetMethods()[0].GetParameters()[0];Assert.IsTrue(baseMethodParam.IsDefined(typeof(ParamArrayAttribute),false),"ParamArrayAttribute is not defined on base");Assert.IsTrue(mockMethodParam.IsDefined(typeof(ParamArrayAttribute),false),"ParamArrayAttribute is not defined on mock");}
The text was updated successfully, but these errors were encountered:
This is an issue in Castle.DynamicProxy most likely. Can you see if it can be reproduced with any of the other open source mocking libraries? (I.e. Rhino, NSubstitute, FakeItEasy, etc.?)
A fix for this is going to be in Castle Core v4.1 (see castleproject/Core#121 (comment)). As soon as we upgrade Castle and republish Moq, this can be closed.
The only way to detect through reflection if a method parameter is a parameter array is by checking if the parameter has the
ParamArrayAttribute
attribute defined on it. However when you mock a method with a params array, the mock implementation looses this attribute.This behavior can be shown by the below test - I'd expect the last assertion to pass, but it currently fails.
The text was updated successfully, but these errors were encountered: