Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

System.NotImplementedException during xUnit test from Xam.Plugins.Settings #70

Closed
arichar1990 opened this issue Jan 23, 2019 · 2 comments

Comments

@arichar1990
Copy link

I am getting the following error when I try to run an xUnit test in a Xamarin project that uses Xam.Plugins.Settings to store data to the device:

Message: System.NotImplementedException : This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

The exception occurs in the ISettings property initialization of the Settings class, which has the following form:

public static class Settings
    {
        private static ISettings AppSettings
        {
            get
            {
                return CrossSettings.Current;
            }
        }
}

When xUnit gets to the return CrossSettings line, the error occurs. Any chance anyone can tell me why this is happening? I have the nuget package installed in both the iOS and Android projects.

@jamesmontemagno
Copy link
Owner

So this should go here: https://github.com/jamesmontemagno/SettingsPlugin

But in general:

Settings has a .net core flavor if you install the pre-release version. Else you can mock out ISettings, which is the recommendation here.

@arichar1990
Copy link
Author

You're right, it should be under SettingsPlugin. Apologies.

I'm relatively new to xUnit so please forgive my ignorance, but how would one go about mocking out ISettings? I'm wanting to test MessagingCenter actions that are dependent upon changes to the Settings object, so would I have to recreate the code I want to test in a mock class then? Again, please forgive my lack of understanding.

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

No branches or pull requests

2 participants