I am writing a Xamarin.Forms
project which I am now trying to Unit Test
currently I use the Xamarin.Forms DependencyService like so:
PCL Interface
public interface IGetDatabase
{
string GetDataBase()
}
Device specific Implementation
[assembly: Dependency(typeof(MyProject.Droid.GetDatabaseImplementation))]
class GetDatabaseImplementation: IGetDatabase
{
public string GetDatabase()
{
return "MyDatabasePath";
}
}
And it is called in the PCL like so:
DependencyService.Get<IGetDatabase>().GetDatabase();
Now I would like to unit Test
this using MOQ
to Mock my interface implementation so that my implementations are generated at runtime. I don't want to write a mock class as my actual example is more complicated so means it wont work.
How would I go about doing this? Is my DepdencyService
too tightly coupled to Xamarin
?