AddCustomField() public method

Add a user-defined custom field.
If 'fieldType' is a basic property type, then 'destinationClass' is ignored. If 'fieldType' is an object type (owning/reference and atomic/collection/sequence) property, then 'destinationClass' must match a class in the model.
/// Thrown if 'fieldType' is an object type (owning/reference and atomic/collection/sequence) property, /// but 'destinationClass' does not match a class in the model. /// /// Thrown if 'className' or 'fieldName' are null or empty. /// /// Thrown if class is not defined. ///
public AddCustomField ( string className, string fieldName, CellarPropertyType fieldType, int destinationClass ) : int
className string Class that gets the new custom field.
fieldName string Field name for the custom field.
fieldType CellarPropertyType Data type for the custom field.
destinationClass int Class Id for object type custom properties
return int
		public void AllInheritedCustomBasicDataPropertiesExistAfterDataMigration66()
		{
			var mockMdc = new MockMDCForDataMigration();
			mockMdc.AddClass(1, "CmObject", null, new List<string> { "CustomPropertyMagnet" });
			mockMdc.AddClass(2, "CustomPropertyMagnet", "CmObject", new List<string>());

			// These are all present in the original data file and act as controls.
			// They should not be changed.
			mockMdc.AddField(1001, "RegularOwningAtomic", CellarPropertyType.OwningAtom, 2);
			var extantExtantOwningAtomicFlid = mockMdc.AddCustomField("CmObject", "ExtantOwningAtomic", CellarPropertyType.OwningAtom, 2);
			var extantBoolFlid = mockMdc.AddCustomField("CmObject", "ExtantBooleanProperty", CellarPropertyType.Boolean, 0);
			var extantGenDateFlid = mockMdc.AddCustomField("CmObject", "ExtantGenDateProperty", CellarPropertyType.GenDate, 0);
			var extantGuidFlid = mockMdc.AddCustomField("CmObject", "ExtantGuidProperty", CellarPropertyType.Guid, 0);
			// Not used in model yet (as of 23 march 2013) var extantFloatFlid = mockMdc.AddCustomField("CmObject", "ExtantFloatProperty", CellarPropertyType.Float, 0);
			var extantIntegerFlid = mockMdc.AddCustomField("CmObject", "ExtantIntegerProperty", CellarPropertyType.Integer, 0);
			// Not used in model yet (as of 23 march 2013) var extantNumericFlid = mockMdc.AddCustomField("CmObject", "ExtantNumericProperty", CellarPropertyType.Numeric, 0);
			var extantTimeFlid = mockMdc.AddCustomField("CmObject", "ExtantTimeProperty", CellarPropertyType.Time, 0);

			// These are all missing in the original data file.
			// They should all end up with the default values for the given type of data.
			var missingBoolFlid = mockMdc.AddCustomField("CmObject", "NewBooleanProperty", CellarPropertyType.Boolean, 0);
			var missingGenDateFlid = mockMdc.AddCustomField("CmObject", "NewGenDateProperty", CellarPropertyType.GenDate, 0);
			var missingGuidFlid = mockMdc.AddCustomField("CmObject", "NewGuidProperty", CellarPropertyType.Guid, 0);
			// Not used in model yet (as of 23 march 2013) var missingFloatFlid = mockMdc.AddCustomField("CmObject", "NewFloatProperty", CellarPropertyType.Float, 0);
			var missingIntegerFlid = mockMdc.AddCustomField("CmObject", "NewIntegerProperty", CellarPropertyType.Integer, 0);
			// Not used in model yet (as of 23 march 2013) var missingNumericFlid = mockMdc.AddCustomField("CmObject", "NewNumericProperty", CellarPropertyType.Numeric, 0);
			var missingTimeFlid = mockMdc.AddCustomField("CmObject", "NewTimeProperty", CellarPropertyType.Time, 0);

			var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000066_CustomPropertyMagnet.xml");
			IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000065, dtos, mockMdc, null, FwDirectoryFinder.FdoDirectories);

			m_dataMigrationManager.PerformMigration(dtoRepos, 7000066, new DummyProgressDlg());

			var magnet = XElement.Parse(dtoRepos.AllInstancesSansSubclasses("CustomPropertyMagnet").First().Xml);

			// Check the 'control' props to make sure they were not changed.
			Assert.AreEqual("e268fe80-5d9d-4f6b-a68f-37db8218b15e", magnet.Element("RegularOwningAtomic").Element("objsur").Attribute("guid").Value);
			Assert.AreEqual("e268fe80-5d9d-4f6b-a68f-37db8218b15d", GetCustomPropertyElement(magnet, "ExtantOwningAtomic").Element("objsur").Attribute("guid").Value);
			Assert.AreEqual("True", GetCustomPropertyValue(magnet, "ExtantBooleanProperty"));
			Assert.AreEqual("-201303233", GetCustomPropertyValue(magnet, "ExtantGenDateProperty"));
			Assert.AreEqual("c1ee311b-e382-11de-8a39-0800200c9a66", GetCustomPropertyValue(magnet, "ExtantGuidProperty"));
			Assert.AreEqual("1", GetCustomPropertyValue(magnet, "ExtantIntegerProperty"));
			Assert.AreEqual("2006-3-12 18:19:46.87", GetCustomPropertyValue(magnet, "ExtantTimeProperty"));

			// Check the newly added props to make sure they are present and using default values.
			Assert.AreEqual("False", GetCustomPropertyValue(magnet, "NewBooleanProperty"));
			Assert.AreEqual("-000000000", GetCustomPropertyValue(magnet, "NewGenDateProperty"));
			Assert.AreEqual(Guid.Empty.ToString(), GetCustomPropertyValue(magnet, "NewGuidProperty"));
			Assert.AreEqual("0", GetCustomPropertyValue(magnet, "NewIntegerProperty"));
			Assert.IsNotNull(GetCustomPropertyValue(magnet, "NewTimeProperty"));
		}
        public void AllInheritedCustomBasicDataPropertiesExistAfterDataMigration66()
        {
            var mockMdc = new MockMDCForDataMigration();

            mockMdc.AddClass(1, "CmObject", null, new List <string> {
                "CustomPropertyMagnet"
            });
            mockMdc.AddClass(2, "CustomPropertyMagnet", "CmObject", new List <string>());

            // These are all present in the original data file and act as controls.
            // They should not be changed.
            mockMdc.AddField(1001, "RegularOwningAtomic", CellarPropertyType.OwningAtom, 2);
            var extantExtantOwningAtomicFlid = mockMdc.AddCustomField("CmObject", "ExtantOwningAtomic", CellarPropertyType.OwningAtom, 2);
            var extantBoolFlid    = mockMdc.AddCustomField("CmObject", "ExtantBooleanProperty", CellarPropertyType.Boolean, 0);
            var extantGenDateFlid = mockMdc.AddCustomField("CmObject", "ExtantGenDateProperty", CellarPropertyType.GenDate, 0);
            var extantGuidFlid    = mockMdc.AddCustomField("CmObject", "ExtantGuidProperty", CellarPropertyType.Guid, 0);
            // Not used in model yet (as of 23 march 2013) var extantFloatFlid = mockMdc.AddCustomField("CmObject", "ExtantFloatProperty", CellarPropertyType.Float, 0);
            var extantIntegerFlid = mockMdc.AddCustomField("CmObject", "ExtantIntegerProperty", CellarPropertyType.Integer, 0);
            // Not used in model yet (as of 23 march 2013) var extantNumericFlid = mockMdc.AddCustomField("CmObject", "ExtantNumericProperty", CellarPropertyType.Numeric, 0);
            var extantTimeFlid = mockMdc.AddCustomField("CmObject", "ExtantTimeProperty", CellarPropertyType.Time, 0);

            // These are all missing in the original data file.
            // They should all end up with the default values for the given type of data.
            var missingBoolFlid    = mockMdc.AddCustomField("CmObject", "NewBooleanProperty", CellarPropertyType.Boolean, 0);
            var missingGenDateFlid = mockMdc.AddCustomField("CmObject", "NewGenDateProperty", CellarPropertyType.GenDate, 0);
            var missingGuidFlid    = mockMdc.AddCustomField("CmObject", "NewGuidProperty", CellarPropertyType.Guid, 0);
            // Not used in model yet (as of 23 march 2013) var missingFloatFlid = mockMdc.AddCustomField("CmObject", "NewFloatProperty", CellarPropertyType.Float, 0);
            var missingIntegerFlid = mockMdc.AddCustomField("CmObject", "NewIntegerProperty", CellarPropertyType.Integer, 0);
            // Not used in model yet (as of 23 march 2013) var missingNumericFlid = mockMdc.AddCustomField("CmObject", "NewNumericProperty", CellarPropertyType.Numeric, 0);
            var missingTimeFlid = mockMdc.AddCustomField("CmObject", "NewTimeProperty", CellarPropertyType.Time, 0);

            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000066_CustomPropertyMagnet.xml");
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000065, dtos, mockMdc, null, FwDirectoryFinder.FdoDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000066, new DummyProgressDlg());

            var magnet = XElement.Parse(dtoRepos.AllInstancesSansSubclasses("CustomPropertyMagnet").First().Xml);

            // Check the 'control' props to make sure they were not changed.
            Assert.AreEqual("e268fe80-5d9d-4f6b-a68f-37db8218b15e", magnet.Element("RegularOwningAtomic").Element("objsur").Attribute("guid").Value);
            Assert.AreEqual("e268fe80-5d9d-4f6b-a68f-37db8218b15d", GetCustomPropertyElement(magnet, "ExtantOwningAtomic").Element("objsur").Attribute("guid").Value);
            Assert.AreEqual("True", GetCustomPropertyValue(magnet, "ExtantBooleanProperty"));
            Assert.AreEqual("-201303233", GetCustomPropertyValue(magnet, "ExtantGenDateProperty"));
            Assert.AreEqual("c1ee311b-e382-11de-8a39-0800200c9a66", GetCustomPropertyValue(magnet, "ExtantGuidProperty"));
            Assert.AreEqual("1", GetCustomPropertyValue(magnet, "ExtantIntegerProperty"));
            Assert.AreEqual("2006-3-12 18:19:46.87", GetCustomPropertyValue(magnet, "ExtantTimeProperty"));

            // Check the newly added props to make sure they are present and using default values.
            Assert.AreEqual("False", GetCustomPropertyValue(magnet, "NewBooleanProperty"));
            Assert.AreEqual("-000000000", GetCustomPropertyValue(magnet, "NewGenDateProperty"));
            Assert.AreEqual(Guid.Empty.ToString(), GetCustomPropertyValue(magnet, "NewGuidProperty"));
            Assert.AreEqual("0", GetCustomPropertyValue(magnet, "NewIntegerProperty"));
            Assert.IsNotNull(GetCustomPropertyValue(magnet, "NewTimeProperty"));
        }