Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

NUnit - How to test when using Application.Current?

$
0
0

My project format is like this:

  • RedBean (shared with viewmodels, views, code, xaml)
  • RedBean.iOS
  • RedBean.Android
  • RedBeanUnitTests (my NUnit Library project)

RedBeanUnitTests has a references to RedBean and System, it also has packages: Moq, NUnit, Xamarin.Forms.

Some ViewModel in RedBean has coupled code to Application.Current.Properties in its constructor, I mocked this 'Application' with Moq. I'm trying to test the business logic. Before you mention that it should be decoupled from the ViewModel, I'm trying to find a way around it first unless absolutely necessary to change.

I end up with the error "You MUST call Xamarin.Forms.Init() prior to using it".

All I'm trying to do is to create a ViewModel via its constructor (it ended up being null reference due to no Application.Current running - so now I mocked it).

What can I do? I'm at a loss.


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>