public async Task InvokeAsync(HttpContext httpContext) { try { await _next(httpContext); } catch (CapacityExceededException ex) { CapacityExceededProblemDetail capacityExceededResponse = new CapacityExceededProblemDetail(ex.ExceededCapacity, ex.RemoveSuggestions); httpContext.Response.ContentType = "application/json"; httpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; var json = JsonConvert.SerializeObject(capacityExceededResponse); await httpContext.Response.WriteAsync(json); } catch (NoSlotsAvailableException ex) { NoSlotsAvailableProblemDetail noSlotAvailableResponse = new NoSlotsAvailableProblemDetail(ex.ChargeStationId); httpContext.Response.ContentType = "application/json"; httpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; var json = JsonConvert.SerializeObject(noSlotAvailableResponse); await httpContext.Response.WriteAsync(json); } catch (Exception) { //TODO log internally the ex message ProblemDetails errorDetail = new ProblemDetails(); httpContext.Response.ContentType = "application/json"; httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; errorDetail.Title = "Internal server Error"; errorDetail.Status = 500; var json = JsonConvert.SerializeObject(errorDetail); await httpContext.Response.WriteAsync(json); } }
public async Task ThenShouldHaveReturnedANumberOfSuggestions(int count) { _scenarioContext.ContainsKey("createdConnector"); HttpResponseMessage response = (HttpResponseMessage)_scenarioContext["createdConnector"]; CapacityExceededProblemDetail capacityExceeded = await _suggestionDriver.ParseFromResponse <CapacityExceededProblemDetail>(response); capacityExceeded.Status.Should().Be(400); capacityExceeded.RemoveSuggestions.Should().NotBeNull(); _suggestionDriver.ShouldHaveExactNumberOfSuggestions(capacityExceeded, count); }
public async Task ThenTheCreateConnectorResponseShouldContainAtLeastASuggestion() { _scenarioContext.ContainsKey("createdConnector"); HttpResponseMessage response = (HttpResponseMessage)_scenarioContext["createdConnector"]; CapacityExceededProblemDetail capacityExceeded = await _suggestionDriver.ParseFromResponse <CapacityExceededProblemDetail>(response); capacityExceeded.Status.Should().Be(400); capacityExceeded.RemoveSuggestions.Should().NotBeNull(); capacityExceeded.RemoveSuggestions.Count.Should().BeGreaterThan(0); }
public async Task ValidateIfTheConnectorsStillExists(Guid groupId, CapacityExceededProblemDetail capacityProblemDetail) { foreach (var suggestionList in capacityProblemDetail.RemoveSuggestions) { foreach (var suggestion in suggestionList) { var response = await _connectorDriver.GetConnector(groupId, suggestion.ChargeStationId, suggestion.ConnectorId); response.StatusCode.Should().Be(200); } } }
public async Task ThenTheConnectorsFromTheSuggestionsShouldNotBeAutomaticallyDeleted() { _scenarioContext.ContainsKey("createdConnector"); _scenarioContext.ContainsKey("createdGroupResponse"); HttpResponseMessage response = (HttpResponseMessage)_scenarioContext["createdConnector"]; HttpResponseMessage groupResponse = (HttpResponseMessage)_scenarioContext["createdGroupResponse"]; GroupResource group = await _suggestionDriver.ParseFromResponse <GroupResource>(groupResponse); CapacityExceededProblemDetail capacityExceeded = await _suggestionDriver.ParseFromResponse <CapacityExceededProblemDetail>(response); await _suggestionDriver.ValidateIfTheConnectorsStillExists(group.Id, capacityExceeded); }
public async Task WhenDeletingAllConnectorsInTheSuggestionListOfNumber(int suggestionListNumber) { _scenarioContext.ContainsKey("createdConnector"); _scenarioContext.ContainsKey("createdGroupResponse"); HttpResponseMessage groupResponse = (HttpResponseMessage)_scenarioContext["createdGroupResponse"]; HttpResponseMessage response = (HttpResponseMessage)_scenarioContext["createdConnector"]; CapacityExceededProblemDetail capacityExceeded = await _suggestionDriver.ParseFromResponse <CapacityExceededProblemDetail>(response); GroupResource group = await _suggestionDriver.ParseFromResponse <GroupResource>(groupResponse); capacityExceeded.RemoveSuggestions.Count.Should().BeGreaterOrEqualTo(suggestionListNumber); { foreach (var suggestion in capacityExceeded.RemoveSuggestions[suggestionListNumber]) { var deleteResponse = await _connectorDriver.DeleteConnector(group.Id, suggestion.ChargeStationId, suggestion.ConnectorId); deleteResponse.StatusCode.Should().Be(204); } } }
public async Task ThenRemoveSuggestionResponseShouldHaveThisSpecificResults(Table table) { _scenarioContext.ContainsKey("createdConnector"); _scenarioContext.ContainsKey("chargeStationListResponses"); HttpResponseMessage response = (HttpResponseMessage)_scenarioContext["createdConnector"]; List <HttpResponseMessage> createdChargeStations = (List <HttpResponseMessage>)_scenarioContext["chargeStationListResponses"]; CapacityExceededProblemDetail capacityExceeded = await _suggestionDriver.ParseFromResponse <CapacityExceededProblemDetail>(response); foreach (var row in table.Rows) { int sugestionListPosition, chargeStationId, connectorId; int.TryParse(row["suggestionListPosition"], out sugestionListPosition).Should().BeTrue(); int.TryParse(row["chargeStationId"], out chargeStationId).Should().BeTrue(); int.TryParse(row["connectorId"], out connectorId).Should().BeTrue(); capacityExceeded.RemoveSuggestions.Count.Should().BeGreaterOrEqualTo(sugestionListPosition); var suggestionList = capacityExceeded.RemoveSuggestions[sugestionListPosition - 1]; bool foundConnector = false; foreach (var suggestion in suggestionList) { ChargeStationResource chargeStation = await _suggestionDriver.ParseFromResponse <ChargeStationResource>(createdChargeStations[chargeStationId - 1]); if (suggestion.ChargeStationId == chargeStation.Id && suggestion.ConnectorId == connectorId) { foundConnector = true; } } foundConnector.Should().BeTrue(); } }
public void ShouldHaveExactNumberOfSuggestions(CapacityExceededProblemDetail capacityProblemDetail, int number) { capacityProblemDetail.RemoveSuggestions.Count.Should().Be(number); }