Пример #1
0
    public async Task CreateOpenApiStubs_ShouldCreateStubs(bool doNotCreateStub)
    {
        // Arrange
        const string openApi = "OPENAPI JSON";
        var          client  = new HttPlaceholderClient(CreateHttpClient(mock => mock
                                                                         .When(HttpMethod.Post, $"{BaseUrl}ph-api/import/openapi")
                                                                         .WithQueryString("doNotCreateStub", doNotCreateStub.ToString())
                                                                         .WithQueryString("tenant", "tenant1")
                                                                         .WithContent(openApi)
                                                                         .Respond("application/json", CreateOpenApiStubsResult)));

        // Act
        var result = (await client.CreateOpenApiStubsAsync(openApi, doNotCreateStub, "tenant1")).ToArray();

        // Assert
        Assert.AreEqual(1, result.Length);
        Assert.AreEqual("generated-7ed80fbc7e90f8a6b40acb2505aff4c7", result[0].Stub.Id);
        Assert.AreEqual("POST", result[0].Stub.Conditions.Method);
    }
Пример #2
0
    public async Task CreateOpenApiStubs_ExceptionInRequest_ShouldThrowHttPlaceholderClientException()
    {
        // Arrange
        const string openApi = "OPENAPI JSON";
        var          client  = new HttPlaceholderClient(CreateHttpClient(mock => mock
                                                                         .When(HttpMethod.Post, $"{BaseUrl}ph-api/import/openapi")
                                                                         .WithQueryString("doNotCreateStub", "False")
                                                                         .WithQueryString("tenant", "tenant1")
                                                                         .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!")));

        // Act
        var exception =
            await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() =>
                                                                              client.CreateOpenApiStubsAsync(openApi, false, "tenant1"));

        // Assert
        Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'",
                        exception.Message);
    }