public async Task CreateStubAsync_ExceptionInRequest_ShouldThrowHttPlaceholderClientException() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Post, $"{BaseUrl}ph-api/stubs") .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!"))); // Act var exception = await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() => client.CreateStubAsync(new StubDto())); // Assert Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'", exception.Message); }
public async Task CreateStubAsync_Builder_ShouldCreateStub() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Post, $"{BaseUrl}ph-api/stubs") .WithPartialContent("stub123") .Respond("application/json", CreateStubResponse))); var input = StubBuilder.Begin().WithId("stub123"); // Act var result = await client.CreateStubAsync(input); // Assert Assert.IsNotNull(result.Stub); Assert.IsNotNull(result.Metadata); Assert.AreEqual("test-situation", result.Stub.Id); Assert.AreEqual("GET", result.Stub.Conditions.Method); }
public async Task CreateStubAsync_ShouldCreateStub() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Post, $"{BaseUrl}ph-api/stubs") .WithPartialContent("test-situation") .WithPartialContent("GET") .WithPartialContent("OK my dude!") .Respond("application/json", CreateStubResponse))); var input = new StubDto { Id = "test-situation", 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.CreateStubAsync(input); // Assert Assert.IsNotNull(result.Stub); Assert.IsNotNull(result.Metadata); Assert.AreEqual("test-situation", result.Stub.Id); Assert.AreEqual("GET", result.Stub.Conditions.Method); }