Xamarin.Forms.Mocks icon indicating copy to clipboard operation
Xamarin.Forms.Mocks copied to clipboard

Issue with DeviceInfo plugin: https://github.com/jamesmontemagno/DeviceInfoPlugin

Open Boxer-Property opened this issue 6 years ago • 5 comments

Boxer-Property avatar Nov 07 '19 16:11 Boxer-Property

@Boxer-Property are you hitting a problem? can you post the error message?

I have been able to keep this library on 3.5.0.2, as it has been working on any Xamarin.Forms version 3.5 or higher. But if there is a bug, I want to fix it, thanks!

jonathanpeppers avatar Nov 07 '19 16:11 jonathanpeppers

I have an issue with the testing app. The Plugin.DeviceInfo is throwing an exception. I have a class im calling that references this in that code file and it throws an exception.

Exception thrown: 'System.NotImplementedException' in Plugin.DeviceInfo.dll Exception thrown: 'System.TypeInitializationException' in XXX.UnitTests.dll An exception of type 'System.TypeInitializationException' occurred in XXX.UnitTests.dll but was not handled in user code The type initializer for 'XXXX.XXX.MethodName' threw an exception.

This is a class with only static properties and method. ( Yes it should be refactored ) In this class there are various functions using Connectivity and Device Xam.PlugIn.Essentials

I am setting to static properties, however if I comment out the code the tests run fine. At some point I need to figure out what to do to get around it.

Boxer-Property avatar Nov 07 '19 16:11 Boxer-Property

I'll try and create a test project, but I'm super busy today.

Boxer-Property avatar Nov 07 '19 16:11 Boxer-Property

@Boxer-Property it looks like you are using this plugin, which is where the exception occurs: https://github.com/jamesmontemagno/DeviceInfoPlugin

I would guess that a reference assembly is being used here, and it always throws NotImplementedException if you tried to use it from unit tests.

Maybe a more appropriate solution going forward would be for Xamarin.Forms.Mocks also to support Xamarin.Essentials? I would recommend using Xamarin.Essentials in your app instead, but you may hit a similar issue as I haven't tried it.

jonathanpeppers avatar Feb 09 '20 21:02 jonathanpeppers

Would it not be better to use Xamarin.Essentials.Interfaces and Moq when writing unit tests so that you can mock out anything you need relating to Xamarin.Essentials?

With the Xamarin.Essentials classes being static, and taking advantage of switch-and-bait, you will never get the platform (iOS/Android etc.) implementations when running a test project.

chowarth avatar Apr 30 '20 06:04 chowarth