public void SaveAs_Bid_SubScopeConnection() { //Arrange TECController expectedConnectedController = null; TECHardwiredConnection expectedConnection = null; foreach (TECController controller in expectedBid.Controllers) { foreach (IControllerConnection connection in controller.ChildrenConnections) { if (connection is TECHardwiredConnection) { expectedConnectedController = controller; expectedConnection = connection as TECHardwiredConnection; break; } } if (expectedConnectedController != null) { break; } } TECController actualConnectedController = actualBid.FindChild(expectedConnectedController.Guid) as TECController; TECHardwiredConnection actualConnection = actualConnectedController.FindChild(expectedConnection.Guid) as TECHardwiredConnection; //Assert Assert.AreEqual(expectedConnection.Guid, actualConnection.Guid); Assert.AreEqual(expectedConnection.ConduitType.Guid, actualConnection.ConduitType.Guid); Assert.AreEqual(expectedConnection.Length, actualConnection.Length, DELTA); Assert.AreEqual(expectedConnection.ParentController.Guid, actualConnection.ParentController.Guid); Assert.AreEqual(expectedConnection.Child.Guid, actualConnection.Child.Guid); Assert.IsTrue(compareCosts(expectedConnection.CostBatch, actualConnection.CostBatch)); //Assert.IsFalse(actualConnection.IsTypical); }
public void DiconnectTest1() { TECConnectionType connectionType = new TECConnectionType(); TECDevice compatibleDevice = new TECDevice(new List <TECConnectionType> { connectionType }, new List <TECProtocol>(), new TECManufacturer()); TECSubScope subScope = new TECSubScope(); subScope.Devices.Add(compatibleDevice); TECPoint point = new TECPoint(); point.Type = IOType.AI; subScope.Points.Add(point); TECControllerType type = new TECControllerType(new TECManufacturer()); type.IO.Add(new TECIO(IOType.AI)); TECProvidedController controller = new TECProvidedController(type); TECHardwiredConnection connection = controller.Connect(subScope, subScope.AvailableProtocols.First(x => x is TECHardwiredProtocol)) as TECHardwiredConnection; controller.Disconnect(subScope); Assert.IsFalse(controller.ChildrenConnections.Contains(connection)); Assert.IsNull((subScope as IConnectable).GetParentConnection()); }
public void ConnectTest2() { TECConnectionType connectionType = new TECConnectionType(); TECDevice compatibleDevice = new TECDevice(new List <TECConnectionType> { connectionType }, new List <TECProtocol>(), new TECManufacturer()); TECSubScope subScope = new TECSubScope(); subScope.Devices.Add(compatibleDevice); TECPoint point = new TECPoint(); point.Type = IOType.AI; subScope.Points.Add(point); TECControllerType type = new TECControllerType(new TECManufacturer()); type.IO.Add(new TECIO(IOType.AI)); TECProvidedController controller = new TECProvidedController(type); TECHardwiredConnection connection = controller.Connect(subScope, subScope.HardwiredProtocol()) as TECHardwiredConnection; Assert.IsTrue(connection.Child == subScope); Assert.IsTrue(controller.ChildrenConnections.Contains(connection)); Assert.IsTrue((subScope as IConnectable).GetParentConnection() == connection); Assert.IsTrue(connection.Protocol is TECHardwiredProtocol); }
public void ConnectTest3() { TECConnectionType connectionType = new TECConnectionType(); TECDevice compatibleDevice = new TECDevice(new List <TECConnectionType> { connectionType }, new List <TECProtocol>(), new TECManufacturer()); TECSubScope subScope = new TECSubScope(); subScope.Devices.Add(compatibleDevice); TECPoint point = new TECPoint(); point.Type = IOType.AI; subScope.Points.Add(point); TECControllerType type = new TECControllerType(new TECManufacturer()); TECIOModule module = new TECIOModule(new TECManufacturer()); module.IO.Add(new TECIO(IOType.AO)); type.IOModules.Add(module); TECProvidedController controller = new TECProvidedController(type); TECHardwiredConnection connection = controller.Connect(subScope, subScope.HardwiredProtocol()) as TECHardwiredConnection; Assert.IsNull(connection); }
private static void linkSubScopeConnections(IEnumerable <TECController> controllers, IEnumerable <TECSubScope> subscope, Dictionary <Guid, Guid> guidDictionary = null) { foreach (TECSubScope subScope in subscope) { foreach (TECController controller in controllers) { List <TECHardwiredConnection> newConnections = new List <TECHardwiredConnection>(); List <TECHardwiredConnection> oldConnections = new List <TECHardwiredConnection>(); foreach (IControllerConnection connection in controller.ChildrenConnections) { if (connection is TECHardwiredConnection) { TECHardwiredConnection ssConnect = connection as TECHardwiredConnection; bool isCopy = (guidDictionary != null && guidDictionary[ssConnect.Child.Guid] == guidDictionary[subScope.Guid]); if (ssConnect.Child.Guid == subScope.Guid || isCopy) { TECHardwiredConnection linkedConnection = new TECHardwiredConnection(ssConnect, subScope, subScope.IsTypical || controller.IsTypical); newConnections.Add(linkedConnection); oldConnections.Add(ssConnect); } } } foreach (TECHardwiredConnection conn in oldConnections) { controller.ChildrenConnections.Remove(conn); } foreach (TECHardwiredConnection conn in newConnections) { controller.ChildrenConnections.Add(conn); } } } }
public void RemoveAllChildHardwiredConnectionsTest() { TECProtocol firstProtocol = new TECProtocol(new List <TECConnectionType>()); TECProtocol secondProtocol = new TECProtocol(new List <TECConnectionType>()); TECProtocol thirdProtocol = new TECProtocol(new List <TECConnectionType>()); TECProtocol fourthProtocol = new TECProtocol(new List <TECConnectionType>()); TECDevice compatibleDevice = new TECDevice(new List <TECConnectionType>(), new List <TECProtocol>() { secondProtocol, firstProtocol, fourthProtocol }, new TECManufacturer()); TECSubScope subScope = new TECSubScope(); subScope.Devices.Add(compatibleDevice); TECControllerType type = new TECControllerType(new TECManufacturer()); type.IO.Add(new TECIO(firstProtocol)); type.IO.Add(new TECIO(secondProtocol)); type.IO.Add(new TECIO(thirdProtocol)); TECProvidedController controller = new TECProvidedController(type); TECNetworkConnection connection = controller.Connect(subScope, firstProtocol) as TECNetworkConnection; TECDevice compatibleHardDevice = new TECDevice(new List <TECConnectionType>(), new List <TECProtocol>(), new TECManufacturer()); TECSubScope hardSubScope = new TECSubScope(); hardSubScope.Devices.Add(compatibleDevice); TECPoint point = new TECPoint(); point.Type = IOType.AI; hardSubScope.Points.Add(point); type.IO.Add(new TECIO(IOType.AI)); TECHardwiredConnection hardConnection = controller.Connect(hardSubScope, hardSubScope.HardwiredProtocol()) as TECHardwiredConnection; TECController parentController = new TECProvidedController(type); parentController.Connect(controller, secondProtocol); Assert.IsNotNull(controller.ParentConnection); controller.RemoveAllChildHardwiredConnections(); Assert.IsTrue(connection.Children.Contains(subScope)); Assert.IsTrue(controller.ChildrenConnections.Contains(connection)); Assert.AreEqual((subScope as IConnectable).GetParentConnection(), connection); Assert.IsFalse(controller.ChildrenConnections.Contains(hardConnection)); Assert.IsNull((hardSubScope as IConnectable).GetParentConnection()); Assert.IsNotNull(controller.ParentConnection); }
public void Load_Templates_TypicalSubScopeConnection() { Guid expectedGuid = new Guid("5723e279-ac5c-4ee0-ae01-494a0c524b5c"); double expectedWireLength = 40; double expectedConduitLength = 20; Guid expectedParentControllerGuid = new Guid("1bb86714-2512-4fdd-a80f-46969753d8a0"); Guid expectedConduitTypeGuid = new Guid("8d442906-efa2-49a0-ad21-f6b27852c9ef"); Guid expectedSubScopeGuid = new Guid("fbe0a143-e7cd-4580-a1c4-26eff0cd55a6"); TECHardwiredConnection actualSSConnect = null; foreach (TECSystem typical in actualTemplates.Templates.SystemTemplates) { foreach (TECController controller in typical.Controllers) { foreach (IControllerConnection connection in controller.ChildrenConnections) { if (connection.Guid == expectedGuid) { actualSSConnect = (connection as TECHardwiredConnection); break; } } if (actualSSConnect != null) { break; } } if (actualSSConnect != null) { break; } } //Assert Assert.AreEqual(expectedWireLength, actualSSConnect.Length, "Length didn't load properly in subscope connection."); Assert.AreEqual(expectedConduitLength, actualSSConnect.ConduitLength, "ConduitLength didn't load properly in subscope connection."); Assert.AreEqual(expectedParentControllerGuid, actualSSConnect.ParentController.Guid, "Parent controller didn't load properly in subscope connection."); Assert.AreEqual(expectedConduitTypeGuid, actualSSConnect.ConduitType.Guid, "Conduit type didn't load properly in subscope connection."); Assert.AreEqual(expectedSubScopeGuid, actualSSConnect.Child.Guid, "Subscope didn't load properly in subscope connection."); }
public void RemoveDeviceFromConnectedHardwired() { TECControllerType type = new TECControllerType(new TECManufacturer()); TECProvidedController controller = new TECProvidedController(type); TECConnectionType connectionType = new TECConnectionType(); TECDevice device = new TECDevice(new List <TECConnectionType> { connectionType }, new List <TECProtocol>(), new TECManufacturer()); TECSubScope subScope = new TECSubScope(); subScope.Devices.Add(device); TECHardwiredConnection connection = controller.Connect(subScope, subScope.HardwiredProtocol()) as TECHardwiredConnection; subScope.RemoveDevice(device); Assert.IsNull((subScope as IConnectable).GetParentConnection()); Assert.IsFalse(controller.ChildrenConnections.Contains(connection)); }