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

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

Open
Boxer-Property opened this issue Nov 7, 2019 · 5 comments

Comments

@Boxer-Property
Copy link

No description provided.

@jonathanpeppers
Copy link
Owner

@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!

@Boxer-Property
Copy link
Author

Boxer-Property commented Nov 7, 2019

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
Copy link
Author

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

@jonathanpeppers
Copy link
Owner

@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 jonathanpeppers changed the title Will this be updated for Xamarin 4.2? Issue with DeviceInfo plugin: https://github.com/jamesmontemagno/DeviceInfoPlugin Feb 9, 2020
@chowarth
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants