//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Test.Mocks { using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; using Validation; /// /// An that sends each request to the specified delegate. /// internal class MockHttpMessageHandler : HttpMessageHandler { /// /// The handler to invoke for each request. /// private readonly Func> handler; /// /// Initializes a new instance of the class. /// /// The handler. internal MockHttpMessageHandler(Func> handler) { Requires.NotNull(handler, "handler"); this.handler = handler; } /// /// Send an HTTP request as an asynchronous operation. /// /// The HTTP request message to send. /// The cancellation token to cancel operation. /// /// Returns .The task object representing the asynchronous operation. /// protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { return this.handler(request, cancellationToken); } } }