Exemple #1
0
    public void WithImage()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithImage(
            ResponseImageType.Bmp,
            500,
            600,
            "#ababab",
            "stub text",
            10,
            "#000000",
            true,
            96)
                       .Build();

        // Assert
        Assert.AreEqual(ResponseImageType.Bmp, response.Image.Type);
        Assert.AreEqual(500, response.Image.Width);
        Assert.AreEqual(600, response.Image.Height);
        Assert.AreEqual("#ababab", response.Image.BackgroundColor);
        Assert.AreEqual("stub text", response.Image.Text);
        Assert.AreEqual(10, response.Image.FontSize);
        Assert.AreEqual("#000000", response.Image.FontColor);
        Assert.IsTrue(response.Image.WordWrap);
        Assert.AreEqual(96, response.Image.JpegQuality);
    }
Exemple #2
0
    public void WithPermanentRedirect()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithPermanentRedirect("/permanent-redirect")
                       .Build();

        // Assert
        Assert.AreEqual("/permanent-redirect", response.PermanentRedirect);
    }
Exemple #3
0
    public void WithTemporaryRedirect()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithTemporaryRedirect("/temp-redirect")
                       .Build();

        // Assert
        Assert.AreEqual("/temp-redirect", response.TemporaryRedirect);
    }
Exemple #4
0
    public void WithExtraDuration()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithExtraDuration(15000)
                       .Build();

        // Assert
        Assert.AreEqual(15000, response.ExtraDuration);
    }
Exemple #5
0
    public void WithDynamicModeDisabled()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithDynamicModeDisabled()
                       .Build();

        // Assert
        Assert.IsFalse(response.EnableDynamicMode);
    }
Exemple #6
0
    public void ShouldClearScenario()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .ShouldClearScenario()
                       .Build();

        // Assert
        Assert.IsTrue(response.Scenario.ClearState);
    }
Exemple #7
0
    public void WithHtmlBody()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithHtmlBody("<html></html>")
                       .Build();

        // Assert
        Assert.AreEqual("<html></html>", response.Html);
    }
    public void WithResponseAsBuilder()
    {
        // Act
        var stub = StubBuilder.Begin()
                   .WithResponse(StubResponseBuilder.Begin())
                   .Build();

        // Assert
        Assert.IsNotNull(stub.Response);
    }
Exemple #9
0
    public void WithJsonBodyAsObject()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithJsonBody(new { key = "val" })
                       .Build();

        // Assert
        Assert.AreEqual(@"{""key"":""val""}", response.Json);
    }
Exemple #10
0
    public void WithBase64ResponseBodyAsBytes()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithBase64ResponseBody(new byte[] { 1, 2, 3 })
                       .Build();

        // Assert
        Assert.AreEqual("AQID", response.Base64);
    }
Exemple #11
0
    public void WithJsonBodyAsString()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithJsonBody("json")
                       .Build();

        // Assert
        Assert.AreEqual("json", response.Json);
    }
Exemple #12
0
    public void WithTextResponseBody()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithTextResponseBody("text body")
                       .Build();

        // Assert
        Assert.AreEqual("text body", response.Text);
    }
Exemple #13
0
    public void WithBase64ResponseBodyAsString()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithBase64ResponseBody("base64")
                       .Build();

        // Assert
        Assert.AreEqual("base64", response.Base64);
    }
Exemple #14
0
    public void SetScenarioStateTo()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .SetScenarioStateTo("new-state")
                       .Build();

        // Assert
        Assert.AreEqual("new-state", response.Scenario.SetScenarioState);
    }
Exemple #15
0
    public void WithContentType()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithContentType("application/json")
                       .Build();

        // Assert
        Assert.AreEqual("application/json", response.ContentType);
    }
Exemple #16
0
    public void WithFile()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithFile("/var/file.jpg")
                       .Build();

        // Assert
        Assert.AreEqual("/var/file.jpg", response.File);
    }
Exemple #17
0
    public void WithUnixLineEndings()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithUnixLineEndings()
                       .Build();

        // Assert
        Assert.AreEqual(LineEndingType.Unix, response.LineEndings);
    }
Exemple #18
0
    public void WithHttpStatusCodeAsHttpStatusCode()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithHttpStatusCode(HttpStatusCode.BadRequest)
                       .Build();

        // Assert
        Assert.AreEqual(400, response.StatusCode);
    }
Exemple #19
0
    public void WithReverseProxy()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithReverseProxy("http://localhost:5000", true, true, false)
                       .Build();

        // Assert
        Assert.AreEqual("http://localhost:5000", response.ReverseProxy.Url);
        Assert.IsTrue(response.ReverseProxy.AppendQueryString);
        Assert.IsTrue(response.ReverseProxy.AppendPath);
        Assert.IsFalse(response.ReverseProxy.ReplaceRootUrl);
    }
Exemple #20
0
    public void WithResponseHeader()
    {
        // Act
        var response = StubResponseBuilder.Begin()
                       .WithResponseHeader("X-Header-1", "val1")
                       .WithResponseHeader("X-Header-2", "val2")
                       .Build();

        // Assert
        Assert.AreEqual(2, response.Headers.Count);

        Assert.AreEqual("val1", response.Headers["X-Header-1"]);
        Assert.AreEqual("val2", response.Headers["X-Header-2"]);
    }
Exemple #21
0
    public async Task UpdateStubAsync_Builder_ShouldUpdateStub()
    {
        // Arrange
        const string stubId = "stub-id";
        var          client = new HttPlaceholderClient(CreateHttpClient(mock => mock
                                                                        .When(HttpMethod.Put, $"{BaseUrl}ph-api/stubs/{stubId}")
                                                                        .WithPartialContent("OK my dude!")
                                                                        .Respond(HttpStatusCode.NoContent)));

        var input = StubBuilder.Begin()
                    .WithResponse(StubResponseBuilder.Begin().WithTextResponseBody("OK my dude!"));

        // Act / Assert
        await client.UpdateStubAsync(input, "stub-id");
    }
Exemple #22
0
    private static async Task Main(string[] args)
    {
        var services = new ServiceCollection();

        services.AddHttPlaceholderClient(c =>
        {
            c.RootUrl  = "http://*****:*****@"curl 'https://site.com/_nuxt/fonts/fa-solid-900.3eb06c7.woff2' \
  -H 'sec-ch-ua: "" Not A;Brand"";v=""99"", ""Chromium"";v=""96"", ""Google Chrome"";v=""96""' \
  -H 'Referer: ' \
  -H 'Origin: https://site.com' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' \
  -H 'sec-ch-ua-platform: ""Linux""' \
  --compressed ;
curl 'https://site.com/_nuxt/css/4cda201.css' \
  -H 'authority: site.com' \
  -H 'sec-ch-ua: "" Not A;Brand"";v=""99"", ""Chromium"";v=""96"", ""Google Chrome"";v=""96""' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' \
  -H 'sec-ch-ua-platform: ""Linux""' \
  -H 'accept: text/css,*/*;q=0.1' \
  -H 'sec-fetch-site: same-origin' \
  -H 'sec-fetch-mode: no-cors' \
  -H 'sec-fetch-dest: style' \
  -H 'accept-language: en-US,en;q=0.9,nl;q=0.8' \
  -H 'cookie: Consent=eyJhbmFseXRpY2FsIjpmYWxzZX0=' \
  --compressed ;
curl 'https://site.com/_nuxt/1d6c3a9.js' \
  -H 'authority: site.com' \
  -H 'sec-ch-ua: "" Not A;Brand"";v=""99"", ""Chromium"";v=""96"", ""Google Chrome"";v=""96""' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' \
  -H 'sec-ch-ua-platform: ""Linux""' \
  -H 'accept: */*' \
  -H 'sec-fetch-site: same-origin' \
  -H 'sec-fetch-mode: no-cors' \
  -H 'sec-fetch-dest: script' \
  -H 'accept-language: en-US,en;q=0.9,nl;q=0.8' \
  -H 'cookie: Consent=eyJhbmFseXRpY2FsIjpmYWxzZX0=' \
  --compressed";
            var          curlCommandResult = await client.CreateCurlStubsAsync(commands, false);

            // Create stubs based on HTTP archive (HAR).
            var har = await File.ReadAllTextAsync("har.json");

            var harResult = await client.CreateHarStubsAsync(har, false);

            // Create stubs based on OpenAPI definition.
            var openapi = await File.ReadAllTextAsync("petstore.yaml");

            var openApiResult = await client.CreateOpenApiStubsAsync(openapi, false);

            // Execute a scheduled job.
            var scheduledJobResult = await client.ExecuteScheduledJobAsync("CleanOldRequestsJob");

            // Get a list of scheduled job names.
            var scheduledJobNames = await client.GetScheduledJobNamesAsync();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }