سؤال

مساء الخير

لدي فئة ولديها طريقة تمديد مرتبطة. giveacodicetagpre.

طريقة التمديد: giveacodicetagpre.

الآن أحاول استخدام وحيد القرن واختبار هذه الطريقة giveacodicetagpre.

يفترض أنني أكتب الاختبار الخاص بي ولديك بالفعل واجهة تستدعي getpersoninfo () giveacodicetagpre.

ويتوقع الرئيسي هو giveacodicetagpre.

كيف يمكنني إنشاء اختبار للتمديد METOD Gettoken؟

هل كانت مفيدة؟

المحلول

Extension methods are just syntatic sugar for static methods. So what you really need is the ability to mock the static method here. Unfortunately this is not possible in Rhino Mocks.

See the following StackOverflow thread for more details

To mock a static method you need a mocking framework which actually uses the CLR profiler to intercept method calls. As the thread mentions TypeMock should be able to do this.

نصائح أخرى

It should be possible by creating Stub for the extension methods.

Extension methods in Mono 2.4 and RhinoMocks 3.5

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top