首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Unit testing Asp.Net WebApi:如何使用[FromUri]参数测试方法的正确路由

Unit testing Asp.Net WebApi:如何使用[FromUri]参数测试方法的正确路由
EN

Stack Overflow用户
提问于 2015-12-02 16:57:48
回答 2查看 1.6K关注 0票数 17

我想测试一下这个控制器:

代码语言:javascript
复制
[HttpGet]
public IList<Notification> GetNotificationsByCustomerAndId([FromUri] string[] name, [FromUri] int[] lastNotificationID)         
{
    return _storage.GetNotifications(name, lastNotificationID, _topX);
}

特别是,在这个方法中,我想测试传入输入以形成请求Url的数组是否与进入routeData.Values的数组相同。如果对于单值参数(不是数组),它可以工作,但不能用于数组。如果我调试Values,我只看到controlleraction

代码语言:javascript
复制
[TestMethod]
public void GetNotificationsByCustomerAndId_ArrayOverload_Should_Match_InputParameter_name()
{
    string[] _testName = new string[] { _testCustomer, _testCustomerBis };

    string Url = string.Format(
           "http://www.testpincopallo.it/Notifications/GetByCustomerAndLastID/customersNotificationsInfos?name={0}&name={1}&lastNotificationID={2}&lastNotificationID={3}",
           _testName[0], _testName[1],
           _testNotificationID, _testNotificationIDBis);

    IHttpRouteData routeData = GetRouteData(Url);
    routeData.Values["name"].Should().Be(_testName);
}

当你传递数组的时候,有没有其他的方法来进行单元测试?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34038494

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档