It is not possible to stub package usage for unit testing either using moq or shims
CraigComeOnThisNameCantBeTaken opened this issue · 3 comments
I am trying to write unit tests around a class which uses the recurly client, however due to the internal constructors and internal methods, I cannot mock or shim the classes.
Example:
var fakeList = new ShimRecurlyList<Plan>();
Error:
Example:
var fakeList = new Mock<RecurlyList<Plan>>();
ShimPlans.List = () => fakeList.Object;
Exception:
System.ArgumentException
HResult=0x80070057
Message=Type to mock must be an interface, a delegate, or a non-sealed, non-static class.
Source=Moq
StackTrace:
at Moq.CastleProxyFactory.CreateProxy(Type mockType, IInterceptor interceptor, Type[] interfaces, Object[] arguments)
at Moq.Mock`1.InitializeInstance()
at Moq.Mock`1.OnGetObject()
at Moq.Mock.get_Object()
at Moq.Mock`1.get_Object()
at KeySystems.SubscriptionServiceTests.RecurlySubscriptionServiceTests.<>c__DisplayClass0_0.<AddPlans>b__1() in D:\KeySystems-CustomerService\KeySystems.SubscriptionServiceTests\RecurlySubscriptionServiceTests.cs:line 57
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
TypeLoadException: Method 'ReadXml' in type 'Castle.Proxies.RecurlyList`1Proxy' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
How should I test my code that relies on the recurly client as a dependency please?
Hi @CraigComeOnThisNameCantBeTaken. Sorry for the delay here and thanks for your question. We'll make sure to get back to you after the long holiday weekend. Thanks for your patience.
Hi @CraigComeOnThisNameCantBeTaken. Sorry for the delay here and thanks for your question. We'll make sure to get back to you after the long holiday weekend. Thanks for your patience.
Many thanks.
Actually, I forgot, we are using API v2.