Xamarin.Forms.Mocks
Xamarin.Forms.Mocks copied to clipboard
Issue with DeviceInfo plugin: https://github.com/jamesmontemagno/DeviceInfoPlugin
@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!
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.
I'll try and create a test project, but I'm super busy today.
@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.
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.