在尝试进行一些测试驱动开发时,我创建了最基本的可构建方法:
public class NoteService : INoteService
{
public IEnumerable<Annotation> GetNotes(ODataQueryOptions oDataQueryOptions)
{
return new List<Annotation>();
}
}
当尝试对其进行单元测试时,似乎不可能创建 ODataQueryOptions 的实例:
[TestFixture]
public class NoteServiceTests
{
[Test]
public void GetNotes_Returns_IEnumerable_Of_Notes()
{
var sut = new NoteService();
var queryOptions = new ODataQueryOptions(new ODataQueryContext(new EdmCoreModel(), new EdmCollectionType())// new new new etc??
Assert.That(() => sut.GetNotes(options), Is.InstanceOf<IEnumerable<Annotation>>());
}
}
如何创建对象 ODataQueryOptions 的简单实例以便将其注入(inject)进行单元测试?
最佳答案
这行得通吗?
var request = new HttpRequestMessage(HttpMethod.Get, "");
var context = new ODataQueryContext(EdmCoreModel.Instance, typeof(int));
var options = new ODataQueryOptions(context, request);
关于c# - 需要 ODataQueryOptions 的单元测试服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40027158/