public ChargeGroup GetChargeGroupRecord(int recordID, string UserID) { try { ChargeGroup ChargeGroup = new ChargeGroup(); SqlParameter[] Parameters = { new SqlParameter("@SNo", Convert.ToInt32(recordID)), new SqlParameter("@UserID", Convert.ToInt32(UserID)) }; SqlDataReader dr = SqlHelper.ExecuteReader(ReadConnectionString.WebConfigConnectionString, CommandType.StoredProcedure, "GetRecordChargeGroup", Parameters); if (dr.Read()) { ChargeGroup.SNo = Convert.ToInt32(dr["SNo"]); ChargeGroup.GroupCode = dr["GroupCode"].ToString().ToUpper(); ChargeGroup.GroupName = dr["GroupName"].ToString().ToUpper(); ChargeGroup.IsActive = Convert.ToBoolean(dr["IsActive"]); ChargeGroup.Active = dr["ACTIVE"].ToString(); ChargeGroup.LedgerSno = dr["LedgerSno"].ToString(); ChargeGroup.Text_LedgerSno = dr["Ledger"].ToString(); ChargeGroup.UpdatedBy = dr["UpdatedUser"].ToString(); ChargeGroup.CreatedBy = dr["CreatedUser"].ToString(); } dr.Close(); return(ChargeGroup); } catch (Exception ex)//(Exception ex) { throw ex; } }
public async Task AsyncExtended_should_return_station_with_linked_properties() { var stations = new ChargeStationRepository(_fixture.DbContext); var groups = new ChargeGroupRepository(_fixture.DbContext); var capacity = 10m; var name = "TestChargeStation"; var stationId = Guid.NewGuid(); var groupId = Guid.NewGuid(); var chargeGroup = new ChargeGroup(groupId, "", capacity, null); var chargeStation = new ChargeStation(stationId, name, chargeGroup); chargeGroup.AddChargeStation(chargeStation); //add await groups.AddAsync(chargeGroup).ConfigureAwait(false); await stations.AddAsync(chargeStation).ConfigureAwait(false); var groupromDb = await groups.GetAsyncExtended(groupId).ConfigureAwait(false); groupromDb.Id.ShouldBe(groupId); groupromDb.ChargeStations.ShouldNotBeNull(); groupromDb.ChargeStations.First(s => s.Id == stationId).ShouldNotBeNull(); groupromDb.ChargeStations.First(s => s.Id == stationId).ParentChargeGroup.Id.ShouldBe(groupId); }
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 async Task Update_should_update_chargeGroup_properties() { var groups = new ChargeGroupRepository(_fixture.DbContext); var capacity = 10m; var name = "TestChargeGroup"; var chargeGroupId = Guid.NewGuid(); var chargeGroup = new ChargeGroup(chargeGroupId, name, capacity, null); //add await groups.AddAsync(chargeGroup).ConfigureAwait(false); var exists = await groups.ExistsAsync(chargeGroupId).ConfigureAwait(false); exists.ShouldBeTrue(); //get var groupFromDb = await groups.GetAsync(chargeGroupId).ConfigureAwait(false); groupFromDb.Id.ShouldBe(chargeGroupId); groupFromDb.Name.ShouldBe(name); groupFromDb.CapacityAmps.ShouldBe(capacity); capacity = 11m; name = "TestChargeGroup_new"; chargeGroup.Update(name, capacity); //update await groups.UpdateAsync(chargeGroup).ConfigureAwait(false); groupFromDb = await groups.GetAsync(chargeGroupId).ConfigureAwait(false); groupFromDb.Id.ShouldBe(chargeGroupId); groupFromDb.Name.ShouldBe(name); groupFromDb.CapacityAmps.ShouldBe(capacity); }
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_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 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 List <List <ConnectorToUnplug> > FindOptions(ChargeGroup chargeGroup, decimal needToFreeAmps) { GetInputData(chargeGroup); FindOptions(needToFreeAmps); decimal min = FindMin(); return(Results[min]); }
public static ChargeGroupDocument AsDocument(this ChargeGroup entity) => new ChargeGroupDocument { Id = entity.Id.ToString(), Name = entity.Name, CapacityAmps = entity.CapacityAmps, ChargeStations = entity.ChargeStations.Select(c => c.Id.ToString()) };
public async Task UpdateAsync(ChargeGroup chargeGroup) { await _chargeGroupsDocuments.FindOneAndUpdateAsync( Builders <ChargeGroupDocument> .Filter.Where(rec => rec.Id == chargeGroup.Id.ToString()), Builders <ChargeGroupDocument> .Update .Set(rec => rec.Name, chargeGroup.Name) .Set(rec => rec.CapacityAmps, chargeGroup.CapacityAmps) .Set(rec => rec.ChargeStations, chargeGroup.ChargeStations.Select(c => c.Id.ToString())) ).ConfigureAwait(false); }
public void chargeStations_should_be_not_null_by_default() { //Arrange decimal capacity = 10; //Act var chargeGroup = new ChargeGroup(Guid.Empty, "", capacity, null); //Assert chargeGroup.ChargeStations.ShouldNotBeNull(); }
public void ChargeGroupId_should_be_newGuid_by_default() { //Arrange decimal capacity = 10; //Act var chargeGroup = new ChargeGroup(Guid.Empty, "", capacity, null); //Assert chargeGroup.Id.ShouldNotBe(Guid.Empty); }
public async Task <AddChargeGroupDto> Handle(AddChargeGroupCommand command, CancellationToken cancellationToken) { if (await _repository.ExistsAsync(command.Id).ConfigureAwait(false)) { throw new ChargeGroupAlreadyExistException(command.Id); } var resource = ChargeGroup.Create(command.Id, command.Name, command.Capacity, new List <ChargeStation>()); await _repository.AddAsync(resource).ConfigureAwait(false); return(_mapper.Map <AddChargeGroupDto>(resource)); }
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 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 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 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); }
private void GetInputData(ChargeGroup chargeGroup) { SortedList <decimal, List <Connector> > Input = new SortedList <decimal, List <Connector> >(); foreach (var chargeStation in chargeGroup.ChargeStations) { foreach (var connector in chargeStation.Connectors) { Input.AddToList(connector); } } foreach (var kvp in Input) { foreach (var connector in kvp.Value) { SortedConnectors.Add(connector); } } }
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)); }
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); }
public async Task AddAsync_should_add_chargeStation() { 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.Name.ShouldBe(name); stationFromDb.ParentChargeGroup.ShouldBeNull(); }
public static ChargeStation AsEntityExtended(this ChargeStationDocument document, ChargeGroup chargeGroup) => new ChargeStation(new Guid(document.Id), document.Name, chargeGroup) { Connectors = document.Connectors.Select(c => new Connector(c.Id, c.MaxCurrentAmps, new Guid(c.ParentChargeStationId))) };
/// <summary> /// Add parsing of elements in mdmolecule: /// <list type="bullet"> /// <item>mdmolecule</item> /// <list type="bullet"> /// <item>chargeGroup</item> /// <list type="bullet"> /// <item>id</item> /// <item>cgNumber</item> /// <item>atomArray</item> /// <item>switchingAtom</item> /// </list> /// </list> /// <item>residue</item> /// <list type="bullet"> /// <item>id</item> /// <item>title</item> /// <item>resNumber</item> /// <item>atomArray</item> /// </list> /// </list> /// </summary> /// <param name="xpath"></param> /// <param name="element"></param> // @cdk.todo The JavaDoc of this class needs to be converted into HTML public override void StartElement(CMLStack xpath, XElement element) { // <molecule convention="md:mdMolecule" // xmlns="http://www.xml-cml.org/schema" // xmlns:md="http://www.bioclipse.org/mdmolecule"> // <atomArray> // <atom id="a1" elementType="C"/> // <atom id="a2" elementType="C"/> // </atomArray> // <molecule dictRef="md:chargeGroup" id="cg1"> // <scalar dictRef="md:cgNumber">5</scalar> // <atomArray> // <atom ref="a1"/> // <atom ref="a2"><scalar dictRef="md:switchingAtom"/></atom> // </atomArray> // </molecule> // <molecule dictRef="md:residue" id="r1" title="resName"> // <scalar dictRef="md:resNumber">3</scalar> // <atomArray> // <atom ref="a1"/> // <atom ref="a2"/> // </atomArray> // </molecule> // </molecule> // let the CMLCore convention deal with things first if (element.Name == XName_CML_molecule) { // the copy the parsed content into a new MDMolecule if (element.Attribute(Attribute_convention) != null && string.Equals(element.Attribute(Attribute_convention).Value, "md:mdMolecule", StringComparison.Ordinal)) { base.StartElement(xpath, element); CurrentMolecule = new MDMolecule(CurrentMolecule); } else { DictRef = element.Attribute(Attribute_dictRef) != null?element.Attribute(Attribute_dictRef).Value : ""; //If residue or chargeGroup, set up a new one switch (DictRef) { case "md:chargeGroup": currentChargeGroup = new ChargeGroup(); break; case "md:residue": currentResidue = new Residue(); if (element.Attribute(Attribute_title) != null) { currentResidue.Name = element.Attribute(Attribute_title).Value; } break; } } } else //We have a scalar element. Now check who it belongs to if (element.Name == XName_CML_scalar) { DictRef = element.Attribute(Attribute_dictRef).Value; //Switching Atom switch (DictRef) { case "md:switchingAtom": //Set current atom as switching atom currentChargeGroup.SetSwitchingAtom(CurrentAtom); break; default: base.StartElement(xpath, element); break; } } else if (element.Name == XName_CML_atom) { if (currentChargeGroup != null) { string id = element.Attribute(Attribute_ref).Value; if (id != null) { // ok, an atom is referenced; look it up CurrentAtom = null; foreach (var nextAtom in CurrentMolecule.Atoms) { if (string.Equals(nextAtom.Id, id, StringComparison.Ordinal)) { CurrentAtom = nextAtom; } } if (CurrentAtom == null) { Trace.TraceError($"Could not found the referenced atom '{id}' for this charge group!"); } else { currentChargeGroup.Atoms.Add(CurrentAtom); } } } else if (currentResidue != null) { string id = element.Attribute(Attribute_ref).Value; if (id != null) { // ok, an atom is referenced; look it up IAtom referencedAtom = null; foreach (var nextAtom in CurrentMolecule.Atoms) { if (string.Equals(nextAtom.Id, id, StringComparison.Ordinal)) { referencedAtom = nextAtom; } } if (referencedAtom == null) { Trace.TraceError($"Could not found the referenced atom '{id}' for this residue!"); } else { currentResidue.Atoms.Add(referencedAtom); } } } else { // ok, fine, just add it to the currentMolecule base.StartElement(xpath, element); } } else { base.StartElement(xpath, element); } }
public ChargeGroupCreated(ChargeGroup chargeGroup) => ChargeGroup = chargeGroup;
public async Task AddAsync(ChargeGroup chargeGroup) { await _chargeGroupsDocuments.InsertOneAsync(chargeGroup.AsDocument()).ConfigureAwait(false); }
/// <summary> /// Finish up parsing of elements in mdmolecule. /// </summary> /// <param name="xpath"></param> /// <param name="element"></param> public override void EndElement(CMLStack xpath, XElement element) { if (element.Name.Equals(XName_CML_molecule)) { // add chargeGroup, and then delete them if (currentChargeGroup != null) { if (CurrentMolecule is MDMolecule) { ((MDMolecule)CurrentMolecule).AddChargeGroup(currentChargeGroup); } else { Trace.TraceError("Need to store a charge group, but the current molecule is not a MDMolecule!"); } currentChargeGroup = null; } else // add chargeGroup, and then delete them if (currentResidue != null) { if (CurrentMolecule is MDMolecule) { ((MDMolecule)CurrentMolecule).AddResidue(currentResidue); } else { Trace.TraceError("Need to store a residue group, but the current molecule is not a MDMolecule!"); } currentResidue = null; } else { base.EndElement(xpath, element); } } else if (element.Name == XName_CML_atomArray) { if (xpath.Count == 2 && xpath.EndsWith("molecule", "atomArray")) { StoreAtomData(); NewAtomData(); } else if (xpath.Count > 2 && xpath.EndsWith("cml", "molecule", "atomArray")) { StoreAtomData(); NewAtomData(); } } else if (element.Name == XName_CML_bondArray) { if (xpath.Count == 2 && xpath.EndsWith("molecule", "bondArray")) { StoreBondData(); NewBondData(); } else if (xpath.Count > 2 && xpath.EndsWith("cml", "molecule", "bondArray")) { StoreBondData(); NewBondData(); } } else if (element.Name == XName_CML_scalar) { //Residue number if (string.Equals("md:resNumber", DictRef, StringComparison.Ordinal)) { int myInt = int.Parse(element.Value, NumberFormatInfo.InvariantInfo); currentResidue.SetNumber(myInt); } //ChargeGroup number else if (string.Equals("md:cgNumber", DictRef, StringComparison.Ordinal)) { int myInt = int.Parse(element.Value, NumberFormatInfo.InvariantInfo); currentChargeGroup.SetNumber(myInt); } } else { base.EndElement(xpath, element); } }
public ChargeGroupUpdated(ChargeGroup chargeGroup) => ChargeGroup = chargeGroup;
public ChargeGroupDeleted(ChargeGroup chargeGroup) => ChargeGroup = chargeGroup;