Пример #1
0
        public void DataTypeDefinition_Assign_Data_Type_With_PreValues()
        {
            //System.Diagnostics.Debugger.Launch();

            //create datatype definition, assign data type
            var dtd = DataTypeDefinition.MakeNew(m_User, "TEST" + Guid.NewGuid().ToString("N"));
            Assert.IsTrue(dtd.Id > 0);
            Assert.IsInstanceOfType(dtd, typeof(DataTypeDefinition));
            IDataType dt = new TextFieldDataType();
            dt.DataTypeDefinitionId = dtd.Id; //need to set the data types data type definition id
            dtd.DataType = dt; //set our data type definition's data type to the text field... i know this is all too weird.
            
            Assert.AreEqual(dt.Id, dtd.DataType.Id);
            Assert.IsInstanceOfType(dtd.DataType, dt.GetType());
            Assert.AreEqual(dtd.Id, dt.DataTypeDefinitionId);

            //create the prevalues
            ((DefaultPrevalueEditor)dt.PrevalueEditor).Prevalue = "TEST" + Guid.NewGuid().ToString("N");
            dt.PrevalueEditor.Save();

            //verify that the prevalue is there
            Assert.AreEqual<int>(1, PreValues.GetPreValues(dtd.Id).Count);

            //now remove it
            dtd.delete();
            Assert.IsFalse(DataTypeDefinition.IsNode(dtd.Id));
        }
Пример #2
0
        public void DataTypeDefinition_Assign_Data_Type_To_Doc_Type_Then_Create_Doc_And_Set_Value()
        {
            //create datatype definition, assign data type
            var dtd = DataTypeDefinition.MakeNew(m_User, "TEST" + Guid.NewGuid().ToString("N"));
            Assert.IsTrue(dtd.Id > 0);
            Assert.IsInstanceOfType(dtd, typeof(DataTypeDefinition));
            IDataType dt = new TextFieldDataType();
            dtd.DataType = dt;
            Assert.AreEqual(dt.Id, dtd.DataType.Id);
            Assert.IsInstanceOfType(dtd.DataType, dt.GetType());

            //create new doc type
            var docType = DocumentType.MakeNew(m_User, "TEST" + Guid.NewGuid().ToString("N"));

            //create the property with this new data type definition
            var alias = "TEST" + Guid.NewGuid().ToString("N");
            docType.AddPropertyType(dtd, alias, alias);
            Assert.AreEqual<int>(1, docType.PropertyTypes.Count());

            //create a new doc with the new doc type
            var doc = Document.MakeNew("TEST" + Guid.NewGuid().ToString("N"), docType, m_User, -1);

            //set the value of the property
            var prop = doc.getProperty(alias);
            var propType = prop.PropertyType;
            Assert.IsNotNull(prop);
            var val = "TEST" + Guid.NewGuid().ToString("N");
            prop.Value = val;
            Assert.AreEqual(val, prop.Value);

            //ok, now that all of the data is setup, we'll just delete the data type definition.
            dtd.delete();

            //make sure the property value is gone, check with sql
            Assert.AreEqual<int>(0, Application.SqlHelper.ExecuteScalar<int>(
                "SELECT COUNT(id) FROM cmsPropertyData WHERE propertytypeid=@propTypeId",
                Application.SqlHelper.CreateParameter("@propTypeId", propType.Id)));

            //make sure the property type is gone
            var hasError = false;
            try
            {
                var confirmPropType = new PropertyType(propType.Id);
            }
            catch (ArgumentException)
            {
                hasError = true;
            }
            Assert.IsTrue(hasError);

            //make sure the dtd is gone
            Assert.IsFalse(DataTypeDefinition.IsNode(dtd.Id));

            //now cleanup the rest
            doc.delete(true);
            Assert.IsFalse(Document.IsNode(doc.Id));
            docType.delete();
            Assert.IsFalse(DocumentType.IsNode(docType.Id));
        }
Пример #3
0
 /// <summary>
 /// Returns a text field property of the document type specified. This will throw an exception if one is not found.
 /// </summary>
 /// <param name="dt"></param>
 /// <returns></returns>
 internal static Property GetTextFieldProperty(DocumentType dt, Document d)
 {
     TextFieldDataType txtField = new TextFieldDataType();
     var prop = dt.PropertyTypes
             .Where(x => x.DataTypeDefinition.DataType.Id == txtField.Id).First();
     return d.GenericProperties.Where(x => x.PropertyType.Id == prop.Id).First();
 }
Пример #4
0
        /// <summary>
        /// Returns a random docuemnt type that supports a text property
        /// </summary>
        /// <returns></returns>
        internal static int GetExistingDocTypeId()
        {
            System.Diagnostics.Debugger.Launch();

            var types = DocumentType.GetAllAsList();
            DocumentType found = null;
            var txtField = new TextFieldDataType();
            foreach (var d in types)
            {
                var prop = d.PropertyTypes.FirstOrDefault(x => x.DataTypeDefinition.DataType.Id == txtField.Id);
                if (prop != null)
                {
                    found = d;
                    break;
                }
            }
            if (found == null)
            {
                throw new MissingMemberException("No document type was found that contains a text field property");
            }
            return found.Id;
        }