需要ODataQueryOptions的单元测试服务

时间:2016-10-13 17:14:33

标签: 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的简单实例以便为单元测试注入它?

1 个答案:

答案 0 :(得分:2)

这会有用吗?

var request = new HttpRequestMessage(HttpMethod.Get, "");

var context = new ODataQueryContext(EdmCoreModel.Instance, typeof(int));

var options = new ODataQueryOptions(context, request);