lundi 27 juillet 2015

Unit testing DelegatingHandler

How do I unit test a custom DelegatingHandler? I have the following but its complaining the innerHandler not set.

var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://foo.com");
var handler = new FooHandler()
{
    InnerHandler = new FooHandler() 
};

var invoker = new HttpMessageInvoker(handler);
var result = await invoker.SendAsync(httpRequestMessage, new CancellationToken());

Assert.That(result.Headers.GetValues("some-header").First(), Is.Not.Empty, "");

Aucun commentaire:

Enregistrer un commentaire