public virtual void SortOrderForOneKeyTest()
        {
            String            key           = "testKey";
            bool              testAscending = true;
            PdfCollectionSort sort          = new PdfCollectionSort(key);

            NUnit.Framework.Assert.IsNull(sort.GetPdfObject().Get(PdfName.A));
            sort.SetSortOrder(testAscending);
            NUnit.Framework.Assert.IsTrue(sort.GetPdfObject().GetAsBool(PdfName.A));
        }
        public virtual void OneKeyConstructorTest()
        {
            String            key  = "testKey";
            PdfCollectionSort sort = new PdfCollectionSort(key);

            NUnit.Framework.Assert.AreEqual(key, sort.GetPdfObject().GetAsName(PdfName.S).GetValue());
        }
        public virtual void MultipleKeysConstructorTest()
        {
            String[]          keys = new String[] { "testKey1", "testKey2", "testKey3" };
            PdfCollectionSort sort = new PdfCollectionSort(keys);

            for (int i = 0; i < keys.Length; i++)
            {
                NUnit.Framework.Assert.AreEqual(keys[i], sort.GetPdfObject().GetAsArray(PdfName.S).GetAsName(i).GetValue()
                                                );
            }
        }
        public virtual void SortOrderForMultipleKeysTest()
        {
            String[]          keys           = new String[] { "testKey1", "testKey2", "testKey3" };
            bool[]            testAscendings = new bool[] { true, false, true };
            PdfCollectionSort sort           = new PdfCollectionSort(keys);

            sort.SetSortOrder(testAscendings);
            for (int i = 0; i < testAscendings.Length; i++)
            {
                NUnit.Framework.Assert.AreEqual(testAscendings[i], sort.GetPdfObject().GetAsArray(PdfName.A).GetAsBoolean(
                                                    i).GetValue());
            }
        }
 public virtual void IncorrectSortOrderForOneKeyTest()
 {
     NUnit.Framework.Assert.That(() => {
         String key             = "testKey";
         bool[] testAscendings  = new bool[] { true, false };
         PdfCollectionSort sort = new PdfCollectionSort(key);
         sort.SetSortOrder(testAscendings);
         // this line will throw an exception as number of parameters of setSortOrder()
         // method should be exactly the same as number of keys of PdfCollectionSort
         // here we have one key but two params
         NUnit.Framework.Assert.IsTrue(sort.GetPdfObject().GetAsBool(PdfName.A));
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfException>().With.Message.EqualTo(PdfException.YouNeedASingleBooleanForThisCollectionSortDictionary))
     ;
 }
Exemplo n.º 6
0
 /// <summary>Sets the Collection sort dictionary.</summary>
 /// <param name="sort">is the Collection sort dictionary</param>
 /// <returns>this instance to support fluent interface</returns>
 public virtual iText.Kernel.Pdf.Collection.PdfCollection SetSort(PdfCollectionSort sort)
 {
     GetPdfObject().Put(PdfName.Sort, sort.GetPdfObject());
     return(this);
 }