【问题标题】:Unit testing service that requires ODataQueryOptions需要 ODataQueryOptions 的单元测试服务
【发布时间】:2016-10-13 17:14:33
【问题描述】:

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

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 的简单实例以便将其注入单元测试?

【问题讨论】:

  • 怎么看起来不可能?

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


【解决方案1】:

这行得通吗?

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

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

var options = new ODataQueryOptions(context, request);

【讨论】:

  • 我得到:'ODataQueryContext' 不包含带有 2 个参数的构造函数有什么建议吗?
猜你喜欢
  • 2014-07-25
  • 1970-01-01
  • 2016-12-14
  • 1970-01-01
  • 1970-01-01
  • 2011-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多