public async Task ShouldCreateConnectorSuccessfully(HttpResponseMessage response) { response.StatusCode.Should().Be(201); ConnectorResource connectorResponse = await this.ParseFromResponse <ConnectorResource>(response); connectorResponse.Id.Should().BeGreaterOrEqualTo(1); connectorResponse.Id.Should().BeLessOrEqualTo(5); connectorResponse.MaxCurrentAmp.Should().BePositive(); }
public async Task ShouldUpdateConnectorSuccessfully(HttpResponseMessage response, PatchConnectorResource expectedValue) { response.StatusCode.Should().Be(200); ConnectorResource connectorResponse = await this.ParseFromResponse <ConnectorResource>(response); if (expectedValue.MaxCurrentAmp.HasValue) { connectorResponse.MaxCurrentAmp.Value.Should().Be(expectedValue.MaxCurrentAmp.Value); } connectorResponse.Id.Should().BeGreaterOrEqualTo(1); connectorResponse.Id.Should().BeLessOrEqualTo(5); connectorResponse.MaxCurrentAmp.Should().BePositive(); }
public async Task <ActionResult <ConnectorResource> > Patch(Guid groupId, Guid chargeStationId, int connectorId, [FromBody] PatchConnectorResource patchConnectorResource) { Group group = await _context.Group.Include(g => g.ChargeStations).ThenInclude(c => c.Connectors).FirstOrDefaultAsync(g => g.Id == groupId); if (group == null) { return(NotFound("Group not found")); } ChargeStation chargeStation; if (!group.ChargeStations.TryGetValue(new ChargeStation(chargeStationId), out chargeStation)) { return(NotFound("Charge station not found")); } Connector connector; if (!chargeStation.Connectors.TryGetValue(new Connector(connectorId), out connector)) { return(NotFound("Connector not found")); } if (patchConnectorResource.MaxCurrentAmp.HasValue) { if (patchConnectorResource.MaxCurrentAmp.Value > connector.MaxCurrentAmp && group.HasExceededCapacity(patchConnectorResource.MaxCurrentAmp.Value - connector.MaxCurrentAmp)) { List <Connector> connectors = (List <Connector>)_context.Connector.Where(c => c.ChargeStation.GroupId == groupId).OrderBy(o => o.MaxCurrentAmp); float excdeededCapacity = group.GetExceededCapacity(); RemoveSuggestions removeSuggestions = new RemoveSuggestions(); removeSuggestions.GenerateAllSuggestions(connectors, excdeededCapacity); throw new CapacityExceededException(excdeededCapacity, removeSuggestions); } connector.ChangeMaxCurrentAmp(patchConnectorResource.MaxCurrentAmp.Value); } await _context.SaveChangesAsync(); ConnectorResource connectorUpdated = _mapper.Map <ConnectorResource>(connector); return(Ok(connectorUpdated)); }
public async Task ThenAllActionsShouldBeExecutedSuccessfully() { _scenarioContext.Should().ContainKey("connectors"); _scenarioContext.Should().ContainKey("actions"); Table actions = ((Table)_scenarioContext["actions"]); List <HttpResponseMessage> connectorsCreated = (List <HttpResponseMessage>)_scenarioContext["connectors"]; actions.Rows.Count.Should().Be(connectorsCreated.Count); for (int i = 0; i < actions.Rows.Count; i++) { connectorsCreated[i].StatusCode.Should().Be(201); ConnectorResource connector = await _connectorDriver.ParseFromResponse <ConnectorResource>(connectorsCreated[i]); TableRow row = actions.Rows[i]; int expectedConnectorId; int.TryParse(row["expectedConnectorId"], out expectedConnectorId).Should().BeTrue(); connector.Id.Should().Be(expectedConnectorId); } }
public async Task <ActionResult <ConnectorResource> > Post(Guid groupId, Guid chargeStationId, [FromBody] SaveConnectorResource saveConnector) { Group group = await _context.Group.Include(g => g.ChargeStations).ThenInclude(c => c.Connectors).FirstOrDefaultAsync(g => g.Id == groupId); if (group == null) { return(NotFound("Group not found")); } Connector connector = _mapper.Map <Connector>(saveConnector); ChargeStation chargeStation; if (!group.ChargeStations.TryGetValue(new ChargeStation(chargeStationId), out chargeStation)) { return(NotFound("Charge station not found")); } if (group.HasExceededCapacity(saveConnector.MaxCurrentAmp.Value)) { List <Connector> connectors = _context.Connector.Where(c => c.ChargeStation.GroupId == groupId).OrderBy(o => o.MaxCurrentAmp).ToList <Connector>(); float excdeededCapacity = group.GetExceededCapacity(); RemoveSuggestions removeSuggestions = new RemoveSuggestions(); removeSuggestions.GenerateAllSuggestions(connectors, excdeededCapacity); throw new CapacityExceededException(excdeededCapacity, removeSuggestions); } chargeStation.SyncConnectorIds(); chargeStation.AppendConnector(connector); await _context.SaveChangesAsync(); ConnectorResource connectorResponse = _mapper.Map <ConnectorResource>(connector); return(CreatedAtAction(nameof(GetConnector), new { chargeStationId = chargeStation.Id, groupId = chargeStation.GroupId, id = connector.Id.Value }, connectorResponse)); }
public async Task ThenTheExpectedConnectorIdShouldBe(int connectorId) { ConnectorResource createdConnector = await _connectorDriver.ParseFromResponse <ConnectorResource>((HttpResponseMessage)_scenarioContext["createdConnector"]); createdConnector.Id.Should().Be(connectorId); }