Пример #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)));
        }
Пример #2
0
        public static void Deregister_Throws_If_Builder_Is_Null()
        {
            // Arrange
            var options = new HttpClientInterceptorOptions();

            HttpRequestInterceptionBuilder builder = null;

            // Act and Assert
            Assert.Throws <ArgumentNullException>("builder", () => options.Deregister(builder));
        }
Пример #3
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
            Assert.Throws <ArgumentNullException>("uri", () => options.Deregister(method, uri));
        }
Пример #4
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
            Assert.Throws <ArgumentNullException>("method", () => options.Deregister(method, uri));
        }
Пример #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 Assert.ThrowsAsync <HttpRequestException>(() => HttpAssert.GetAsync(options, "https://google.com/"));

            await Assert.ThrowsAsync <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 Assert.ThrowsAsync <HttpRequestNotInterceptedException>(() => HttpAssert.GetAsync(options, "https://bing.com/"));
        }