mardi 5 juillet 2016

Unit Test to verify content of IEnumerable

Given the following WebAPI method

public IHttpActionResult GetDeliveryTypes()
{
    return Ok(... .Select(dt => new { Id = dt.Id, Name = dt.Name }));
}

Where

typeof(Id) = long  
typeof(Name) = string

In a unit test, how can I

  1. Assert that the content is as I expect it? For example, the following assertion fails

    var contentResult = response as OkNegotiatedContentResult<IEnumerable<dynamic>>; Assert.IsNotNull(contentResult);

  2. Reduce this IEnumerable<dynamic> result to an IEnumerable<long> so I can verify that it contains the expected sequence of values?

I have already added the InternalsVisibleTo attribute to the AssemblyInfo.

Aucun commentaire:

Enregistrer un commentaire