Example #1
0
    /// <summary>
    /// Deregisters an HTTP GET request.
    /// </summary>
    /// <param name="options">The <see cref="HttpClientInterceptorOptions"/> to set up.</param>
    /// <param name="uriString">The request URL.</param>
    /// <returns>
    /// The value specified by <paramref name="options"/>.
    /// </returns>
    /// <exception cref="ArgumentNullException">
    /// <paramref name="options"/> is <see langword="null"/>.
    /// </exception>
    public static HttpClientInterceptorOptions DeregisterGet(this HttpClientInterceptorOptions options, string uriString)
    {
        if (options == null)
        {
            throw new ArgumentNullException(nameof(options));
        }

        return(options.Deregister(HttpMethod.Get, new Uri(uriString)));
    }
Example #2
0
    public static void Deregister_Throws_If_Builder_Is_Null()
    {
        // Arrange
        var options = new HttpClientInterceptorOptions();

        HttpRequestInterceptionBuilder builder = null;

        // Act and Assert
        Should.Throw <ArgumentNullException>(() => options.Deregister(builder), "builder");
    }
Example #3
0
    public static void Deregister_Throws_If_Method_Is_Null()
    {
        // Arrange
        var options = new HttpClientInterceptorOptions();

        HttpMethod method = null;
        Uri        uri    = new Uri("https://www.just-eat.co.uk");

        // Act and Assert
        Should.Throw <ArgumentNullException>(() => options.Deregister(method, uri), "method");
    }
Example #4
0
    public static void Deregister_Throws_If_Uri_Is_Null()
    {
        // Arrange
        var options = new HttpClientInterceptorOptions();

        HttpMethod method = HttpMethod.Get;
        Uri        uri    = null;

        // Act and Assert
        Should.Throw <ArgumentNullException>(() => options.Deregister(method, uri), "uri");
    }
Example #5
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/"));
    }