public void NewItemNoGroupTest() { //Arrange TECScopeTemplates templates = new TECScopeTemplates(); TemplateSynchronizer <TECSubScope> synchronizer = new TemplateSynchronizer <TECSubScope>(copySubScope, item => { }, syncSubScope, templates); TECSubScope templateSS = new TECSubScope(); templateSS.Name = "Template SubScope"; //Act TECSubScope copySS = synchronizer.NewItem(templateSS); //Assert Assert.AreEqual(templateSS.Name, copySS.Name); Assert.AreNotEqual(templateSS.Guid, copySS.Guid); }
public void ChangeInstanceTest() { //Arrange TECScopeTemplates templates = new TECScopeTemplates(); TemplateSynchronizer <TECSubScope> synchronizer = new TemplateSynchronizer <TECSubScope>(copySubScope, item => { }, syncSubScope, templates); TECSubScope templateSS = new TECSubScope(); templateSS.Name = "Template SubScope"; TECSubScope copySS = synchronizer.NewItem(templateSS); //Act copySS.Description = "Test Description"; //Assert Assert.AreEqual(templateSS.Description, copySS.Description); }
public void LinkNewTest() { TemplateSynchronizer <TestObject> synchronizer = new TemplateSynchronizer <TestObject>(obj => new TestObject(), obj => { }, (sync, obj1, obj2, e) => { }, new TECScopeTemplates()); var template = new TestObject(); synchronizer.NewGroup(template); bool changed = false; synchronizer.TECChanged += arg => { changed = true; }; var existing = new TestObject(); synchronizer.LinkNew(template, existing); Assert.IsTrue(synchronizer.GetFullDictionary()[template].Contains(existing)); Assert.IsTrue(changed); }
public static void AddSyncronizerItems(TECTemplates templates) { TemplateSynchronizer <TECEquipment> equipSynchronizer = templates.EquipmentSynchronizer; TemplateSynchronizer <TECSubScope> ssSynchronizer = templates.SubScopeSynchronizer; TECSystem syncSys = new TECSystem(); syncSys.Name = "Sync System"; templates.Templates.SystemTemplates.Add(syncSys); TECEquipment syncEquip = new TECEquipment(); syncEquip.Name = "Sync Equip"; templates.Templates.EquipmentTemplates.Add(syncEquip); syncSys.Equipment.Add(equipSynchronizer.NewItem(syncEquip)); TECSubScope syncSubScope = new TECSubScope(); syncSubScope.Name = "Sync SS"; templates.Templates.SubScopeTemplates.Add(syncSubScope); syncEquip.SubScope.Add(ssSynchronizer.NewItem(syncSubScope)); }
public void TemplatedSubScopeRemovedFromReferenceEquipment() { //Arrange TECTemplates templates = new TECTemplates(); TemplateSynchronizer <TECEquipment> equipSynchronizer = templates.EquipmentSynchronizer; TemplateSynchronizer <TECSubScope> ssSynchronizer = templates.SubScopeSynchronizer; TECEquipment templateEquip = new TECEquipment(); templates.Templates.EquipmentTemplates.Add(templateEquip); TECSubScope templateSS = new TECSubScope(); templates.Templates.SubScopeTemplates.Add(templateSS); TECSystem system = new TECSystem(); templates.Templates.SystemTemplates.Add(system); TECEquipment refEquip = equipSynchronizer.NewItem(templateEquip); system.Equipment.Add(refEquip); TECSubScope refSS = ssSynchronizer.NewItem(templateSS); refEquip.SubScope.Add(refSS); //TECSubScope refSS = refEquip.SubScope[0]; //Act refEquip.SubScope.Remove(refSS); //Assert Assert.IsTrue(templateEquip.SubScope.Count == 0, "SubScope not removed properly from Equipment template."); Assert.IsFalse(ssSynchronizer.Contains(refSS), "Reference SubScope was not removed properly from synchronizer."); Assert.IsTrue(ssSynchronizer.Contains(templateSS), "Template SubScope was removed from synchronizer."); }
public TECTemplates(Guid guid) : base(guid) { Catalogs.ScopeChildRemoved += scopeChildRemoved; SubScopeSynchronizer = new TemplateSynchronizer <TECSubScope>((item => { return(new TECSubScope(item)); }), (item => { }), syncSubScope, this.Templates); SubScopeSynchronizer.TECChanged += synchronizerChanged; EquipmentSynchronizer = new TemplateSynchronizer <TECEquipment>( //Copy (item => { TECEquipment newItem = new TECEquipment(); newItem.CopyPropertiesFromScope(item); foreach (TECSubScope subScope in item.SubScope) { newItem.SubScope.Add(SubScopeSynchronizer.NewItem(subScope)); } return(newItem); }), //Remove (item => { foreach (TECSubScope subScope in item.SubScope) { if (SubScopeSynchronizer.GetTemplate(subScope) != null) { SubScopeSynchronizer.RemoveItem(subScope); } } }), //Sync syncEquipment, this.Templates); EquipmentSynchronizer.TECChanged += synchronizerChanged; }
public void ReferenceEquipmentRemoved() { //Arrange TECTemplates templates = new TECTemplates(); TemplateSynchronizer <TECEquipment> synchronizer = templates.EquipmentSynchronizer; TECEquipment templateEquip = new TECEquipment(); templates.Templates.EquipmentTemplates.Add(templateEquip); TECSystem templateSys = new TECSystem(); templates.Templates.SystemTemplates.Add(templateSys); TECEquipment refEquip = synchronizer.NewItem(templateEquip); templateSys.Equipment.Add(refEquip); //Act templateSys.Equipment.Remove(refEquip); //Assert Assert.IsFalse(synchronizer.Contains(refEquip)); Assert.IsTrue(synchronizer.Contains(templateEquip)); }
public void ReferenceSubScopeRemoved() { //Arrange TECTemplates templates = new TECTemplates(); TemplateSynchronizer <TECSubScope> synchronizer = templates.SubScopeSynchronizer; TECSubScope templateSS = new TECSubScope(); templates.Templates.SubScopeTemplates.Add(templateSS); TECEquipment templateEquip = new TECEquipment(); templates.Templates.EquipmentTemplates.Add(templateEquip); TECSubScope refSS = synchronizer.NewItem(templateSS); templateEquip.SubScope.Add(refSS); //Act templateEquip.SubScope.Remove(refSS); //Assert Assert.IsFalse(synchronizer.Contains(refSS)); Assert.IsTrue(synchronizer.Contains(templateSS)); }
public void Load_Templates_CombinedSynchronizer() { Guid parentSystemGuid = new Guid("d562049c-ea9e-449c-8c1f-eaa7fbcb70d3"); Guid equipmentTemplateGuid = new Guid("adced9c6-41c1-478b-b9db-3833f1618378"); Guid equipmentReferenceGuid = new Guid("53d8c07f-872c-41de-8dd1-8aa349978ef4"); Guid subScopeTemplateGuid = new Guid("59d6adb3-7f48-4448-82fa-f77cdfac47ad"); Guid subScopeChildTemplateGuid = new Guid("a26ab8aa-3b44-4321-a48e-872b250490a9"); Guid subScopeChildReferenceGuid = new Guid("c96120a1-b9e7-40e8-b015-e7383feca57d"); TECSystem actualSystem = null; foreach (TECSystem system in actualTemplates.Templates.SystemTemplates) { if (system.Guid == parentSystemGuid) { actualSystem = system; break; } } Assert.IsNotNull(actualSystem, "Parent system not found."); TECEquipment actualTemplateEquip = null; foreach (TECEquipment equip in actualTemplates.Templates.EquipmentTemplates) { if (equip.Guid == equipmentTemplateGuid) { actualTemplateEquip = equip; break; } } Assert.IsNotNull(actualTemplateEquip, "Equipment template not found."); TECEquipment actualRefEquip = null; foreach (TECEquipment equip in actualSystem.Equipment) { if (equip.Guid == equipmentReferenceGuid) { actualRefEquip = equip; break; } } Assert.IsNotNull(actualRefEquip, "Equipment reference not found."); TECSubScope actualTemplateSS = null; foreach (TECSubScope ss in actualTemplates.Templates.SubScopeTemplates) { if (ss.Guid == subScopeTemplateGuid) { actualTemplateSS = ss; break; } } Assert.IsNotNull(actualTemplateSS, "SubScope template not found."); TECSubScope actualChildTemplateSS = null; foreach (TECSubScope ss in actualTemplateEquip.SubScope) { if (ss.Guid == subScopeChildTemplateGuid) { actualChildTemplateSS = ss; break; } } Assert.IsNotNull(actualChildTemplateSS, "Child subScope in template equipment not found."); TECSubScope actualChildRefSS = null; foreach (TECSubScope ss in actualRefEquip.SubScope) { if (ss.Guid == subScopeChildReferenceGuid) { actualChildRefSS = ss; break; } } Assert.IsNotNull(actualChildRefSS, "Child subScope in reference equipment not found."); TemplateSynchronizer <TECSubScope> ssSync = actualTemplates.SubScopeSynchronizer; TemplateSynchronizer <TECEquipment> equipSync = actualTemplates.EquipmentSynchronizer; Assert.IsTrue(equipSync.Contains(actualTemplateEquip), "Equipment template not in synchronizer."); Assert.IsTrue(equipSync.Contains(actualRefEquip), "Equipment reference not in synchronizer."); Assert.IsTrue(equipSync.GetFullDictionary()[actualTemplateEquip].Contains(actualRefEquip), "Equipment template not synchronized with equipment reference."); Assert.IsTrue(ssSync.Contains(actualTemplateSS), "SubScope template not in synchroninzer."); Assert.IsTrue(ssSync.Contains(actualChildTemplateSS), "SubScope reference not in synchronizer."); Assert.IsTrue(ssSync.Contains(actualChildRefSS), "Child SubScope reference not in synchronizer."); Assert.IsTrue(ssSync.GetFullDictionary()[actualTemplateSS].Contains(actualChildTemplateSS), "SubScope template not synchronized with subScope reference."); Assert.IsTrue(ssSync.GetFullDictionary()[actualChildTemplateSS].Contains(actualChildRefSS), "Child subScope template not synchronized with child subScope reference."); }
public static TECTemplates CreateTestTemplates() { TECTemplates templates = new TECTemplates(); //Labor //templates.Labor = CreateTestLabor(); templates.Parameters.Add(CreateTestParameters(Guid.NewGuid())); templates.Catalogs = CreateTestCatalogs(); //Tags TECTag testTag = new TECTag(); testTag.Label = "Test Tag"; TECTag sysTag = new TECTag(); sysTag.Label = "System Tag"; TECTag equipTag = new TECTag(); equipTag.Label = "Equipment Tag"; TECTag ssTag = new TECTag(); ssTag.Label = "SubScope Tag"; TECTag devTag = new TECTag(); devTag.Label = "Device Tag"; templates.Catalogs.Tags.Add(testTag); templates.Catalogs.Tags.Add(sysTag); templates.Catalogs.Tags.Add(equipTag); templates.Catalogs.Tags.Add(ssTag); templates.Catalogs.Tags.Add(devTag); //Manufacturers TECManufacturer testMan = new TECManufacturer(); testMan.Label = "Test Manufacturer"; testMan.Multiplier = 0.654; TECManufacturer testDevMan = new TECManufacturer(); testDevMan.Label = "Child Manufacturer (Test Device)"; testDevMan.Multiplier = 0.446; TECManufacturer childDevMan = new TECManufacturer(); childDevMan.Label = "Child Manufacturer (Child Device)"; childDevMan.Multiplier = 0.916; templates.Catalogs.Manufacturers.Add(testMan); templates.Catalogs.Manufacturers.Add(testDevMan); templates.Catalogs.Manufacturers.Add(childDevMan); //Connection Types TECConnectionType testDevConnType = new TECConnectionType(); testDevConnType.Name = "FourC18"; TECConnectionType childDevConnType = new TECConnectionType(); childDevConnType.Name = "ThreeC18"; templates.Catalogs.ConnectionTypes.Add(testDevConnType); templates.Catalogs.ConnectionTypes.Add(childDevConnType); //Conduit Types TECElectricalMaterial testConduitType = new TECElectricalMaterial(); testConduitType.Name = "EMT"; testConduitType.Cost = 12; testConduitType.Labor = 2; templates.Catalogs.ConduitTypes.Add(testConduitType); TECElectricalMaterial otherConduitType = new TECElectricalMaterial(); otherConduitType.Name = "RGS"; otherConduitType.Cost = 18; otherConduitType.Labor = 4; templates.Catalogs.ConduitTypes.Add(otherConduitType); //Associated Costs TECAssociatedCost testAssociatedCost = new TECAssociatedCost(CostType.Electrical); testAssociatedCost.Name = "Flex"; testAssociatedCost.Cost = 42; templates.Catalogs.AssociatedCosts.Add(testAssociatedCost); var testCost2 = new TECAssociatedCost(CostType.TEC); testCost2.Name = "Other Cost"; templates.Catalogs.AssociatedCosts.Add(testCost2); //IO Modules TECIOModule testIOModule = new TECIOModule(testMan); testIOModule.Name = "Test IO Module"; testIOModule.Price = 42; testIOModule.Manufacturer = testMan; templates.Catalogs.IOModules.Add(testIOModule); //Devices ObservableCollection <TECConnectionType> contypes2 = new ObservableCollection <TECConnectionType>(); contypes2.Add(testDevConnType); TECDevice testDev = new TECDevice(Guid.NewGuid(), contypes2, new List <TECProtocol>(), testDevMan); testDev.Name = "Test Device"; testDev.Description = "Device Description"; testDev.Price = 20.3; ObservableCollection <TECConnectionType> contypes3 = new ObservableCollection <TECConnectionType>(); contypes3.Add(childDevConnType); TECDevice childDev = new TECDevice(Guid.NewGuid(), contypes3, new List <TECProtocol>(), childDevMan); childDev.Name = "Child Device"; childDev.Description = "Child Device Description"; childDev.Price = 54.1; testDev.Tags.Add(devTag); childDev.Tags.Add(devTag); templates.Catalogs.Devices.Add(testDev); templates.Catalogs.Devices.Add(childDev); //System TECSystem system = new TECSystem(false); system.Name = "Test System"; system.Description = "System Description"; TECEquipment sysEquip = new TECEquipment(false); sysEquip.Name = "System Equipment"; sysEquip.Description = "Child Equipment"; TECSubScope sysSS = new TECSubScope(false); sysSS.Name = "System SubScope"; sysSS.Description = "Child SubScope"; sysSS.AssociatedCosts.Add(testAssociatedCost); TECPoint sysPoint = new TECPoint(false); sysPoint.Type = IOType.AI; sysPoint.Label = "System Point"; sysSS.Points.Add(sysPoint); sysSS.Devices.Add(childDev); sysSS.Tags.Add(ssTag); sysEquip.SubScope.Add(sysSS); sysEquip.Tags.Add(equipTag); system.Equipment.Add(sysEquip); system.Tags.Add(sysTag); templates.SystemTemplates.Add(system); //Equipment TECEquipment equipment = new TECEquipment(false); equipment.Name = "Test Equipment"; equipment.Description = "Equipment Description"; TECSubScope equipSS = new TECSubScope(false); equipSS.Name = "Equipment SubScope"; equipSS.Description = "Child SubScope"; TECPoint equipPoint = new TECPoint(false); equipPoint.Type = IOType.AI; equipPoint.Label = "Equipment Point"; equipSS.Points.Add(equipPoint); equipSS.Devices.Add(childDev); equipSS.Tags.Add(ssTag); equipment.SubScope.Add(equipSS); equipment.Tags.Add(equipTag); templates.EquipmentTemplates.Add(equipment); //SubScope TECSubScope subScope = new TECSubScope(false); subScope.Name = "Test SubScope"; subScope.Description = "SubScope Description"; TECPoint ssPoint = new TECPoint(false); ssPoint.Type = IOType.DO; ssPoint.Label = "SubScope Point"; subScope.Points.Add(ssPoint); subScope.Devices.Add(childDev); subScope.Tags.Add(ssTag); subScope.AssociatedCosts.Add(testAssociatedCost); templates.SubScopeTemplates.Add(subScope); //Controller var expectedControllerType = new TECControllerType(testMan); expectedControllerType.Price = 42.6; TECIO ioToAdd = new TECIO(IOType.AI); ioToAdd.Quantity = 5; TECIO otherIO = new TECIO(IOType.UI); otherIO.Quantity = 3; expectedControllerType.IO.Add(ioToAdd); expectedControllerType.IO.Add(otherIO); templates.Catalogs.ControllerTypes.Add(expectedControllerType); TECController expectedController = new TECProvidedController(expectedControllerType, false); expectedController.Name = "Test Controller"; expectedController.Description = "Test description"; TECController controlledController = new TECProvidedController(expectedControllerType, false); controlledController.Name = "Controlled Controller"; templates.ControllerTemplates.Add(expectedController); //Misc Cost TECMisc cost = new TECMisc(CostType.TEC, false); cost.Name = "Test Cost"; cost.Cost = 79.79; cost.Quantity = 67; templates.MiscCostTemplates.Add(cost); //Misc wiring TECMisc wiring = new TECMisc(CostType.Electrical, false); wiring.Name = "Test Wiring"; wiring.Cost = 69.69; wiring.Quantity = 69; templates.MiscCostTemplates.Add(wiring); //Panel Types TECPanelType panelType = new TECPanelType(testMan); panelType.Price = 123.4; panelType.Name = "Test Panel Type"; templates.Catalogs.PanelTypes.Add(panelType); //Panels TECPanel panel = new TECPanel(panelType, false); panel.Name = "Test Panel"; panel.AssociatedCosts.Add(testAssociatedCost); panel.AssociatedCosts.Add(testAssociatedCost); TECPanel controlledPanel = new TECPanel(panelType, false); controlledPanel.Name = "Controlled Panel"; templates.PanelTemplates.Add(panel); //Synchronizer TemplateSynchronizer <TECEquipment> equipSynchronizer = templates.EquipmentSynchronizer; TemplateSynchronizer <TECSubScope> ssSynchronizer = templates.SubScopeSynchronizer; TECSystem syncSys = new TECSystem(false); syncSys.Name = "Sync System"; templates.SystemTemplates.Add(syncSys); TECEquipment syncEquip = new TECEquipment(false); syncEquip.Name = "Sync Equip"; templates.EquipmentTemplates.Add(syncEquip); syncSys.Equipment.Add(equipSynchronizer.NewItem(syncEquip)); TECSubScope syncSubScope = new TECSubScope(false); syncSubScope.Name = "Sync SS"; templates.SubScopeTemplates.Add(syncSubScope); syncEquip.SubScope.Add(ssSynchronizer.NewItem(syncSubScope)); return(templates); }
private void syncEquipment(TemplateSynchronizer <TECEquipment> synchronizer, TECEquipment template, TECEquipment changed, TECChangedEventArgs args) { if (!(args.Sender is TECEquipment)) { return; } TECEquipment item = args.Sender as TECEquipment; TECSubScope value = args.Value as TECSubScope; List <TECEquipment> references = synchronizer.GetFullDictionary()[template]; if (value != null && args.Change == Change.Add) { TECSubScope newTemplate = value; if (item == template) { SubScopeSynchronizer.NewGroup(newTemplate); } else { TECSubScope parentTemplate = SubScopeSynchronizer.GetTemplate(newTemplate); if (parentTemplate != null) { SubScopeSynchronizer.RemoveItem(newTemplate); newTemplate = SubScopeSynchronizer.NewItem(parentTemplate); } else { newTemplate = new TECSubScope(value); } template.SubScope.Add(newTemplate); SubScopeSynchronizer.NewGroup(newTemplate); SubScopeSynchronizer.LinkExisting(newTemplate, value); } foreach (TECEquipment reference in references.Where(obj => obj != item)) { reference.SubScope.Add(SubScopeSynchronizer.NewItem(newTemplate)); } } else if (value != null && args.Change == Change.Remove) { TECSubScope subScopeTemplate = value; if (item != template) { subScopeTemplate = SubScopeSynchronizer.GetTemplate(value); } template.SubScope.Remove(subScopeTemplate); List <TECSubScope> subScopeReferences = SubScopeSynchronizer.GetFullDictionary()[subScopeTemplate]; foreach (TECEquipment reference in references) { List <TECSubScope> toRemove = new List <TECSubScope>(); foreach (TECSubScope referenceSubScope in reference.SubScope) { if (subScopeReferences.Contains(referenceSubScope)) { toRemove.Add(referenceSubScope); } } foreach (TECSubScope thing in toRemove) { reference.SubScope.Remove(thing); } } SubScopeSynchronizer.RemoveGroup(subScopeTemplate); if (SubScopeSynchronizer.GetTemplate(subScopeTemplate) != null) { SubScopeSynchronizer.RemoveItem(subScopeTemplate); } } else { if (item != template) { template.CopyChildrenFromScope(item); } foreach (TECEquipment reference in references.Where(obj => obj != item)) { reference.CopyChildrenFromScope(item); } } }
//Copy Constructor public TECEquipment(TECEquipment equipmentSource, Dictionary <Guid, Guid> guidDictionary = null, ObservableListDictionary <ITECObject> characteristicReference = null, TemplateSynchronizer <TECSubScope> ssSynchronizer = null) : this() { if (guidDictionary != null) { guidDictionary[_guid] = equipmentSource.Guid; } foreach (TECSubScope subScope in equipmentSource.SubScope) { var toAdd = new TECSubScope(subScope, guidDictionary, characteristicReference); if (ssSynchronizer != null && ssSynchronizer.Contains(subScope)) { ssSynchronizer.LinkNew(ssSynchronizer.GetTemplate(subScope), toAdd); } characteristicReference?.AddItem(subScope, toAdd); SubScope.Add(toAdd); } copyPropertiesFromScope(equipmentSource); }
public void SaveNew_Templates_Synchronizer() { //Arrange TECSystem expectedSys = null, actualSys = null; TECEquipment expectedTempEquip = null, actualTempEquip = null; TECEquipment expectedRefEquip = null, actualRefEquip = null; TECSubScope expectedTempSS = null, actualTempSS = null; TECSubScope expectedRefSSInTemp = null, actualRefSSInTemp = null; TECSubScope expectedRefSSInRef = null, actualRefSSInRef = null; #region Expected foreach (TECSystem sys in expectedTemplates.Templates.SystemTemplates) { if (sys.Name == "Sync System") { expectedSys = sys; break; } } Assert.IsNotNull(expectedSys); foreach (TECEquipment equip in expectedTemplates.Templates.EquipmentTemplates) { if (equip.Name == "Sync Equip") { expectedTempEquip = equip; break; } } Assert.IsNotNull(expectedTempEquip); foreach (TECEquipment equip in expectedSys.Equipment) { if (equip.Name == "Sync Equip") { expectedRefEquip = equip; break; } } Assert.IsNotNull(expectedRefEquip); foreach (TECSubScope ss in expectedTemplates.Templates.SubScopeTemplates) { if (ss.Name == "Sync SS") { expectedTempSS = ss; break; } } Assert.IsNotNull(expectedTempSS); foreach (TECSubScope ss in expectedTempEquip.SubScope) { if (ss.Name == "Sync SS") { expectedRefSSInTemp = ss; break; } } Assert.IsNotNull(expectedRefSSInTemp); foreach (TECSubScope ss in expectedRefEquip.SubScope) { if (ss.Name == "Sync SS") { expectedRefSSInRef = ss; break; } } Assert.IsNotNull(expectedRefSSInRef); #endregion #region Actual foreach (TECSystem sys in actualTemplates.Templates.SystemTemplates) { if (sys.Name == "Sync System" && sys.Guid == expectedSys.Guid) { actualSys = sys; break; } } Assert.IsNotNull(actualSys); foreach (TECEquipment equip in actualTemplates.Templates.EquipmentTemplates) { if (equip.Name == "Sync Equip" && equip.Guid == expectedTempEquip.Guid) { actualTempEquip = equip; break; } } Assert.IsNotNull(actualTempEquip); foreach (TECEquipment equip in actualSys.Equipment) { if (equip.Name == "Sync Equip" && equip.Guid == expectedRefEquip.Guid) { actualRefEquip = equip; break; } } Assert.IsNotNull(actualRefEquip); foreach (TECSubScope ss in actualTemplates.Templates.SubScopeTemplates) { if (ss.Name == "Sync SS" && ss.Guid == expectedTempSS.Guid) { actualTempSS = ss; break; } } Assert.IsNotNull(actualTempSS); foreach (TECSubScope ss in actualTempEquip.SubScope) { if (ss.Name == "Sync SS" && ss.Guid == expectedRefSSInTemp.Guid) { actualRefSSInTemp = ss; break; } } Assert.IsNotNull(actualRefSSInTemp); foreach (TECSubScope ss in actualRefEquip.SubScope) { if (ss.Name == "Sync SS" && ss.Guid == expectedRefSSInRef.Guid) { actualRefSSInRef = ss; break; } } Assert.IsNotNull(actualRefSSInRef); #endregion //Assert TemplateSynchronizer <TECEquipment> equipSync = actualTemplates.EquipmentSynchronizer; TemplateSynchronizer <TECSubScope> ssSync = actualTemplates.SubScopeSynchronizer; Assert.IsTrue(equipSync.Contains(actualTempEquip)); Assert.IsTrue(equipSync.Contains(actualRefEquip)); Assert.IsTrue(equipSync.GetFullDictionary()[actualTempEquip].Contains(actualRefEquip)); Assert.IsTrue(ssSync.Contains(actualTempSS)); Assert.IsTrue(ssSync.Contains(actualRefSSInTemp)); Assert.IsTrue(ssSync.Contains(actualRefSSInRef)); Assert.IsTrue(ssSync.GetFullDictionary()[actualTempSS].Contains(actualRefSSInTemp)); Assert.IsTrue(ssSync.GetFullDictionary()[actualRefSSInTemp].Contains(actualRefSSInRef)); }
public void EquipmentReferenceChanged() { //Arrange TECTemplates templates = new TECTemplates(); TECEquipment templateEquip = new TECEquipment(); templateEquip.Name = "Template Equip"; templates.Templates.EquipmentTemplates.Add(templateEquip); TemplateSynchronizer <TECEquipment> equipSynchronizer = templates.EquipmentSynchronizer; TECEquipment refEquip = equipSynchronizer.NewItem(templateEquip); TECSystem sys = new TECSystem(); templates.Templates.SystemTemplates.Add(sys); sys.Equipment.Add(refEquip); TECDevice dev = new TECDevice(new List <TECConnectionType>(), new List <TECProtocol>(), new TECManufacturer()); templates.Catalogs.Add(dev); TECPoint point = new TECPoint(); point.Label = "Test Point"; point.Type = IOType.AI; point.Quantity = 5; TECAssociatedCost cost = new TECAssociatedCost(CostType.TEC); templates.Catalogs.Add(cost); TECTag tag = new TECTag(); templates.Catalogs.Add(tag); TECSubScope ss = new TECSubScope(); ss.Description = "Test Description"; ss.Devices.Add(dev); ss.AddPoint(point); ss.AssociatedCosts.Add(cost); ss.Tags.Add(tag); templates.Templates.SubScopeTemplates.Add(ss); //Act refEquip.Description = "Test Description"; refEquip.SubScope.Add(ss); refEquip.AssociatedCosts.Add(cost); refEquip.Tags.Add(tag); //Assert //Assert.AreEqual(refEquip.Description, templateEquip.Description, "Description didn't sync properly between Equipment."); Assert.IsNotNull(templateEquip.SubScope[0], "SubScope didn't sync properly between Equipment."); TECSubScope templateSubScope = templateEquip.SubScope[0]; TECSubScope refSubScope = refEquip.SubScope[0]; //Assert.AreEqual(refSubScope.Description, templateSubScope.Description, "Description didn't sync properly between SubScope in Equipment."); Assert.AreEqual(refSubScope.Devices[0], templateSubScope.Devices[0], "Devices didn't sync properly between SubScope in Equipment."); Assert.AreEqual(refSubScope.Points[0].Label, templateSubScope.Points[0].Label, "Points didn't sync properly between SubScope in Equipment."); Assert.AreEqual(refSubScope.Points[0].Type, templateSubScope.Points[0].Type, "Points didn't sync properly between SubScope in Equipment."); Assert.AreEqual(refSubScope.Points[0].Quantity, templateSubScope.Points[0].Quantity, "Points didn't sync properly between SubScope in Equipment."); Assert.AreEqual(refSubScope.AssociatedCosts[0], templateSubScope.AssociatedCosts[0], "AssociatedCosts didn't sync properly between SubScope in Equipment."); Assert.AreEqual(refSubScope.Tags[0], templateSubScope.Tags[0], "Tags didn't sync properly between SubScope."); Assert.AreEqual(refEquip.AssociatedCosts[0], templateEquip.AssociatedCosts[0], "AssociatedCosts didn't sync properly between Equipment."); Assert.AreEqual(refEquip.Tags[0], templateEquip.Tags[0], "Tags didn't sync properly in Equipment."); }
public void CopyTemplateWithReferences() { //Arrange TECTemplates templates = new TECTemplates(); TemplateSynchronizer <TECEquipment> equipSync = templates.EquipmentSynchronizer; TemplateSynchronizer <TECSubScope> ssSync = templates.SubScopeSynchronizer; TECSystem templateSys = new TECSystem(); templates.Templates.SystemTemplates.Add(templateSys); TECEquipment templateEquip = new TECEquipment(); templateEquip.Name = "Template Equip"; templates.Templates.EquipmentTemplates.Add(templateEquip); templateSys.Equipment.Add(equipSync.NewItem(templateEquip)); TECSubScope templateSS = new TECSubScope(); templateSS.Name = "Template SS"; templates.Templates.SubScopeTemplates.Add(templateSS); templateEquip.SubScope.Add(ssSync.NewItem(templateSS)); TECSubScope equipSS = new TECSubScope(); equipSS.Name = "Equip SS"; templateEquip.SubScope.Add(equipSS); //Act TECSystem sysCopy = new TECSystem(templateSys, synchronizers: new Tuple <TemplateSynchronizer <TECEquipment>, TemplateSynchronizer <TECSubScope> >(equipSync, ssSync)); //Assert TECEquipment tempEquipCopy = sysCopy.Equipment[0]; TECSubScope tempSSCopy = null, equipSSCopy = null; foreach (TECSubScope ss in tempEquipCopy.SubScope) { if (ss.Name == "Template SS") { tempSSCopy = ss; } else if (ss.Name == "Equip SS") { equipSSCopy = ss; } else { Assert.Fail("Different subScope than expected in System copy."); } } Assert.IsNotNull(tempSSCopy, "Template SubScope didn't copy properly."); Assert.IsNotNull(equipSSCopy, "Equipment SubScope didn't copy properly."); Assert.IsTrue(equipSync.Contains(tempEquipCopy)); Assert.IsTrue(equipSync.GetFullDictionary()[templateEquip].Contains(tempEquipCopy)); Assert.IsTrue(ssSync.Contains(tempSSCopy)); Assert.IsTrue(ssSync.Contains(equipSSCopy)); Assert.IsTrue(ssSync.GetFullDictionary()[templateSS].Contains(ssSync.GetParent(tempSSCopy))); Assert.IsTrue(ssSync.GetFullDictionary()[equipSS].Contains(equipSSCopy)); }