public void Algo_should_return_multiple_double_options_with_min_current() { //Arrange decimal capacity = 10; var chargeGroup = new ChargeGroup(Guid.Empty, "", capacity, null); var chargeStation = new ChargeStation(Guid.NewGuid(), "", chargeGroup); chargeGroup.AddChargeStation(chargeStation); var expectedConnectorId_1 = 9; var expectedConnectorId_2 = 8; var expectedConnectorId_3 = 5; chargeStation.AddConnector(0.4m, expectedConnectorId_1); chargeStation.AddConnector(0.5m, expectedConnectorId_2); chargeStation.AddConnector(0.9m, expectedConnectorId_3); chargeStation.AddConnector(2); chargeStation.AddConnector(3); var needToFree = 0.9m; //Act var result = new Algo().FindOptions(chargeGroup, needToFree); //Assert result.Count.ShouldBe(2); //0.4 + 0.5 result.Find(l => l.Exists(c => c.ConnectorId == expectedConnectorId_1)).Count.ShouldBe(2); result.Find(l => l.Exists(c => c.ConnectorId == expectedConnectorId_1)) .Find(c => c.ConnectorId == expectedConnectorId_1).Amps.ShouldBe(0.4m); result.Find(l => l.Exists(c => c.ConnectorId == expectedConnectorId_1)) .Find(c => c.ConnectorId == expectedConnectorId_2).Amps.ShouldBe(0.5m); //0.9 result.Find(l => l.Exists(c => c.ConnectorId == expectedConnectorId_3)).Count.ShouldBe(1); result.Find(l => l.Exists(c => c.ConnectorId == expectedConnectorId_3)).FirstOrDefault().Amps.ShouldBe(0.9m); }
public void Algo_should_return_multiple_single_options_with_min_current() { //Arrange decimal capacity = 10; var chargeGroup = new ChargeGroup(Guid.Empty, "", capacity, null); var chargeStation = new ChargeStation(Guid.NewGuid(), "", chargeGroup); chargeGroup.AddChargeStation(chargeStation); var expectedConnectorId = 9; chargeStation.AddConnector(1, expectedConnectorId); chargeStation.AddConnector(1); chargeStation.AddConnector(2); chargeStation.AddConnector(2); chargeStation.AddConnector(3); var needToFree = 0.9m; //Act var result = new Algo().FindOptions(chargeGroup, needToFree); //Assert result.Count.ShouldBe(2); result[0].Count.ShouldBe(1); result[1].Count.ShouldBe(1); result.Find(c => c[0].ConnectorId == expectedConnectorId)[0].Amps.ShouldBe(1); result.Find(c => c[0].ConnectorId != expectedConnectorId)[0].Amps.ShouldBe(1); }
public void Algo_should_return_connector_with_min_current() { //Arrange decimal capacity = 10; var chargeGroup = new ChargeGroup(Guid.Empty, "", capacity, null); var chargeStation = new ChargeStation(Guid.NewGuid(), "", chargeGroup); chargeGroup.AddChargeStation(chargeStation); var expectedConnectorId = 9; chargeStation.AddConnector(1, expectedConnectorId); chargeStation.AddConnector(1.5m); chargeStation.AddConnector(2); chargeStation.AddConnector(2); chargeStation.AddConnector(3); var needToFree = 1.0m; //Act var result = new Algo().FindOptions(chargeGroup, needToFree); //Assert result.Count.ShouldBe(1); result.FirstOrDefault().Count.ShouldBe(1); result.FirstOrDefault().FirstOrDefault().ConnectorId.ShouldBe(expectedConnectorId); result.FirstOrDefault().FirstOrDefault().Amps.ShouldBe(1); result.FirstOrDefault().FirstOrDefault().StationId.ShouldBe(chargeStation.Id); }
public async Task UpdateConnectors_should_update_chargestation_connectors() { var stations = new ChargeStationRepository(_fixture.DbContext); var capacity = 10m; var name = "TestChargeStation"; var chargeStationId = Guid.NewGuid(); var chargeGroup = new ChargeGroup(Guid.Empty, "", capacity, null); var chargeStation = new ChargeStation(chargeStationId, name, chargeGroup); chargeGroup.AddChargeStation(chargeStation); //add await stations.AddAsync(chargeStation).ConfigureAwait(false); //get var stationFromDb = await stations.GetAsync(chargeStationId).ConfigureAwait(false); stationFromDb.Id.ShouldBe(chargeStationId); stationFromDb.Connectors.Count().ShouldBe(0); chargeStation.AddConnector(3.0m); await stations.UpdateConnectorsAsync(chargeStation).ConfigureAwait(false); stationFromDb = await stations.GetAsync(chargeStationId).ConfigureAwait(false); stationFromDb.Id.ShouldBe(chargeStationId); stationFromDb.Connectors.Count().ShouldBe(1); stationFromDb.Connectors.FirstOrDefault().MaxCurrentAmps.ShouldBe(3.0m); }
public void MaxCurrentAmps_should_sum_all_connectors() { //Arrange decimal groupCapacity = 10m; var chargeGroup = new ChargeGroup(Guid.Empty, "", groupCapacity, null); var chargeStation = new ChargeStation(Guid.NewGuid(), "", chargeGroup); chargeGroup.AddChargeStation(chargeStation); chargeStation.AddConnector(1.0m); chargeStation.AddConnector(0.2m); chargeStation.AddConnector(0.03m); //Act var expected = chargeStation.MaxCurrentAmps; //Assert expected.ShouldBe(1.23m); }
public void Connectors_number_can_not_be_grater_than_MAX_CONNECTORS() { //Arrange decimal groupCapacity = 10m; var chargeGroup = new ChargeGroup(Guid.Empty, "", groupCapacity, null); var chargeStation = new ChargeStation(Guid.NewGuid(), "", chargeGroup); chargeGroup.AddChargeStation(chargeStation); for (int i = 0; i < Const.MAX_CONNECTORS; i++) { chargeStation.AddConnector(1.0m); } //Act //Assert var ex = Assert.Throws <InvalidChargeStationConnectorsAmount>( () => chargeStation.AddConnector(0.3m)); }
public void AddConnector_should_return_suggestions_if_capacity_reserve_exceeded() { //Arrange decimal groupCapacity = 2.0m; var chargeGroup = new ChargeGroup(Guid.Empty, "", groupCapacity, null); var chargeStation = new ChargeStation(Guid.NewGuid(), "", chargeGroup); chargeGroup.AddChargeStation(chargeStation); chargeStation.AddConnector(1.0m); chargeStation.AddConnector(0.2m); //Act var result = chargeStation.AddConnector(1.0m); //Assert result.IsError.ShouldBeTrue(); result.Suggestions.ShouldNotBeNull(); result.Suggestions.ShouldNotBeEmpty(); result.Suggestions.FirstOrDefault().FirstOrDefault().Amps.ShouldBe(0.2m); }
public void CapacityReserve_should_sum_all_connectors_in_all_stations_in_group() { //Arrange decimal capacity = 10; var chargeGroup = new ChargeGroup(Guid.Empty, "", capacity, null); var chargeStation = new ChargeStation(Guid.NewGuid(), "", chargeGroup); chargeStation.AddConnector(1); chargeStation.AddConnector(2); var chargeStation2 = new ChargeStation(Guid.NewGuid(), "", chargeGroup); chargeStation2.AddConnector(3); chargeStation2.AddConnector(0.5m); chargeGroup.AddChargeStation(chargeStation); chargeGroup.AddChargeStation(chargeStation2); //Act var result = chargeGroup.CapacityReserve; //Assert result.ShouldBe(10 - (1 + 2 + 3 + 0.5m)); }
private Connector AddToChargeStation(ChargeStation chargeStation, AddConnectorCommand request) { var connector = new Connector { MaxCurrentInAmps = request.MaxCurrentInAmps }; chargeStation.AddConnector(connector); _dbContext.Connector.Add(connector); return(connector); }
public void Connector_id_can_not_be_grater_than_MAX_CONNECTOR_ID_VALUE() { //Arrange decimal groupCapacity = 10m; var chargeGroup = new ChargeGroup(Guid.Empty, "", groupCapacity, null); var chargeStation = new ChargeStation(Guid.NewGuid(), "", chargeGroup); chargeGroup.AddChargeStation(chargeStation); int connectorId = Const.MAX_CONNECTOR_ID_VALUE + 1; //Act //Assert var ex = Assert.Throws <InvalidConnectorId>( () => chargeStation.AddConnector(0.3m, connectorId)); }
public void Connector_id_should_be_initialised_implicitly() { //Arrange decimal groupCapacity = 10m; var chargeGroup = new ChargeGroup(Guid.Empty, "", groupCapacity, null); var chargeStation = new ChargeStation(Guid.NewGuid(), "", chargeGroup); chargeGroup.AddChargeStation(chargeStation); chargeStation.AddConnector(0.3m); //Act var connector = chargeStation.Connectors.FirstOrDefault(); //Assert connector.ShouldNotBeNull(); connector.Id.ShouldBe(1); connector.MaxCurrentAmps.ShouldBe(0.3m); connector.ParentChargeStationId.ShouldBe(chargeStation.Id); }
public void UpdateCapasity_should_return_suggestions_if_capacity_reduced_too_much() { //Arrange decimal capacity = 10; decimal newCapacity = 3; decimal connectorMaxCurrent = 5; var chargeGroup = new ChargeGroup(Guid.Empty, "", capacity, null); var chargeStation = new ChargeStation(Guid.NewGuid(), "", chargeGroup); chargeStation.AddConnector(connectorMaxCurrent); chargeGroup.AddChargeStation(chargeStation); //Act var result = chargeGroup.UpdateCapacity(newCapacity); //Assert result.IsError.ShouldBeTrue(); result.Suggestions.ShouldNotBeNull(); result.Suggestions.ShouldNotBeEmpty(); result.Suggestions.FirstOrDefault().FirstOrDefault().Amps.ShouldBe(connectorMaxCurrent); }