mercredi 2 décembre 2015

Unit testing Asp.Net WebApi: how to test correct routing of a method with [FromUri] parameters

I'd like to test this controller:

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

In particular, in this method I want to test that the array passed in input to form the request Url, is the same array that goes into routeData.Values. If for single valued parameters (not arrays) it works, now it isn't working. If I debug Values I see only controller and action.

    [TestMethod]
    public void GetNotificationsByCustomerAndId_ArrayOverload_Should_Match_InputParameter_name()
    {
        string[] _testName = new string[] { _testCustomer, _testCustomerBis };

        string Url = string.Format(
           "http://ift.tt/1QdtEvX}",
           _testName[0], _testName[1],
           _testNotificationID, _testNotificationIDBis);

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

Is there another way to unit test while you are passing arrays?

Aucun commentaire:

Enregistrer un commentaire