私の現在の解決策は、サービス/データビジネスロジックを持つクラスを作成し、それをローカルデータベース(mdf)でテストしてから、そのクラスをデータサービスクラスの同じ関数でラップすることです。
public class MyDataService : DataService<MyEntities>
{
[WebGet]
[SingleResult]
public Team GetTeam(string name)
{
return _serviceBusinessLogic.GetTeam(name);
}
}
//seam here to make this testable
public class ServiceBusinessLogic
{
public Team GetTeam(string name)
{
return _dbContext.Teams.SingleOrDefault(p => p.Name == name);
}
}
ただし、これらは同一であるため、ラッパー関数は必要ありません。
データサービスを直接テストしたいのですが、CreateDataSourceが保護されているため、データソースを設定する方法がありません。
public class MyDataService : DataService<MyEntities>
{
[WebGet]
[SingleResult]
public Team GetTeam(string name)
{
//problem is CurrentDataSource is not settable, so cant set it in test
return CurrentDataSource.Teams.SingleOrDefault(p => p.Name == name);
}
}