public void ThenTheConnectorShoulNotdBeUpdatedSuccessfully()
        {
            PatchConnectorResource patchConnectorResource = new PatchConnectorResource()
            {
                MaxCurrentAmp = ((SaveConnectorResource)_scenarioContext["createConnector"]).MaxCurrentAmp
            };

            _connectorDriver.ShouldNotUpdateConnectorSuccessfully((HttpResponseMessage)_scenarioContext["updatedConnector"]);
        }
        public async Task ThenTheConnectorShouldBeUpdatedSuccessfully()
        {
            PatchConnectorResource patchConnectorResource = new PatchConnectorResource()
            {
                MaxCurrentAmp = ((SaveConnectorResource)_scenarioContext["createConnector"]).MaxCurrentAmp
            };

            await _connectorDriver.ShouldUpdateConnectorSuccessfully((HttpResponseMessage)_scenarioContext["updatedConnector"], patchConnectorResource);
        }
Пример #3
0
        public async Task <HttpResponseMessage> UpdateConnector(Guid groupId, Guid chargeStationId, int connectorId, float maxCurrentAmp)
        {
            PatchConnectorResource patchConnectorResource = new PatchConnectorResource()
            {
                MaxCurrentAmp = maxCurrentAmp
            };

            return(await Client.PatchAsync(ConnectorUrl(groupId.ToString(), chargeStationId.ToString(), connectorId.ToString()), ConvertToJsonData <PatchConnectorResource>(patchConnectorResource)));
        }
Пример #4
0
        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));
        }