コード例 #1
0
        public void TestLoadProperties_EmptyDocument( )
        {
            DocxProperties props = new DocxProperties( testEmptyDocx );

            Field[ ] contentTypes = props.DocumentManagementProperties;
            Assert.IsNotNull( contentTypes );
            Assert.AreEqual( 0, contentTypes.Length );
        }
コード例 #2
0
        public void TestCopy_DontDupliateProperties( )
        {
            // the destination file has the properties in it already, let's make sure they don't get duplicated
            System.IO.File.Copy( docxWithProps, testDestFile, true );

            ContentTypeCopier.Copy( testSourceFile, testDestFile );

            DocxProperties sourceProps = new DocxProperties( testSourceFile );
            DocxProperties destProps = new DocxProperties( testDestFile );

            Assert.AreEqual( sourceProps.DocumentManagementProperties, destProps.DocumentManagementProperties );
        }
コード例 #3
0
        public void TestLoadProperties_CustomFileProperties( )
        {
            DocxProperties props = new DocxProperties( testSourceFile );

            Field[ ] customFileProps = props.CustomFileProperties;
            Assert.IsNotNull( customFileProps );
            Assert.AreEqual( 8, customFileProps.Length );

            Field docProp = props.FindProperty( "ContentType", props.customFileProperties );
            Assert.IsNotNull( docProp );
            Assert.AreEqual( "DevDocument", docProp.Value );

            docProp = props.FindProperty( "ContentTypeId", props.customFileProperties );
            Assert.IsNotNull( docProp );
            Assert.AreEqual( "0x010100D30FF0BF8E1580448375D6E711A61115006CA08441E381C64382FE7EE9A9DE741B", docProp.Value );
        }
コード例 #4
0
        public void TestCopy( )
        {
            System.IO.File.Copy( emptyDocx, testDestFile, true );

            ContentTypeCopier.Copy( testSourceFile, testDestFile );

            DocxProperties sourceProps = new DocxProperties(testSourceFile);
            DocxProperties destProps = new DocxProperties(testDestFile);

            Assert.AreEqual(sourceProps.DocumentManagementProperties.Length, destProps.DocumentManagementProperties.Length);
            for (int i = 0; i != sourceProps.DocumentManagementProperties.Length; ++i)
            {
                Assert.AreEqual(sourceProps.DocumentManagementProperties[i].Name, destProps.DocumentManagementProperties[i].Name);
                Assert.AreEqual(sourceProps.DocumentManagementProperties[i].Value, destProps.DocumentManagementProperties[i].Value);
            }
        }
コード例 #5
0
        public void TestRemoveCustomXml( )
        {
            // docx with custom xml section
            System.IO.File.Copy( docxWithProps, testDestFile, true );

            {
                DocxProperties props = new DocxProperties( testDestFile );
                Assert.AreNotEqual( 0, props.DocumentManagementProperties.Length ); // props
            }

            ContentTypeCopier.RemoveCustomXml( testDestFile );

            {
                DocxProperties props = new DocxProperties( testDestFile );
                Assert.AreEqual( 0, props.DocumentManagementProperties.Length ); // no props
            }
        }
コード例 #6
0
        public void TestLoadProperties()
        {
            DocxProperties props = new DocxProperties( testSourceFile );

            Field[ ] docManProps = props.DocumentManagementProperties;
            Assert.IsNotNull( docManProps );
            Assert.AreEqual( 6, docManProps.Length );
            Assert.AreEqual( "Doc_x0020_No", docManProps[ 0 ].Name );
            Assert.AreEqual( "123", docManProps[ 0 ].Value );
            Assert.AreEqual( "Client_x0020_Name", docManProps[ 1 ].Name );
            Assert.AreEqual( "TheClient", docManProps[ 1 ].Value );
            Assert.AreEqual( "Dept_x0020_Name", docManProps[ 2 ].Name );
            Assert.AreEqual( "TheDept", docManProps[ 2 ].Value );
            Assert.AreEqual( "Matter_x0020_Name", docManProps[ 3 ].Name );
            Assert.AreEqual( "TheMatter", docManProps[ 3 ].Value );
            Assert.AreEqual( "Author0", docManProps[ 4 ].Name );
            Assert.AreEqual( "UK\\iainb2", docManProps[ 4 ].Value );
            Assert.AreEqual( "Document_x0020_Type", docManProps[ 5 ].Name );
            Assert.AreEqual( "TheDocType", docManProps[ 5 ].Value );
        }
コード例 #7
0
ファイル: Artifact.cs プロジェクト: killbug2004/WSProf
		private void LogCustomXml(string filename, string logMessage)
		{
			Logger.LogDebug(logMessage);
			Logger.LogDebug("Filename: " + filename);

			try
			{
				DocxProperties props = new DocxProperties(filename);
				Logger.LogDebug("ContentTypeProperties.ContentTypes.Length: " + props.DocumentManagementProperties.Length.ToString());

				foreach (Field prop in props.DocumentManagementProperties)
				{
					Logger.LogDebug("Name: " + prop.Name);
					Logger.LogDebug("Value: " + prop.Value);
				}
			}
			catch (Exception ex)
			{
				Logger.LogError("Exception thrown while attempting to log custom xml");
				Logger.LogError(ex);
			}
		}
コード例 #8
0
        public void TestLoadProperties_CoreProperties( )
        {
            DocxProperties props = new DocxProperties( testSourceFile );

            Field[ ] customFileProps = props.CoreProperties;
            Assert.IsNotNull( customFileProps );
            Assert.AreEqual( 9, customFileProps.Length ); 
        }
コード例 #9
0
        public void TestAddCustomFileProperty( )
        {
            DocxProperties props = new DocxProperties( testSourceFile );

            Field[ ] customFileProps = props.CustomFileProperties;
            Assert.IsNotNull( customFileProps );
            Assert.AreEqual( 8, customFileProps.Length );

            props.AddCustomFileProperty( new Field( "NewProperty", "NewValue" ) );
            customFileProps = props.CustomFileProperties;
            Assert.AreEqual( 9, customFileProps.Length );

            // ensure that the property is saved to the document by reloading and testing
            DocxProperties propsReloaded = new DocxProperties( testSourceFile );
            customFileProps = props.CustomFileProperties;
            Assert.AreEqual( 9, customFileProps.Length );

            Field savedProp = propsReloaded.FindProperty( "NewProperty", propsReloaded.customFileProperties );
            Assert.IsNotNull( savedProp );
            Assert.AreEqual( "NewValue", savedProp.Value );
        }
コード例 #10
0
		public void TestAddCoreProperty( )
		{
			DocxProperties props = new DocxProperties( testSourceFile );

			Field[ ] coreProps = props.CoreProperties;
			Assert.IsNotNull( coreProps );
			int oldLength = coreProps.Length;

			props.AddCoreProperty( new Field( "cp:contentType", "Document" ) );
			Assert.AreEqual( oldLength + 1, props.CoreProperties );

			Field retrievedProp = props.FindProperty( "cp:contentType", props.coreProperties );
			Assert.IsNotNull( retrievedProp );
			Assert.AreEqual( "Document", retrievedProp.Value );
		}
コード例 #11
0
        public void TestRemoveCustomXml_DoesntThrowIfFileHasNoProps( )
        {
            // docx without customxml section
            System.IO.File.Copy( emptyDocx, testDestFile, true );

            {
                DocxProperties props = new DocxProperties( testDestFile );
                Assert.AreEqual( 0, props.DocumentManagementProperties.Length ); // no props
            }

            ContentTypeCopier.RemoveCustomXml( testDestFile );

            {
                DocxProperties props = new DocxProperties( testDestFile );
                Assert.AreEqual( 0, props.DocumentManagementProperties.Length ); // no props
            }
        }