【发布时间】:2015-09-24 15:39:24
【问题描述】:
我正在写一个Xamarin.Forms 项目,我现在正在尝试Unit Test,目前我使用Xamarin.Forms DependencyService,如下所示:
PCL 接口
public interface IGetDatabase
{
string GetDataBase()
}
设备特定实施
[assembly: Dependency(typeof(MyProject.Droid.GetDatabaseImplementation))]
class GetDatabaseImplementation: IGetDatabase
{
public string GetDatabase()
{
return "MyDatabasePath";
}
}
它在 PCL 中被这样调用:
DependencyService.Get<IGetDatabase>().GetDatabase();
现在我想unit Test 这个使用MOQ 来模拟我的接口实现,以便我的实现在运行时生成。我不想写一个模拟类,因为我的实际示例更复杂,所以这意味着它不会工作。
我该怎么做呢?我的DepdencyService 与Xamarin 的耦合是否过于紧密?
【问题讨论】:
标签: c# unit-testing xamarin moq