public async Task CreateHarStubs_ShouldCreateStubs(bool doNotCreateStub) { // Arrange const string har = "HAR JSON"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Post, $"{BaseUrl}ph-api/import/har") .WithQueryString("doNotCreateStub", doNotCreateStub.ToString()) .WithQueryString("tenant", "tenant1") .WithContent(har) .Respond("application/json", CreateHarStubsResult))); // Act var result = (await client.CreateHarStubsAsync(har, 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); }
public async Task CreateHarStubs_ExceptionInRequest_ShouldThrowHttPlaceholderClientException() { // Arrange const string har = "HAR JSON"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Post, $"{BaseUrl}ph-api/import/har") .WithQueryString("doNotCreateStub", "False") .WithQueryString("tenant", "tenant1") .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!"))); // Act var exception = await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() => client.CreateHarStubsAsync(har, false, "tenant1")); // Assert Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'", exception.Message); }