开发者

Ignoring argument of a List type for a protected method in Moq

开发者 https://www.devze.com 2023-01-31 01:50 出处:网络
I\'m trying to setup an expected call to a protected method. The methods signature looks like this: protected SqlDataReader MethodName(string Name, List<SqlParameter> paramList, SqlConnection c

I'm trying to setup an expected call to a protected method. The methods signature looks like this:

protected SqlDataReader MethodName(string Name, List<SqlParameter> paramList, SqlConnection con)

I've come as far as setting up the expectation as follows, but I get an error when running the test:

mock.开发者_运维百科Protected()
    .Setup<SqlDataReader>( "MethodName", "SomeString", ItExpr.IsAny<List<SqlParameter>>(), ItExpr.IsNull<SqlConnection>() )
    .Returns( dataReader );

The error I get is:

Test method GlobalTests.DBAdapterSystemDataTest.GetDentalWingsProstheticTypeMappings threw exception: 
System.NotSupportedException: Invalid setup on a non-virtual (overridable in VB) member: mock => mock.ExecuteReaderStoredProcedure("GetDentalWingsProstheticTypeMappings", It.IsAny<List`1>(), It.Is<SqlConnection>(v => Object.Equals((Object)v, (Object)null)))

Does anyone have an idea how I can set up the expectation so that it works? I don't care for any argument values, I just want to chech that the method was called at least once.


The error message implies that you need to add the virtual keyword to your MethodName method, so that Moq can override it in the tests.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号