public async Task GetAllRequestsAsync_ShouldReturnAllRequests() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When($"{BaseUrl}ph-api/requests") .Respond("application/json", AllRequestsResponse))); // Act var result = (await client.GetAllRequestsAsync()).ToArray(); // Assert Assert.AreEqual(1, result.Length); var request = result.Single(); Assert.AreEqual("bec89e6a-9bee-4565-bccb-09f0a3363eee", request.CorrelationId); Assert.AreEqual("POST", request.RequestParameters.Method); Assert.AreEqual(8, request.RequestParameters.Headers.Count); Assert.AreEqual("PostmanRuntime/7.26.8", request.RequestParameters.Headers["User-Agent"]); Assert.AreEqual(2, request.StubExecutionResults.Count); Assert.AreEqual("xml-without-namespaces-specified", request.ExecutingStubId); var stubExecutionResult = request.StubExecutionResults[0]; Assert.AreEqual("post-with-json-object-checker", stubExecutionResult.StubId); Assert.AreEqual("MethodConditionChecker", stubExecutionResult.Conditions.ElementAt(0).CheckerName); Assert.AreEqual(2, request.StubResponseWriterResults.Count); Assert.AreEqual("StatusCodeResponseWriter", request.StubResponseWriterResults[0].ResponseWriterName); }
public async Task UpdateStubAsync_ShouldUpdateStub() { // Arrange const string stubId = "stub-id"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Put, $"{BaseUrl}ph-api/stubs/{stubId}") .WithPartialContent("test-situation") .WithPartialContent("GET") .WithPartialContent("OK my dude!") .Respond(HttpStatusCode.NoContent))); 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 / Assert await client.UpdateStubAsync(input, "stub-id"); }
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); }
public async Task DeleteAllRequestsAsync_ShouldDeleteRequests() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Delete, $"{BaseUrl}ph-api/requests") .Respond(HttpStatusCode.NoContent))); // Act / Assert await client.DeleteAllRequestsAsync(); }
public async Task DeleteAllStubsByTenantAsync_ShouldDeleteStub() { // Arrange const string tenant = "tenantName"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Delete, $"{BaseUrl}ph-api/tenants/{tenant}/stubs") .Respond(HttpStatusCode.NoContent))); // Act / Assert await client.DeleteAllStubsByTenantAsync(tenant); }
public async Task DeleteStubAsync_ShouldDeleteStub() { // Arrange const string stubId = "fallback"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Delete, $"{BaseUrl}ph-api/stubs/{stubId}") .Respond(HttpStatusCode.NoContent))); // Act / Assert await client.DeleteStubAsync(stubId); }
public async Task SetScenario_ShouldSetScenario() { // Arrange const string scenario = "scenario-1"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Put, $"{BaseUrl}ph-api/scenarios/{scenario}") .Respond(HttpStatusCode.NoContent))); // Act / Assert await client.SetScenarioAsync(scenario, new ScenarioStateInputDto()); }
public async Task DeleteRequest_ShouldDeleteRequest() { // Arrange var correlationId = Guid.NewGuid().ToString(); var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Delete, $"{BaseUrl}ph-api/requests/{correlationId}") .Respond(HttpStatusCode.NoContent))); // Act / Assert await client.DeleteRequestAsync(correlationId); }
public async Task CheckFeature_ShouldReturnFeatureEnabledOrNot() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When($"{BaseUrl}ph-api/metadata/features/authentication") .Respond("application/json", FeatureResponse))); // Act var result = await client.CheckFeatureAsync(FeatureFlagType.Authentication); // Assert Assert.IsTrue(result); }
public async Task GetRequestAsync_ShouldReturnUser() { // Arrange const string username = "******"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When($"{BaseUrl}ph-api/users/{username}") .Respond("application/json", GetUserResponse))); // Act var result = await client.GetUserAsync(username); // Assert Assert.AreEqual(username, result.Username); }
public async Task ExecuteScheduledJobAsync_ShouldExecuteScheduledJob() { // Arrange const string jobName = "CleanOldRequestsJobs"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Post, $"{BaseUrl}ph-api/scheduledJob/{jobName}") .Respond("application/json", ExecuteJobJson))); // Act var result = await client.ExecuteScheduledJobAsync(jobName); // Assert Assert.AreEqual("OK", result.Message); }
public async Task ExecuteScheduledJobAsync_ShouldExecuteScheduledJob() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Get, $"{BaseUrl}ph-api/scheduledJob") .Respond("application/json", GetScheduledJobsJson))); // Act var result = await client.GetScheduledJobNamesAsync(); // Assert Assert.AreEqual(1, result.Length); Assert.AreEqual("CleanOldRequestsJob", result[0]); }
public async Task DeleteAllRequestsAsync_ExceptionInRequest_ShouldThrowHttPlaceholderClientException() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Delete, $"{BaseUrl}ph-api/requests") .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!"))); // Act var exception = await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() => client.DeleteAllRequestsAsync()); // Assert Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'", exception.Message); }
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"); }
public async Task GetAllStubsAsync_ShouldReturnAllStubs() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Get, $"{BaseUrl}ph-api/stubs") .Respond("application/json", GetAllStubsResponse))); // Act var result = (await client.GetAllStubsAsync()).ToArray(); // Assert Assert.AreEqual(2, result.Length); Assert.AreEqual("temporary-redirect", result[0].Stub.Id); Assert.AreEqual("dynamic-mode-form-post", result[1].Stub.Id); }
public async Task CheckFeature_ExceptionInRequest_ShouldThrowHttPlaceholderClientException() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When($"{BaseUrl}ph-api/metadata/features/authentication") .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!"))); // Act var exception = await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() => client.CheckFeatureAsync(FeatureFlagType.Authentication)); // Assert Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'", exception.Message); }
public async Task GetTenantNamesAsync_ShouldReturnTenantNames() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When($"{BaseUrl}ph-api/tenants") .Respond("application/json", GetTenantNamesResponse))); // Act var result = (await client.GetTenantNamesAsync()).ToArray(); // Assert Assert.AreEqual(2, result.Length); Assert.AreEqual("01-get", result[0]); Assert.AreEqual("02-post", result[1]); }
public async Task GetScenarioState_ShouldReturnScenarioState() { // Arrange const string scenario = "scenario-1"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Get, $"{BaseUrl}ph-api/scenarios/{scenario}") .Respond("application/json", ScenarioResponse))); // Act var result = await client.GetScenarioStateAsync(scenario); // Assert Assert.AreEqual("scenario-1", result.Scenario); Assert.AreEqual("new-state", result.State); Assert.AreEqual(10, result.HitCount); }
public async Task UpdateStubAsync_ExceptionInRequest_ShouldThrowHttPlaceholderClientException() { // Arrange const string stubId = "stub-id"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Put, $"{BaseUrl}ph-api/stubs/{stubId}") .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!"))); // Act var exception = await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() => client.UpdateStubAsync(new StubDto(), stubId)); // Assert Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'", exception.Message); }
public async Task GetRequestAsync_ExceptionInRequest_ShouldThrowHttPlaceholderClientException() { // Arrange const string username = "******"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When($"{BaseUrl}ph-api/users/{username}") .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!"))); // Act var exception = await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() => client.GetUserAsync(username)); // Assert Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'", exception.Message); }
public async Task GetStubOverviewAsync_ShouldReturnStubOverview() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When($"{BaseUrl}ph-api/stubs/overview") .Respond("application/json", GetStubOverviewResponse))); // Act var result = (await client.GetStubOverviewAsync()).ToArray(); // Assert Assert.AreEqual(2, result.Length); Assert.AreEqual("post-with-json-object-checker", result[0].Stub.Id); Assert.AreEqual("temporary-redirect", result[1].Stub.Id); }
public async Task GetRequestOverviewAsync_ShouldReturnRequestOverview() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When($"{BaseUrl}ph-api/requests/overview") .Respond("application/json", RequestOverviewResponse))); // Act var result = (await client.GetRequestOverviewAsync()).ToArray(); // Assert Assert.AreEqual(2, result.Length); Assert.AreEqual("bec89e6a-9bee-4565-bccb-09f0a3363eee", result[0].CorrelationId); Assert.AreEqual("xml-without-namespaces-specified", result[0].ExecutingStubId); }
public async Task ExecuteScheduledJobAsync_ExceptionInRequest_ShouldThrowHttPlaceholderClientException() { // Arrange const string jobName = "CleanOldRequestsJobs"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Post, $"{BaseUrl}ph-api/scheduledJob/{jobName}") .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!"))); // Act var exception = await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() => client.ExecuteScheduledJobAsync(jobName)); // Assert Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'", exception.Message); }
public async Task GetAllScenarioStates_ShouldReturnAllScenarioStates() { // Arrange var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Get, $"{BaseUrl}ph-api/scenarios") .Respond("application/json", ScenariosResponse))); // Act var result = (await client.GetAllScenarioStatesAsync()).ToArray(); // Assert Assert.AreEqual(2, result.Length); Assert.AreEqual("scenario-1", result[0].Scenario); Assert.AreEqual("new-state", result[0].State); Assert.AreEqual(10, result[0].HitCount); }
public async Task UpdateAllStubsByTenantAsync_ExceptionInRequest_ShouldThrowHttPlaceholderClientException() { // Arrange const string tenant = "01-get"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Put, $"{BaseUrl}ph-api/tenants/{tenant}/stubs") .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!"))); // Act var exception = await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() => client.UpdateAllStubsByTenantAsync(tenant, Array.Empty <StubDto>())); // Assert Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'", exception.Message); }
public async Task GetRequestAsync_ExceptionInRequest_ShouldThrowHttPlaceholderClientException() { // Arrange const string correlationId = "bec89e6a-9bee-4565-bccb-09f0a3363eee"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When($"{BaseUrl}ph-api/requests/{correlationId}") .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!"))); // Act var exception = await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() => client.GetRequestAsync(correlationId)); // Assert Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'", exception.Message); }
public async Task GetStubsByTenantAsync_ShouldReturnStubs() { // Arrange const string tenant = "01-get"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When($"{BaseUrl}ph-api/tenants/{tenant}/stubs") .Respond("application/json", GetStubsResponse))); // Act var result = (await client.GetStubsByTenantAsync(tenant)).ToArray(); // Assert Assert.AreEqual(2, result.Length); Assert.AreEqual("situation-fallback", result[0].Stub.Id); Assert.AreEqual("situation-02", result[1].Stub.Id); }
public async Task SetScenario_ExceptionInRequest_ShouldThrowHttPlaceholderClientException() { // Arrange const string scenario = "scenario-1"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Put, $"{BaseUrl}ph-api/scenarios/{scenario}") .Respond(HttpStatusCode.BadRequest, "text/plain", "Error occurred!"))); // Act var exception = await Assert.ThrowsExceptionAsync <HttPlaceholderClientException>(() => client.SetScenarioAsync(scenario, new ScenarioStateInputDto())); // Assert Assert.AreEqual("Status code '400' returned by HttPlaceholder with message 'Error occurred!'", exception.Message); }
public async Task UpdateAllStubsByTenantAsync_Builder_ShouldUpdateStubs() { // Arrange const string tenant = "01-get"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When(HttpMethod.Put, $"{BaseUrl}ph-api/tenants/{tenant}/stubs") .WithPartialContent("stub1") .WithPartialContent("stub2") .Respond(HttpStatusCode.NoContent))); var stub1 = StubBuilder.Begin().WithId("stub1"); var stub2 = StubBuilder.Begin().WithId("stub2"); var input = new[] { stub1, stub2 }; // Act / Assert await client.UpdateAllStubsByTenantAsync(tenant, input); }
public async Task GetStubAsync_ShouldReturnStub() { // Arrange const string stubId = "fallback"; var client = new HttPlaceholderClient(CreateHttpClient(mock => mock .When($"{BaseUrl}ph-api/stubs/{stubId}") .Respond("application/json", GetStubResponse))); // Act var result = await client.GetStubAsync(stubId); // Assert Assert.IsNotNull(result.Metadata); Assert.IsNotNull(result.Stub); Assert.AreEqual(stubId, result.Stub.Id); Assert.AreEqual("OK FALLBACK", result.Stub.Response.Text); }