How to mock extension methods with Rhino Mock?

后端 未结 4 1501
日久生厌
日久生厌 2020-12-20 15:25

I have extended objects of type IDataReader with some extension methods that I needed. The problem is now when I try to mock the IDataReader, the extended method is not incl

4条回答
  •  时光说笑
    2020-12-20 15:53

    It is possible to stub extension method or any other static method without any framework. The following code allows you to do so, you just need to stub _doSumm.

    public static class MyExtensions
    {
        public static Func _doSumm = (x, y) => x + y;
    
        public static int Summ(this int x, int y)
        {
            return _doSumm(x, y);
        }
    }
    

提交回复
热议问题