/// <summary> /// Delete specified Node from database /// </summary> /// <param name="user">dto node</param> public void DeleteNode(NodeDto 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.Nodes); //Find node which have to be deleted. Node existingNode = dbContext.Nodes.Single(nd => nd.Id == dto.Id); //If required node doesn't exists, throw exception. if (existingNode == null) { throw new Exception("Node does not exist"); } //else perform delete from database else { //Delete node. dbContext.DeleteObject(existingNode); //Saves chages. dbContext.SaveChanges(); } } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
public void IdTest() { NodeDto target = new NodeDto(); // 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 NodeDtoConstructorTest() { int id = 0; // TODO: Initialize to an appropriate value string nodeName = string.Empty; // TODO: Initialize to an appropriate value int nodeTypeId = 0; // TODO: Initialize to an appropriate value int activeLoadId = 0; // TODO: Initialize to an appropriate value int reactiveLoadId = 0; // TODO: Initialize to an appropriate value int voltageId = 0; // TODO: Initialize to an appropriate value NodeDto target = new NodeDto(id, nodeName, nodeTypeId, activeLoadId, reactiveLoadId, voltageId); Assert.Inconclusive("TODO: Implement code to verify target"); }
/// <summary> /// Implementation of insert node contract. /// Inserts NodeDto into database. /// </summary> /// <param name="dto">NodeDto</param> public void InsertNode(NodeDto dto) { try { nodeManager.InsertNode(dto); } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Implementation of delete node contract. /// Delete NodeDto from database. /// </summary> /// <param name="dto">NodeDto</param> public void DeleteNode(NodeDto dto) { try { nodeManager.DeleteNode(dto); } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Returns list of all Nodes from database. /// </summary> /// <returns>List list of NodeDto's</returns> public List<NodeDto> GetAllNodes() { //Instantiate list of dto nodes which has been returned. List<NodeDto> listDto = new List<NodeDto>(); 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.Nodes); //list of nodes from entities List<Node> list = dbContext.Nodes.OrderBy(nd => nd.Id).ToList(); //filling the list foreach (Node nd in list) { NodeDto nodeDto = new NodeDto(nd.Id, nd.NodeName, nd.NodeTypeId, nd.ActiveLoadId, nd.ReactiveLoadId, nd.VoltageId); listDto.Add(nodeDto); } } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } //returns list of all node details as list of dtoes. return listDto; }
/// <summary> /// Update node in database /// </summary> /// <param name="dto">dto of node</param> public void UpdateNode(NodeDto 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.Nodes); //Find node which have to be updated. Node existingNode = dbContext.Nodes.Single(nd => nd.Id == dto.Id); //If required node doesn't exists, throw exception. if (existingNode == null) { throw new Exception("Node does not exist"); } //else prepare all data for storing to database else { existingNode.Id = dto.Id; existingNode.NodeName = dto.NodeName; existingNode.NodeTypeId = dto.NodeTypeId; existingNode.ActiveLoadId = dto.ActiveLoadId; existingNode.ReactiveLoadId = dto.ReactiveLoadId; existingNode.VoltageId = dto.VoltageId; } //Save changes dbContext.SaveChanges(); } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
/// <summary> /// Insert specified node in database /// </summary> /// <param name="dto">dto data for node</param> public void InsertNode(NodeDto 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.Nodes); Node nd = new Node(); nd.Id = dto.Id; nd.NodeName = dto.NodeName; nd.NodeTypeId = dto.NodeTypeId; nd.ActiveLoadId = dto.ActiveLoadId; nd.ReactiveLoadId = dto.ReactiveLoadId; nd.VoltageId = dto.VoltageId; //Adds new node details to context dbContext.Nodes.AddObject(nd); //saves changes. dbContext.SaveChanges(); } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
public void NodeDtoConstructorTest1() { NodeDto target = new NodeDto(); Assert.Inconclusive("TODO: Implement code to verify target"); }
public void NodeNameTest() { NodeDto target = new NodeDto(); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; target.NodeName = expected; actual = target.NodeName; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }