コード例 #1
0
        public void InstanceSubScopeRemovedFromReferenceEquipment()
        {
            //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 ss = new TECSubScope();

            templateEquip.SubScope.Add(ss);

            TECEquipment refEqiup = equipSynchronizer.NewItem(templateEquip);
            TECSubScope  refSS    = refEqiup.SubScope[0];

            //Act
            refEqiup.SubScope.Remove(refSS);

            //Assert
            Assert.IsTrue(templateEquip.SubScope.Count == 0, "SubScope not removed properly from Equipment template.");

            Assert.IsFalse(ssSynchronizer.Contains(ss), "SubScope was not removed properly from synchronizer.");
            Assert.IsFalse(ssSynchronizer.Contains(refSS), "Reference SubScope was not removed properly from synchronizer.");
        }
コード例 #2
0
        public void TemplateEquipmentRemoved()
        {
            //Arrange
            TECTemplates templates = new TECTemplates();
            TemplateSynchronizer <TECEquipment> synchronizer = templates.EquipmentSynchronizer;

            TECEquipment templateEquip = new TECEquipment();

            templateEquip.Name = "First Name";
            templates.Templates.EquipmentTemplates.Add(templateEquip);

            TECSystem templateSys = new TECSystem();

            templates.Templates.SystemTemplates.Add(templateSys);
            TECEquipment equip1 = synchronizer.NewItem(templateEquip);
            TECEquipment equip2 = synchronizer.NewItem(templateEquip);

            templateSys.Equipment.Add(equip1);
            templateSys.Equipment.Add(equip2);

            //Act
            templates.Templates.EquipmentTemplates.Remove(templateEquip);

            equip2.Name = "Second Name";

            //Assert
            Assert.IsFalse(synchronizer.Contains(templateEquip));
            Assert.IsFalse(synchronizer.Contains(equip1));
            Assert.IsFalse(synchronizer.Contains(equip2));
            Assert.AreEqual("First Name", equip1.Name);
            Assert.AreEqual("Second Name", equip2.Name);
        }
コード例 #3
0
        public void TemplatedSubScopeRemovedFromTemplateEquipment()
        {
            //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);

            TECSubScope instanceSS = ssSynchronizer.NewItem(templateSS);

            templateEquip.SubScope.Add(instanceSS);

            TECEquipment instanceEquip = equipSynchronizer.NewItem(templateEquip);

            templates.Templates.EquipmentTemplates.Add(instanceEquip);

            //Act
            templateEquip.SubScope.Remove(instanceSS);

            //Assert
            Assert.IsTrue(instanceEquip.SubScope.Count == 0, "SubScope not removed properly from equipment reference.");

            Assert.IsFalse(ssSynchronizer.Contains(instanceSS), "Reference SubScope not removed properly from synchronizer.");
            Assert.IsTrue(ssSynchronizer.Contains(templateSS), "Template SubScope was removed from synchronizer when it shouldn't have been.");
        }
コード例 #4
0
        public void TemplateSubScopeRemoved()
        {
            //Arrange
            TECTemplates templates = new TECTemplates();
            TemplateSynchronizer <TECSubScope> synchronizer = templates.SubScopeSynchronizer;

            TECSubScope templateSS = new TECSubScope();

            templateSS.Name = "First Name";
            templates.Templates.SubScopeTemplates.Add(templateSS);

            TECEquipment templateEquip = new TECEquipment();

            templates.Templates.EquipmentTemplates.Add(templateEquip);
            TECSubScope ss1 = synchronizer.NewItem(templateSS);
            TECSubScope ss2 = synchronizer.NewItem(templateSS);

            templateEquip.SubScope.Add(ss1);
            templateEquip.SubScope.Add(ss2);

            //Act
            templates.Templates.SubScopeTemplates.Remove(templateSS);

            ss2.Name = "Second Name";

            //Assert
            Assert.IsFalse(synchronizer.Contains(templateSS));
            Assert.IsFalse(synchronizer.Contains(ss1));
            Assert.IsFalse(synchronizer.Contains(ss2));
            Assert.AreEqual("First Name", ss1.Name);
            Assert.AreEqual("Second Name", ss2.Name);
        }
コード例 #5
0
        public void ContainsTest1()
        {
            TemplateSynchronizer <TestObject> synchronizer = new TemplateSynchronizer <TestObject>(obj => new TestObject(), obj => { }, (sync, obj1, obj2, e) => { }, new TECScopeTemplates());
            var template = new TestObject();

            synchronizer.NewGroup(template);

            var newItem = synchronizer.NewItem(template);

            synchronizer.RemoveItem(template, newItem);

            Assert.IsFalse(synchronizer.Contains(newItem));
        }
コード例 #6
0
        public void ContainsTest()
        {
            TemplateSynchronizer <TestObject> synchronizer = new TemplateSynchronizer <TestObject>(obj => new TestObject(), obj => { }, (sync, obj1, obj2, e) => { }, new TECScopeTemplates());
            var template = new TestObject();

            synchronizer.NewGroup(template);

            var existing = new TestObject();

            synchronizer.LinkExisting(template, existing);

            Assert.IsTrue(synchronizer.Contains(existing));
        }
コード例 #7
0
        public void CopyTemplateWithReferences()
        {
            //Arrange
            TECTemplates templates = new TECTemplates();

            TECEquipment tempEquip = new TECEquipment();

            templates.Templates.EquipmentTemplates.Add(tempEquip);

            TECSubScope tempSS = new TECSubScope();

            tempSS.Name = "Template SS";
            templates.Templates.SubScopeTemplates.Add(tempSS);
            tempEquip.SubScope.Add(templates.SubScopeSynchronizer.NewItem(tempSS));

            TECSubScope equipSS = new TECSubScope();

            equipSS.Name = "Equipment SS";
            tempEquip.SubScope.Add(equipSS);

            //Act
            TECEquipment equipCopy = new TECEquipment(tempEquip, ssSynchronizer: templates.SubScopeSynchronizer);

            //Assert
            TECSubScope newTempSS = null, newEquipSS = null;

            foreach (TECSubScope ss in equipCopy.SubScope)
            {
                if (ss.Name == "Template SS")
                {
                    newTempSS = ss;
                }
                else if (ss.Name == "Equipment SS")
                {
                    newEquipSS = ss;
                }
                else
                {
                    Assert.Fail("Different subScope than expected in equipment copy.");
                }
            }
            Assert.IsNotNull(newTempSS, "Template SubScope didn't copy properly.");
            Assert.IsNotNull(newEquipSS, "Equipment SubScope didn't copy properly.");

            TemplateSynchronizer <TECSubScope> ssSync = templates.SubScopeSynchronizer;

            Assert.IsTrue(ssSync.Contains(newTempSS));
            Assert.IsTrue(ssSync.GetFullDictionary()[tempSS].Contains(newTempSS));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
 //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);
 }
コード例 #11
0
        public bool IsTemplateObject(TECObject item)
        {
            if (item is TECSubScope subScope)
            {
                bool isTemplate = Templates.SubScopeTemplates.Contains(subScope);

                bool isTemplated = Templates.SubScopeTemplates.Contains(SubScopeSynchronizer.GetParent(subScope)) ||
                                   Templates.SubScopeTemplates.Contains(SubScopeSynchronizer.GetParent(SubScopeSynchronizer.GetParent(subScope)));
                return(isTemplate || isTemplated);
            }
            else if (item is TECEquipment equipment)
            {
                return(Templates.EquipmentTemplates.Contains(equipment) || EquipmentSynchronizer.Contains(equipment));
            }
            else if (item is TECController controller)
            {
                return(Templates.ControllerTemplates.Contains(controller));
            }
            else if (item is TECPanel panel)
            {
                return(Templates.PanelTemplates.Contains(panel));
            }
            else if (item is TECMisc misc)
            {
                return(Templates.MiscCostTemplates.Contains(misc));
            }
            else if (item is TECParameters parameters)
            {
                return(Templates.Parameters.Contains(parameters));
            }
            else if (item is TECSystem system)
            {
                return(Templates.SystemTemplates.Contains(system));
            }
            else
            {
                return(false);
            }
        }
コード例 #12
0
        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.");
        }
コード例 #13
0
        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));
        }
コード例 #14
0
        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));
        }