public static void DeregisterGet_Throws_If_Options_Is_Null()
    {
        // Arrange
        HttpClientInterceptorOptions options = null;

        // Act and Assert
        Should.Throw <ArgumentNullException>(() => options.DeregisterGet("https://google.com"), "options");
    }
Example #2
0
    public static async Task HttpClient_Registrations_Can_Be_Removed()
    {
        // Arrange
        var options = new HttpClientInterceptorOptions()
                      .RegisterGetJson("https://google.com/", new { message = "Hello world!" })
                      .RegisterGetJson("https://google.co.uk/", new { message = "Hello world!" });

        // Act and Assert
        await HttpAssert.GetAsync(options, "https://google.com/");

        await HttpAssert.GetAsync(options, "https://google.com/");

        await HttpAssert.GetAsync(options, "https://google.co.uk/");

        await HttpAssert.GetAsync(options, "https://google.co.uk/");

        // Arrange
        options.DeregisterGet("https://google.com/")
        .DeregisterGet("https://google.com/");

        // Act and Assert
        await Should.ThrowAsync <HttpRequestException>(() => HttpAssert.GetAsync(options, "https://google.com/"));

        await Should.ThrowAsync <HttpRequestException>(() => HttpAssert.GetAsync(options, "https://google.com/"));

        await HttpAssert.GetAsync(options, "https://google.co.uk/");

        await HttpAssert.GetAsync(options, "https://google.co.uk/");

        // Arrange
        var builder = new HttpRequestInterceptionBuilder()
                      .ForHttps()
                      .ForGet()
                      .ForHost("bing.com");

        options.ThrowOnMissingRegistration = true;
        options.Register(builder);

        await HttpAssert.GetAsync(options, "https://bing.com/");

        options.Deregister(builder);

        await Should.ThrowAsync <HttpRequestNotInterceptedException>(() => HttpAssert.GetAsync(options, "https://bing.com/"));
    }