public static async Task Register_For_Callback_Invokes_Delegate_With_Message_Asynchronous() { // Arrange var requestUri = new Uri("https://api.just-eat.com/"); var content = new { foo = "bar" }; bool wasDelegateInvoked = false; Func <HttpRequestMessage, Task> onIntercepted = async(request) => { request.ShouldNotBeNull(); request.Method.ShouldBe(HttpMethod.Post); request.RequestUri.ShouldBe(requestUri); string json = await request.Content.ReadAsStringAsync(); var body = JObject.Parse(json); body.Value <string>("foo").ShouldBe("bar"); wasDelegateInvoked = true; }; var builder = new HttpRequestInterceptionBuilder() .ForPost() .ForUri(requestUri) .WithInterceptionCallback(onIntercepted); var options = new HttpClientInterceptorOptions().Register(builder); // Act await HttpAssert.PostAsync(options, requestUri.ToString(), content); // Assert wasDelegateInvoked.ShouldBeTrue(); }