c# - 需要 ODataQueryOptions 的单元测试服务

标签 c# .net unit-testing visual-studio-2015 nunit

在尝试进行一些测试驱动开发时,我创建了最基本的可构建方法:

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/

相关文章:

c# - EF5 代码优先 : IsLoaded and . AsNoTracking()

java - 获取 junit.framework.AssertionFailedError : No tests found in [package] when using Unit and Mockito

angularjs - 单元测试 AngularFire karma 错误

c# - 生成 pgp key 时出现问题?

c# - 不受信任的反序列化策略

c# - 全景windows phone中不同的应用栏导航

c# - 在 C# 中捕获网络流量

java - JUnit测试检查三角形是否是矩形

c# - 如何在 Selenium 3.1.0 中设置 ImplicitWait

c# - Gembox 电子表格 : Is it possible to apply "Convert To Number" for the cells with warning?