コード例 #1
0
        public void GetParentTest()
        {
            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);

            Assert.AreEqual(template, synchronizer.GetParent(newItem));
            Assert.IsNull(synchronizer.GetParent(template));
        }
コード例 #2
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);
            }
        }
コード例 #3
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));
        }