Using xunit, I test a method calling which is the Xamarin.Essentials method
MainThread.GetMainThreadSynchronizationContextAsync(). I added the Xamarin.Essentials nuget to my test project as well.
But I still get an error from Xamarin.Essentials:
Xamarin.Essentials.NotImplementedInReferenceAssemblyException : 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.
Is there a way to get this to work?
An **alternative **I tried is to hide the call
MainThread.GetMainThreadSynchronizationContextAsync() behind an interface to be able to mock it away in the unit test. But then I get into trouble cause System.Reactive is complaining a ArgumentNullException in the SynchronizationContext I receive from XUnit.
// raises ArgumentException in System.Reactive ObserveOn(context) appCtxMock.Setup(_ => _.GetMainThreadContext()).ReturnsAsync(SynchronizationContext.Current);