public void GetInstancesFromTypicalTest() { TECSubScope subScope = new TECSubScope(); TECEquipment equipment = new TECEquipment(); TECTypical typical = new TECTypical(); equipment.SubScope.Add(subScope); typical.Equipment.Add(equipment); typical.AddInstance(); typical.AddInstance(); Assert.AreEqual(2, typical.GetInstancesFromTypical(subScope).Count); Assert.AreEqual(2, typical.GetInstancesFromTypical(equipment).Count); }
public void RemoveInstanceWithGlobalConnectionToController() { TECBid bid = new TECBid(); bid.Catalogs = ModelCreation.TestCatalogs(rand); TECControllerType type = bid.Catalogs.ControllerTypes.RandomElement(rand); TECController controller = new TECProvidedController(type); bid.AddController(controller); TECTypical typical = new TECTypical(); TECController typicalController = new TECProvidedController(type); typical.AddController(typicalController); bid.Systems.Add(typical); TECSystem system = typical.AddInstance(); TECController instanceController = typical.GetInstancesFromTypical(typicalController).First(); Assert.IsTrue(controller.CanConnect(instanceController)); IControllerConnection connection = controller.Connect(instanceController, instanceController.AvailableProtocols.First()); Assert.IsTrue(connection is TECNetworkConnection); typical.Instances.Remove(system); Assert.IsTrue((connection as TECNetworkConnection).Children.Count == 0); }
public void RemoveTECCost() { //Arrange TECAssociatedCost cost = null; int x = 0; while (cost == null) { TECAssociatedCost randomCost = bid.Catalogs.AssociatedCosts[x]; if (randomCost.Type == CostType.TEC) { cost = randomCost; } x++; } TECTypical system = new TECTypical(); bid.Systems.Add(system); system.AddInstance(); system.AssociatedCosts.Add(cost); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); CostBatch initial = MatVMToCostBatch(matVM); //Act system.AssociatedCosts.Remove(cost); //Assert AssertMaterialVMMatchesCostBatch(matVM, initial - cost.CostBatch); }
public void AddValve() { //Arrange TECValve valve = ModelCreation.TestValve(bid.Catalogs, rand); valve.AssignRandomScopeProperties(bid.Catalogs, rand); TECTypical typical = new TECTypical(); bid.Systems.Add(typical); TECEquipment typEquip = new TECEquipment(); typical.Equipment.Add(typEquip); TECSubScope typSS = new TECSubScope(); typEquip.SubScope.Add(typSS); typical.AddInstance(); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); //Act typSS.Devices.Add(valve); //Assert AssertMaterialVMMatchesCostBatch(matVM, valve.CostBatch); }
public void RemoveDevice() { //Arrange TECTypical typical = new TECTypical(); bid.Systems.Add(typical); TECEquipment typEquip = new TECEquipment(); typical.Equipment.Add(typEquip); TECSubScope typSS = new TECSubScope(); typEquip.SubScope.Add(typSS); TECDevice device = bid.Catalogs.Devices[0]; device.AssignRandomScopeProperties(bid.Catalogs, rand); typSS.Devices.Add(device); typical.AddInstance(); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); CostBatch initial = MatVMToCostBatch(matVM); //Act typSS.Devices.Remove(device); //Assert AssertMaterialVMMatchesCostBatch(matVM, initial - device.CostBatch); }
public void RemoveValve() { //Arrange bid.Catalogs.Add(ModelCreation.TestValve(bid.Catalogs, rand)); ChangeWatcher cw = new ChangeWatcher(bid); TECTypical typical = new TECTypical(); bid.Systems.Add(typical); TECEquipment typEquip = new TECEquipment(); typical.Equipment.Add(typEquip); TECSubScope typSS = new TECSubScope(); typEquip.SubScope.Add(typSS); TECValve valve = bid.Catalogs.Valves[0]; valve.AssignRandomScopeProperties(bid.Catalogs, rand); typSS.Devices.Add(valve); typical.AddInstance(); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); CostBatch initial = MatVMToCostBatch(matVM); //Act typSS.Devices.Remove(valve); //Assert AssertMaterialVMMatchesCostBatch(matVM, initial - valve.CostBatch); }
public void AddRemoveSystemInstanceWithBidConnection() { var bid = new TECBid(); bid.Catalogs = ModelCreation.TestCatalogs(rand); var bidController = new TECProvidedController(bid.Catalogs.ControllerTypes.RandomElement(rand)); bid.AddController(bidController); var system = new TECTypical(); var equipment = new TECEquipment(); var subScope = new TECSubScope(); TECDevice dev = bid.Catalogs.Devices.First(x => x.HardwiredConnectionTypes.Count > 0); subScope.Devices.Add(dev); TECHardwiredProtocol hardProt = subScope.AvailableProtocols.First(x => x is TECHardwiredProtocol) as TECHardwiredProtocol; system.Equipment.Add(equipment); equipment.SubScope.Add(subScope); var instance = system.AddInstance(); var instanceSubScope = instance.GetAllSubScope().First(); bidController.Connect(instanceSubScope, hardProt); Assert.AreEqual(1, bidController.ChildrenConnections.Count, "Connection not added"); system.Instances.Remove(instance); Assert.AreEqual(0, bidController.ChildrenConnections.Count, "Connection not removed"); }
public void EditInstances() { TECBid bid = new TECBid(); int qty = 3; bid.Catalogs = ModelCreation.TestCatalogs(rand); TECTypical system = ModelCreation.TestTypical(bid.Catalogs, rand); bid.Systems.Add(system); for (int x = 0; x < qty; x++) { system.AddInstance(); } system.Equipment.Add(ModelCreation.TestEquipment(bid.Catalogs, rand)); system.AddController(ModelCreation.TestProvidedController(bid.Catalogs, rand)); system.Panels.Add(ModelCreation.TestPanel(bid.Catalogs, rand)); foreach (TECSystem instance in system.Instances) { Assert.AreEqual(system.Equipment.Count, instance.Equipment.Count); Assert.AreEqual(system.Controllers.Count, instance.Controllers.Count); Assert.AreEqual(system.Panels.Count, instance.Panels.Count); } }
public void RemoveSubScope() { //Arrange TECTypical typical = new TECTypical(); bid.Systems.Add(typical); TECEquipment typEquip = new TECEquipment(); typical.Equipment.Add(typEquip); TECSubScope subScope = ModelCreation.TestSubScope(bid.Catalogs, rand); subScope.AssignRandomScopeProperties(bid.Catalogs, rand); typEquip.SubScope.Add(subScope); typical.AddInstance(); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); CostBatch initial = MatVMToCostBatch(matVM); //Act typEquip.SubScope.Remove(subScope); //Assert AssertMaterialVMMatchesCostBatch(matVM, initial - subScope.CostBatch); }
public void AddElectricalCostToSystem() { //Arrange TECAssociatedCost cost = null; foreach (TECAssociatedCost assoc in bid.Catalogs.AssociatedCosts) { if (assoc.Type == CostType.Electrical) { cost = assoc; break; } } if (cost == null) { Assert.Fail("No electrical cost in catalogs."); } TECTypical typical = new TECTypical(); bid.Systems.Add(typical); TECSystem instance = typical.AddInstance(); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); //Act typical.AssociatedCosts.Add(cost); //Assert AssertMaterialVMMatchesCostBatch(matVM, cost.CostBatch); }
public void UpdateInstanceConnectionsTest() { Random rand = new Random(); TECCatalogs catalogs = ModelCreation.TestCatalogs(rand); TECTypical typical = ModelCreation.TestTypical(catalogs, rand); typical.AddInstance(); foreach (var controller in typical.Controllers) { foreach (var connection in controller.ChildrenConnections) { connection.Length = 324; } } typical.UpdateInstanceConnections(); foreach (var instance in typical.Instances) { foreach (var controller in instance.Controllers) { foreach (var connection in controller.ChildrenConnections) { Assert.AreEqual(324, connection.Length); } } } }
private void addExecute() { for (int x = 0; x < Quantity; x++) { if (parent is TECBid bid) { TECTypical typical = new TECTypical(toAdd, bid); bid.Systems.Add(typical); typical.AddInstance(); Added?.Invoke(typical); } else if (parent is TECTemplates) { TECSystem system = null; if (underlyingTemplate != null) { system = new TECSystem(underlyingTemplate, synchronizers: new Tuple <TemplateSynchronizer <TECEquipment>, TemplateSynchronizer <TECSubScope> >(templates.EquipmentSynchronizer, templates.SubScopeSynchronizer)); system.CopyPropertiesFromScope(ToAdd); } else { system = ToAdd; } parent.Templates.SystemTemplates.Add(system); Added?.Invoke(system); } } }
public void AddTECCostToSystem() { //Arrange TECAssociatedCost cost = null; int x = 0; while (cost == null) { TECAssociatedCost randomCost = bid.Catalogs.AssociatedCosts[x]; if (randomCost.Type == CostType.TEC) { cost = randomCost; } x++; } TECTypical typical = new TECTypical(); bid.Systems.Add(typical); typical.AddInstance(); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); //Act typical.AssociatedCosts.Add(cost); //Assert AssertMaterialVMMatchesCostBatch(matVM, cost.CostBatch); }
private void testNetworkExecute() { TECControllerType type = new TECControllerType(bid.Catalogs.Manufacturers[0]); type.Name = "Controller Type"; type.IO.Add(new TECIO(IOType.AI)); bid.Catalogs.Add(type); TECProvidedController controller = new TECProvidedController(type); controller.Name = "Test Server"; controller.Description = "For testing."; controller.IsServer = true; bid.AddController(controller); TECProvidedController child = new TECProvidedController(type); child.Name = "Child"; bid.AddController(child); TECProvidedController emptyController = new TECProvidedController(type); emptyController.Name = "EmptyController"; bid.AddController(emptyController); TECNetworkConnection connection = controller.AddNetworkConnection(bid.Catalogs.Protocols[0]); connection.AddChild(child); TECTypical typical = new TECTypical(); TECEquipment equip = new TECEquipment(); TECSubScope ss = new TECSubScope(); ss.Name = "Test Subscope"; ss.AddDevice(bid.Catalogs.Devices[0]); TECPoint point = new TECPoint(); point.Type = IOType.AI; point.Quantity = 1; ss.AddPoint(point); equip.SubScope.Add(ss); typical.Equipment.Add(equip); bid.Systems.Add(typical); typical.AddInstance(); }
public void RemoveInstanceWithGlobalConnectionToSubScope() { TECBid bid = new TECBid(); bid.Catalogs = ModelCreation.TestCatalogs(rand); TECController controller = ModelCreation.TestProvidedController(bid.Catalogs, rand); bid.AddController(controller); TECTypical typical = new TECTypical(); TECEquipment equipment = new TECEquipment(); TECSubScope subScope = new TECSubScope(); TECDevice device = null; foreach (TECDevice item in bid.Catalogs.Devices) { foreach (TECProtocol prot in item.PossibleProtocols) { if (controller.AvailableProtocols.Contains(prot)) { device = item; break; } } if (device != null) { break; } } if (device == null) { throw new NullReferenceException("Device is Null"); } subScope.Devices.Add(device); equipment.SubScope.Add(subScope); typical.Equipment.Add(equipment); bid.Systems.Add(typical); TECSystem system = typical.AddInstance(); TECSubScope instanceSubScope = typical.GetInstancesFromTypical(subScope).First(x => x.AvailableProtocols.Any(y => y is TECProtocol && controller.AvailableProtocols.Contains(y))); IControllerConnection connection = controller.Connect(instanceSubScope, instanceSubScope.AvailableProtocols.First(y => controller.AvailableProtocols.Contains(y))); Assert.IsTrue(connection is TECNetworkConnection); typical.Instances.Remove(system); Assert.IsTrue((connection as TECNetworkConnection).Children.Count == 0); }
public void AddInstanceTest() { Random rand = new Random(0); TECCatalogs catalogs = ModelCreation.TestCatalogs(rand); TECTypical typical = ModelCreation.TestTypical(catalogs, rand); TECSystem system = typical.AddInstance(); Assert.AreEqual(typical.Equipment.Count, system.Equipment.Count); Assert.AreEqual(typical.ScopeBranches.Count, system.ScopeBranches.Count); Assert.AreEqual(typical.ProposalItems.Count, system.ProposalItems.Count); Assert.AreEqual(typical.Controllers.Count, system.Controllers.Count); Assert.AreEqual(typical.Panels.Count, system.Panels.Count); Assert.AreEqual(typical.MiscCosts.Count, system.MiscCosts.Count); Assert.AreEqual(typical.Controllers.Aggregate(0, (total, next) => total += next.GetAll <TECConnection>().Count), system.GetAll <TECConnection>().Count); }
public void AddInstanceSystem() { //Arrange TECTypical typical = ModelCreation.TestTypical(bid.Catalogs, rand); typical.AssignRandomScopeProperties(bid.Catalogs, rand); bid.Systems.Add(typical); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); //Act TECSystem instance = typical.AddInstance(); //Assert AssertMaterialVMMatchesCostBatch(matVM, instance.CostBatch); }
public void AddConnection() { //Arrange TECControllerType controllerType = new TECControllerType(bid.Catalogs.Manufacturers[0]); bid.Catalogs.Add(controllerType); TECTypical typical = new TECTypical(); bid.Systems.Add(typical); TECController controller = new TECProvidedController(controllerType); typical.AddController(controller); TECEquipment typEquip = new TECEquipment(); typical.Equipment.Add(typEquip); TECSubScope typSS = new TECSubScope(); typEquip.SubScope.Add(typSS); ObservableCollection <TECConnectionType> connectionTypes = new ObservableCollection <TECConnectionType>(); connectionTypes.Add(bid.Catalogs.ConnectionTypes[0]); TECDevice dev = new TECDevice(connectionTypes, new List <TECProtocol>(), bid.Catalogs.Manufacturers[0]); bid.Catalogs.Add(dev); typSS.Devices.Add(dev); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); //Act IControllerConnection connection = controller.Connect(typSS, (typSS as IConnectable).AvailableProtocols.First()); connection.Length = 50; connection.ConduitLength = 50; connection.ConduitType = bid.Catalogs.ConduitTypes[0]; TECSystem instance = typical.AddInstance(); TECSubScope instanceSubScope = instance.GetAllSubScope()[0]; //Assert AssertMaterialVMMatchesCostBatch(matVM, connection.CostBatch); }
public void AddEquipmentToTypicalWithInstance() { TECBid bid = new TECBid(); TECTypical typical = new TECTypical(); bid.Systems.Add(typical); TECSystem instance = typical.AddInstance(); TECEquipment toAdd = new TECEquipment(); typical.Equipment.Add(toAdd); TECEquipment instanceEquipment = typical.TypicalInstanceDictionary.GetInstances(toAdd)[0] as TECEquipment; Assert.IsNotNull(instanceEquipment, "Not added to instance dictionary"); Assert.IsTrue(instance.Equipment.Contains(instanceEquipment)); }
public void AddElectricalMiscToSystem() { //Arrange TECMisc misc = ModelCreation.TestMisc(bid.Catalogs, rand, CostType.Electrical); TECTypical typical = new TECTypical(); bid.Systems.Add(typical); typical.AddInstance(); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); //Act typical.MiscCosts.Add(misc); //Assert AssertMaterialVMMatchesCostBatch(matVM, misc.CostBatch); }
public void SaveAs_Bid_System() { //Arrange TECBid bid = new TECBid(); bid.Catalogs = ModelCreation.TestCatalogs(rand, 5); TECTypical expectedSystem = ModelCreation.TestTypical(bid.Catalogs, rand); bid.Systems.Add(expectedSystem); expectedSystem.AddInstance(); path = Path.GetTempFileName(); //Act DatabaseManager <TECBid> manager = new DatabaseManager <TECBid>(path); manager.New(bid); TECBid loadedBid = manager.Load() as TECBid; TECTypical actualSystem = null; foreach (TECTypical system in loadedBid.Systems) { if (system.Guid == expectedSystem.Guid) { actualSystem = system; break; } } //Assert Assert.AreEqual(expectedSystem.Name, actualSystem.Name); Assert.AreEqual(expectedSystem.Description, actualSystem.Description); Assert.AreEqual(expectedSystem.Instances.Count, actualSystem.Instances.Count); Assert.AreEqual(expectedSystem.Equipment.Count, actualSystem.Equipment.Count); Assert.AreEqual(expectedSystem.Controllers.Count, actualSystem.Controllers.Count); Assert.AreEqual(expectedSystem.Panels.Count, actualSystem.Panels.Count); Assert.AreEqual(expectedSystem.ScopeBranches.Count, actualSystem.ScopeBranches.Count); Assert.AreEqual(expectedSystem.AssociatedCosts.Count, actualSystem.AssociatedCosts.Count); Assert.AreEqual(expectedSystem.MiscCosts.Count, actualSystem.MiscCosts.Count); Assert.AreEqual(expectedSystem.TypicalInstanceDictionary.GetFullDictionary().Count, actualSystem.TypicalInstanceDictionary.GetFullDictionary().Count); Assert.IsTrue(compareCosts(expectedSystem.CostBatch, actualSystem.CostBatch)); }
public void AddSubScopeConnectionToTypicalWithInstance() { TECBid bid = new TECBid(); TECTypical typical = new TECTypical(); TECEquipment equipment = new TECEquipment(); typical.Equipment.Add(equipment); bid.Systems.Add(typical); TECSystem instance = typical.AddInstance(); TECSubScope toAdd = new TECSubScope(); equipment.SubScope.Add(toAdd); TECEquipment instanceEquipment = typical.TypicalInstanceDictionary.GetInstances(equipment)[0] as TECEquipment; TECSubScope instanceSubScope = typical.TypicalInstanceDictionary.GetInstances(toAdd)[0] as TECSubScope; Assert.IsNotNull(instanceSubScope, "Not added to instance dictionary"); Assert.IsTrue(instanceEquipment.SubScope.Contains(instanceSubScope)); }
public void RemoveElectricalCost() { //Arrange TECAssociatedCost cost = bid.Catalogs.AssociatedCosts.First(x => x.Type == CostType.Electrical); TECTypical system = new TECTypical(); bid.Systems.Add(system); system.AddInstance(); system.AssociatedCosts.Add(cost); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); CostBatch initial = MatVMToCostBatch(matVM); //Act system.AssociatedCosts.Remove(cost); //Assert AssertMaterialVMMatchesCostBatch(matVM, initial - cost.CostBatch); }
public void AddEquipment() { //Arrange TECEquipment equipment = ModelCreation.TestEquipment(bid.Catalogs, rand); equipment.AssignRandomScopeProperties(bid.Catalogs, rand); TECTypical typical = new TECTypical(); bid.Systems.Add(typical); typical.AddInstance(); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); //Act typical.Equipment.Add(equipment); //Assert AssertMaterialVMMatchesCostBatch(matVM, equipment.CostBatch); }
public void RemoveConnection() { //Arrange TECController controller = new TECProvidedController(bid.Catalogs.ControllerTypes[0]); bid.AddController(controller); TECTypical typical = new TECTypical(); bid.Systems.Add(typical); TECEquipment typEquip = new TECEquipment(); typical.Equipment.Add(typEquip); TECSubScope ss = new TECSubScope(); ss.Devices.Add(bid.Catalogs.Devices[0]); typEquip.SubScope.Add(ss); TECSystem instance = typical.AddInstance(); TECSubScope instanceSubScope = instance.GetAllSubScope().First(sub => sub.AvailableProtocols.Any(prot => prot is TECHardwiredProtocol)); IConnection connection = controller.Connect(instanceSubScope, (instanceSubScope as IConnectable).AvailableProtocols.First(x => x is TECHardwiredProtocol)); connection.Length = 50; connection.ConduitLength = 50; connection.ConduitType = bid.Catalogs.ConduitTypes[0]; MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); CostBatch expected = MatVMToCostBatch(matVM) - connection.CostBatch; //Act controller.Disconnect(instanceSubScope); //Assert AssertMaterialVMMatchesCostBatch(matVM, expected); }
public void RemoveInstanceSystem() { //Arrange TECTypical typical = ModelCreation.TestTypical(bid.Catalogs, rand); bid.Systems.Add(typical); TECSystem instance = typical.AddInstance(); CostBatch instanceCost = instance.CostBatch; MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); CostBatch initial = MatVMToCostBatch(matVM); //Act typical.Instances.Remove(instance); //Assert AssertMaterialVMMatchesCostBatch(matVM, initial - instanceCost); }
public void CanUpdateInstanceConnectionsTest() { Random rand = new Random(); TECCatalogs catalogs = ModelCreation.TestCatalogs(rand); TECTypical typical = ModelCreation.TestTypical(catalogs, rand); typical.AddInstance(); foreach (var controller in typical.Controllers) { foreach (var connection in controller.ChildrenConnections) { connection.Length = 324; } } Assert.IsTrue(typical.CanUpdateInstanceConnections()); typical.Instances.Clear(); Assert.IsFalse(typical.CanUpdateInstanceConnections()); }
private void addExecute() { foreach (NameConatiner item in Names) { TECSystem newSystem = parent.AddInstance(); newSystem.Name = item.Name; if (item.Location != null) { newSystem.Location = item.Location; foreach (var equip in newSystem.Equipment) { equip.Location = item.Location; foreach (var subScope in equip.SubScope) { subScope.Location = item.Location; } } foreach (var controller in newSystem.Controllers) { controller.Location = item.Location; } foreach (var panel in newSystem.Panels) { panel.Location = item.Location; } } if (LabelInstances) { foreach (TECController controller in newSystem.Controllers) { controller.Name += String.Format(" ({0})", item.Name); } foreach (TECPanel panel in newSystem.Panels) { panel.Name += String.Format(" ({0})", item.Name); } } } }
public void IsDirectDescendantTest() { //Arrange TECBid bid = ModelCreation.TestBid(rand); TECTypical typical = ModelCreation.TestTypical(bid.Catalogs, rand); TECSubScope newSS = ModelCreation.TestSubScope(bid.Catalogs, rand); //Act typical.AddInstance(); TECSystem sys = typical.Instances[0]; TECEquipment equip = sys.Equipment[0]; TECSubScope ss = equip.SubScope[0]; //Assert Assert.IsFalse(typical.IsDirectDescendant(newSS)); Assert.IsTrue(typical.IsDirectDescendant(sys)); Assert.IsTrue(typical.IsDirectDescendant(equip)); Assert.IsTrue(typical.IsDirectDescendant(ss)); }
public void RemoveControllerFromTypicalWithInstanceConnections() { TECBid bid = new TECBid(); bid.Catalogs = ModelCreation.TestCatalogs(rand); TECTypical system = ModelCreation.TestTypical(bid.Catalogs, rand); TECController controller = system.Controllers[0]; TECEquipment equipment = system.Equipment[0]; TECSubScope subScope = new TECSubScope(); subScope.Devices.Add(bid.Catalogs.Devices.First()); equipment.SubScope.Add(subScope); controller.Connect(subScope, subScope.AvailableProtocols.First()); bid.Systems.Add(system); TECSystem instance = system.AddInstance(); TECController instanceController = system.TypicalInstanceDictionary.GetInstances(controller)[0] as TECController; TECSubScope instanceSubScope = system.TypicalInstanceDictionary.GetInstances(subScope)[0] as TECSubScope; system.RemoveController(controller); Assert.IsFalse(instance.Controllers.Contains(instanceController)); Assert.IsTrue(instanceSubScope.Connection == null); }