小编And*_*toy的帖子

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

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

[HttpGet]
public IList<Notification> GetNotificationsByCustomerAndId([FromUri] string[] name, [FromUri] int[] lastNotificationID)         
{
    return _storage.GetNotifications(name, lastNotificationID, _topX);
}
Run Code Online (Sandbox Code Playgroud)

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

[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);
}
Run Code Online (Sandbox Code Playgroud)

在传递数组时,还有另一种单元测试方法吗?

c# asp.net unit-testing asp.net-web-api

17
推荐指数
1
解决办法
1316
查看次数

是否有一个像Scan一样的运算符,但让我返回一个IObservable <TResult>而不是IObservable <TSource>?

在这个纯粹用于练习的示例中,这是我想要返回的内容:

如果两个学生在指定的时间内(例如2秒)加入学校,那么我想要一个数据结构返回学生,他们加入的学校以及他们加入之间的时间间隔.

我一直在思考这些问题:

class Program
{
    static void Main(string[] args)
    {
        ObserveStudentsJoiningWithin(TimeSpan.FromSeconds(2));
    }

    static void ObserveStudentsJoiningWithin(TimeSpan timeSpan)
    {
        var school = new School("School 1");

        var admissionObservable =
            Observable.FromEventPattern<StudentAdmittedEventArgs>(school, "StudentAdmitted");

        var observable = admissionObservable.TimeInterval()
            .Scan((current, next) =>
            {
                if (next.Interval - current.Interval <= timeSpan)
                {
                    // But this won't work for me because
                    // this requires me to return a TSource
                    // and not a TResult
                }
            });

        var subscription = observable.Subscribe(TimeIntervalValueHandler);

        school.FillWithStudentsAsync(10, TimeSpan.FromSeconds(3));
        school.FillWithStudentsAsync(8, TimeSpan.FromSeconds(1));

        Console.WriteLine("Press any key to exit …
Run Code Online (Sandbox Code Playgroud)

c# system.reactive

5
推荐指数
1
解决办法
124
查看次数