Mangopay / mangopay2-net-sdk

.Net SDK for MANGOPAY
https://www.nuget.org/packages/mangopay2-sdk/
20 stars 23 forks source link

Mocking support for APIs #172

Open luixodev opened 2 years ago

luixodev commented 2 years ago

Hello, I'm trying to unit test my solution using Moq framework, but since Moq cannot mock non-virtual type members I always get an Unsupported Error Type. Is there any work around for Mock MangoPayApi services and the apis within ?

I found a couple of possible solutions. One could be making the class virtual (https://github.com/moq/moq4/issues/961) The other one is to create interfaces for this api classes

Thank you

juangcarmona commented 2 years ago

Hi,

I created a dot net core library some years ago, before Mangopay released the mangopay2-net-sdk. I based my work on their previous library, which targeted old .NET framework, I had to do some refactoring to apply best practices and, in my project, you can find I used interfaces, exactly for that reason (unit test with mocking and moq). In the docs, you can find that you can easily do basic mocking...

BTW, at that point (using that library on prod) I sent the code to Mangopay, but nobody answered, that's why I published it here in GitHub.

https://github.com/jgcarmona-com/mangopay-net-core-sdk

I hope it helps you. At least you have an alternative if it fits your needs.

Juan