Esempio n. 1
0
    public static async Task Options_Can_Be_Scoped()
    {
        // Arrange
        var url     = "https://google.com/";
        var payload = new MyObject()
        {
            Message = "Hello world!"
        };

        var options = new HttpClientInterceptorOptions()
                      .RegisterGetJson(url, payload, statusCode: HttpStatusCode.NotFound);

        // Act - begin first scope
        using (options.BeginScope())
        {
            // Assert - original registration
            await HttpAssert.GetAsync(options, url, HttpStatusCode.NotFound);

            // Arrange - first update to registration
            options.RegisterGetJson(url, payload, statusCode: HttpStatusCode.InternalServerError);

            // Assert - first updated registration
            await HttpAssert.GetAsync(options, url, HttpStatusCode.InternalServerError);

            // Act - begin second scope
            using (options.BeginScope())
            {
                // Arrange - second update to registration
                options.RegisterGetJson(url, payload, statusCode: HttpStatusCode.RequestTimeout);

                // Assert - second updated registration
                await HttpAssert.GetAsync(options, url, HttpStatusCode.RequestTimeout);
            }

            // Assert - first updated registration
            await HttpAssert.GetAsync(options, url, HttpStatusCode.InternalServerError);
        }

        // Assert - original registration
        await HttpAssert.GetAsync(options, url, HttpStatusCode.NotFound);
    }
    public static void RegisterGetJson_Validates_Parameters_For_Null()
    {
        // Arrange
        HttpClientInterceptorOptions options = null;

        // Act and Assert
        Should.Throw <ArgumentNullException>(() => options.RegisterGetJson("https://google.com", new { }), "options");

        // Arrange
        options = new HttpClientInterceptorOptions();

        // Act and Assert
        Should.Throw <ArgumentNullException>(() => options.RegisterGetJson("https://google.com", null), "content");
    }