/// <summary> /// Delete specified branch Resistance from database /// </summary> /// <param name="user">dto BranchResistance</param> public void DeleteBranchResistance(BranchResistanceDto dto) { try { //Before any action, it must be updated because calls from contract uses //only one instance of BranchManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.BranchResistances); //Find branch Resistance which have to be deleted. BranchResistance existingBranchResistance = dbContext.BranchResistances.Single(brRtc => brRtc.Id == dto.Id); //If required branch Resistance doesn't exists, throw exception. if (existingBranchResistance == null) { throw new Exception("Branch Resistance does not exist"); } //else perform delete from database else { //Delete branch. dbContext.DeleteObject(existingBranchResistance); //Saves chages. dbContext.SaveChanges(); } } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
/// <summary> /// Annull all values after server stop. /// </summary> /// <returns>String annulment info</returns> public String AnnullValues() { String annulmentInfo = null; //Annulment list of dto branch resistance which has been returned. List<BranchResistanceDto> listDto = new List<BranchResistanceDto>(); try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.BranchResistances); //list of branch resistances from entities List<BranchResistance> list = dbContext.BranchResistances.OrderBy(br => br.Id).ToList(); //filling the list foreach (BranchResistance br in list) { BranchResistanceDto branchResistanceDto = new BranchResistanceDto(br.Id, br.InitialBranchResistance, br.CurrentBranchResistance, br.MinimalBranchResistance, br.MaximalBranchResistance); branchResistanceDto.CurrentBranchResistance = 0; UpdateBranchResistance(branchResistanceDto); annulmentInfo = annulmentInfo + "\t- Current branch resistance at id: " + branchResistanceDto.Id + "\t-> Annulled.\r\n"; } } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } //returns String which shows annulment details return annulmentInfo; }
public void CurrentBranchResistanceTest() { BranchResistanceDto target = new BranchResistanceDto(); // TODO: Initialize to an appropriate value double expected = 0F; // TODO: Initialize to an appropriate value double actual; target.CurrentBranchResistance = expected; actual = target.CurrentBranchResistance; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void BranchResistanceDtoConstructorTest() { int id = 0; // TODO: Initialize to an appropriate value double initialBranchResistance = 0F; // TODO: Initialize to an appropriate value double currentBranchResistance = 0F; // TODO: Initialize to an appropriate value double minimalBranchResistance = 0F; // TODO: Initialize to an appropriate value double maximalBranchResistance = 0F; // TODO: Initialize to an appropriate value BranchResistanceDto target = new BranchResistanceDto(id, initialBranchResistance, currentBranchResistance, minimalBranchResistance, maximalBranchResistance); Assert.Inconclusive("TODO: Implement code to verify target"); }
public void IdTest() { BranchResistanceDto target = new BranchResistanceDto(); // TODO: Initialize to an appropriate value int expected = 0; // TODO: Initialize to an appropriate value int actual; target.Id = expected; actual = target.Id; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void BranchResistanceDtoConstructorTest1() { BranchResistanceDto target = new BranchResistanceDto(); Assert.Inconclusive("TODO: Implement code to verify target"); }
/// <summary> /// Update Branch Resistance in database /// </summary> /// <param name="dto">dto of Branch Resistance</param> public void UpdateBranchResistance(BranchResistanceDto dto) { try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.BranchResistances); //Find branch which have to be updated. BranchResistance existingBranchResistance = dbContext.BranchResistances.Single(brRtc => brRtc.Id == dto.Id); //If required branch Resistance doesn't exists, throw exception. if (existingBranchResistance == null) { throw new Exception("Branch Resistance does not exist"); } //else prepare all data for storing to database else { existingBranchResistance.Id = dto.Id; existingBranchResistance.InitialBranchResistance = dto.InitialBranchResistance; existingBranchResistance.CurrentBranchResistance = dto.CurrentBranchResistance; existingBranchResistance.MinimalBranchResistance = dto.MinimalBranchResistance; existingBranchResistance.MaximalBranchResistance = dto.MaximalBranchResistance; } //Save changes dbContext.SaveChanges(); } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
/// <summary> /// Insert specified branch Resistance in database /// </summary> /// <param name="dto">dto data for branch Resistance</param> public void InsertBranchResistance(BranchResistanceDto dto) { try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.BranchResistances); BranchResistance brRtc = new BranchResistance(); brRtc.Id = dto.Id; brRtc.InitialBranchResistance = dto.InitialBranchResistance; brRtc.CurrentBranchResistance = dto.CurrentBranchResistance; brRtc.MinimalBranchResistance = dto.MinimalBranchResistance; brRtc.MaximalBranchResistance = dto.MaximalBranchResistance; //Adds new branch Resistance details to context dbContext.BranchResistances.AddObject(brRtc); //saves changes. dbContext.SaveChanges(); } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
/// <summary> /// Returns list of all branch Resistances from database. /// </summary> /// <returns>List list of BranchResistanceDto's</returns> public List<BranchResistanceDto> GetAllBranchResistances() { //Instantiate list of dto branch Resistances which has been returned. List<BranchResistanceDto> listDto = new List<BranchResistanceDto>(); try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.BranchResistances); //list of branch Resistances from entities List<BranchResistance> list = dbContext.BranchResistances.OrderBy(brRtc => brRtc.Id).ToList(); //filling the list foreach (BranchResistance brRtc in list) { BranchResistanceDto branchResistanceDto = new BranchResistanceDto(brRtc.Id, brRtc.InitialBranchResistance, brRtc.CurrentBranchResistance, brRtc.MinimalBranchResistance, brRtc.MaximalBranchResistance); listDto.Add(branchResistanceDto); } } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } //returns list of all branch details as list of dtoes. return listDto; }