alexrainman / ModernHttpClient

ModernHttpClient
MIT License
126 stars 28 forks source link

Testing NativeMessageHandler with NUnit (or similar) #16

Closed Xerillio closed 5 years ago

Xerillio commented 6 years ago

I've been using this library as part of a shared .NET Standard 2.0 class library which is used by my Xamarin.Android project. My shared library contains code that uses the NativeMessageHandler and I'd like to write some tests for it. Is there a preferred way of doing this or at least a way that works?

What I've tried is creating a .NET Core project for the tests, however since the target framework is not one of the three supported ones, the NativeMessageHandler throws the exception "You're referencing the Portable version in your App - you need to...". I've also tried with an Android class library which doesn't seem to work with NUnit (at least not out of the box).. so I'm kinda stuck. Does it mean that we need an implementation that works for .NET Core or is there actually a way of using this library in unit testing?

alexrainman commented 6 years ago

It is complicated to write unit testing for IoC or Dependency Injection, basically because the native client is injected at runtime but your code seats in your shared library.