Exemple #1
0
        public virtual void FieldAddingTest()
        {
            String        fieldName = "fieldName";
            PdfDictionary pdfObject = new PdfDictionary();

            pdfObject.Put(PdfName.Subtype, PdfName.S);
            PdfCollectionField  field  = new PdfCollectionField(pdfObject);
            PdfCollectionSchema schema = new PdfCollectionSchema();

            schema.AddField(fieldName, field);
            // should be the same instance
            NUnit.Framework.Assert.AreEqual(schema.GetField(fieldName).GetPdfObject(), pdfObject);
        }
        public virtual void DontAddDateItemToAnotherSubTypeFieldTest()
        {
            String        fieldName         = "fieldName";
            String        timeValueAsString = "D:19860426012347+04'00'";
            PdfDictionary pdfObject         = new PdfDictionary();

            pdfObject.Put(PdfName.Subtype, PdfName.F);
            PdfCollectionField  field  = new PdfCollectionField(pdfObject);
            PdfCollectionSchema schema = new PdfCollectionSchema();

            schema.AddField(fieldName, field);
            PdfCollectionItem item = new PdfCollectionItem(schema);

            item.AddItem(fieldName, new PdfDate(PdfDate.Decode(timeValueAsString)));
            NUnit.Framework.Assert.IsNull(item.GetPdfObject().GetAsString(new PdfName(fieldName)));
        }
        public virtual void DontAddNumberItemToAnotherSubTypeFieldTest()
        {
            String        fieldName   = "fieldName";
            double        numberValue = 0.1234;
            PdfDictionary pdfObject   = new PdfDictionary();

            pdfObject.Put(PdfName.Subtype, PdfName.F);
            PdfCollectionField  field  = new PdfCollectionField(pdfObject);
            PdfCollectionSchema schema = new PdfCollectionSchema();

            schema.AddField(fieldName, field);
            PdfCollectionItem item = new PdfCollectionItem(schema);

            item.AddItem(fieldName, new PdfNumber(numberValue));
            NUnit.Framework.Assert.IsNull(item.GetPdfObject().GetAsString(new PdfName(fieldName)));
        }
        public virtual void AddDateItemTest()
        {
            String        fieldName         = "fieldName";
            String        timeValueAsString = "D:19860426012347+04'00'";
            PdfDictionary pdfObject         = new PdfDictionary();

            pdfObject.Put(PdfName.Subtype, PdfName.D);
            PdfCollectionField  field  = new PdfCollectionField(pdfObject);
            PdfCollectionSchema schema = new PdfCollectionSchema();

            schema.AddField(fieldName, field);
            PdfCollectionItem item = new PdfCollectionItem(schema);

            item.AddItem(fieldName, new PdfDate(PdfDate.Decode(timeValueAsString)));
            NUnit.Framework.Assert.IsTrue(((PdfString)field.GetValue(timeValueAsString)).GetValue().StartsWith("D:1986"
                                                                                                               ));
        }
        public virtual void AddItemTest()
        {
            String        fieldName  = "fieldName";
            String        fieldValue = "fieldValue";
            PdfDictionary pdfObject  = new PdfDictionary();

            pdfObject.Put(PdfName.Subtype, PdfName.S);
            PdfCollectionField  field  = new PdfCollectionField(pdfObject);
            PdfCollectionSchema schema = new PdfCollectionSchema();

            schema.AddField(fieldName, field);
            PdfCollectionItem item = new PdfCollectionItem(schema);

            item.AddItem(fieldName, fieldValue);
            NUnit.Framework.Assert.AreEqual(fieldValue, item.GetPdfObject().GetAsString(new PdfName(fieldName)).GetValue
                                                ());
        }
        public virtual void AddNumberItemTest()
        {
            String        fieldName   = "fieldName";
            double        numberValue = 0.1234;
            PdfDictionary pdfObject   = new PdfDictionary();

            pdfObject.Put(PdfName.Subtype, PdfName.N);
            PdfCollectionField  field  = new PdfCollectionField(pdfObject);
            PdfCollectionSchema schema = new PdfCollectionSchema();

            schema.AddField(fieldName, field);
            PdfCollectionItem item = new PdfCollectionItem(schema);

            item.AddItem(fieldName, new PdfNumber(numberValue));
            NUnit.Framework.Assert.AreEqual(numberValue, item.GetPdfObject().GetAsNumber(new PdfName(fieldName)).GetValue
                                                (), 0.0001);
        }
 public virtual void AddPrefixToEmptyFieldTest()
 {
     NUnit.Framework.Assert.That(() => {
         String fieldName        = "fieldName";
         String fieldPrefix      = "fieldPrefix";
         PdfDictionary pdfObject = new PdfDictionary();
         pdfObject.Put(PdfName.Subtype, PdfName.S);
         PdfCollectionField field   = new PdfCollectionField(pdfObject);
         PdfCollectionSchema schema = new PdfCollectionSchema();
         schema.AddField(fieldName, field);
         PdfCollectionItem item = new PdfCollectionItem(schema);
         // this line will throw an exception as setPrefix() method may be called
         // only if value was set previously
         item.SetPrefix(fieldName, fieldPrefix);
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfException>().With.Message.EqualTo(PdfException.YouMustSetAValueBeforeAddingAPrefix))
     ;
 }