So setzen Sie eine Erweiterungsmethode in Rhino Mocks 3.6 ein
-
14-11-2019 - |
Frage
Guten Nachmittag
Ich habe eine Klasse und es hat eine zugehörige Erweiterungsmethode. generasacodicetagpre.
Erweiterungsmethode: generasacodicetagpre.
Ich versuche jetzt, Rhino zu verwenden und diese Methode zu testen generasacodicetagpre.
Angenommen, ich schreibe meinen Test und habe bereits eine Schnittstelle, die getPERSONINFO () ruft generasacodicetagpre.
und der Hauptgeld ist generasacodicetagpre.
Wie kann ich einen Test für die Erweiterungsmethode CetToken erstellen?
Lösung
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.
Andere Tipps
It should be possible by creating Stub for the extension methods.