コード例 #1
0
        public static async Task HttpClient_Registrations_Can_Be_Removed()
        {
            // Arrange
            var options = new HttpClientInterceptorOptions()
                          .RegisterGet("https://google.com/", new { message = "Hello world!" })
                          .RegisterGet("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/");
        }
コード例 #2
0
        public static void DeregisterGet_Throws_If_Options_Is_Null()
        {
            // Arrange
            HttpClientInterceptorOptions options = null;

            // Act and Assert
            Assert.Throws <ArgumentNullException>("options", () => options.DeregisterGet("https://google.com"));
        }
コード例 #3
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/"));
        }