Пример #1
0
    public async Task CreateStubsAsync_ShouldCreateStub()
    {
        // Arrange
        var client = new HttPlaceholderClient(CreateHttpClient(mock => mock
                                                               .When(HttpMethod.Post, $"{BaseUrl}ph-api/stubs/multiple")
                                                               .WithPartialContent("test-situation1")
                                                               .WithPartialContent("test-situation2")
                                                               .Respond("application/json", CreateStubResponse)));
        var input = new[]
        {
            new StubDto
            {
                Id         = "test-situation1",
                Tenant     = "01-get",
                Conditions = new StubConditionsDto
                {
                    Method = "GET",
                    Url    = new StubUrlConditionDto
                    {
                        Path  = "/testtesttest",
                        Query = new Dictionary <string, string> {
                            { "id", "13" }
                        }
                    }
                },
                Response = new StubResponseDto {
                    StatusCode = 200, Text = "OK my dude!"
                }
            },
            new StubDto
            {
                Id         = "test-situation2",
                Tenant     = "01-get",
                Conditions = new StubConditionsDto
                {
                    Method = "GET",
                    Url    = new StubUrlConditionDto
                    {
                        Path  = "/testtesttest",
                        Query = new Dictionary <string, string> {
                            { "id", "13" }
                        }
                    }
                },
                Response = new StubResponseDto {
                    StatusCode = 200, Text = "OK my dude!"
                }
            }
        };

        // Act
        var result = (await client.CreateStubsAsync(input)).ToArray();

        // Assert
        Assert.AreEqual(2, result.Length);
        Assert.AreEqual("test-situation1", result[0].Stub.Id);
        Assert.AreEqual("test-situation2", result[1].Stub.Id);
    }
Пример #2
0
    public async Task CreateStubsAsync_ExceptionInRequest_ShouldThrowHttPlaceholderClientException()
    {
        // Arrange
        var client = new HttPlaceholderClient(CreateHttpClient(mock => mock
                                                               .When(HttpMethod.Post, $"{BaseUrl}ph-api/stubs/multiple")
                                                               .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!")));

        // Act
        var exception =
            await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() => client.CreateStubsAsync(new StubDto()));

        // Assert
        Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'",
                        exception.Message);
    }
Пример #3
0
    public async Task CreateStubsAsync_Builder_ShouldCreateStub()
    {
        // Arrange
        var client = new HttPlaceholderClient(CreateHttpClient(mock => mock
                                                               .When(HttpMethod.Post, $"{BaseUrl}ph-api/stubs/multiple")
                                                               .WithPartialContent("test-situation1")
                                                               .WithPartialContent("test-situation2")
                                                               .Respond("application/json", CreateStubResponse)));
        var input = new[]
        {
            StubBuilder.Begin().WithId("test-situation1"), StubBuilder.Begin().WithId("test-situation2")
        };

        // Act
        var result = (await client.CreateStubsAsync(input)).ToArray();

        // Assert
        Assert.AreEqual(2, result.Length);
        Assert.AreEqual("test-situation1", result[0].Stub.Id);
        Assert.AreEqual("test-situation2", result[1].Stub.Id);
    }