Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is not possible to stub package usage for unit testing either using moq or shims #596

Open
CraigComeOnThisNameCantBeTaken opened this issue Nov 23, 2020 · 3 comments
Assignees
Labels

Comments

@CraigComeOnThisNameCantBeTaken

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:

image

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?

@joannasese
Copy link
Contributor

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.

@CraigComeOnThisNameCantBeTaken
Copy link
Author

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.

@CraigComeOnThisNameCantBeTaken
Copy link
Author

Actually, I forgot, we are using API v2.

@jguidry-recurly jguidry-recurly added the V2 V2 Client label Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants