Example #1
0
        /// <summary>
        /// Checks the object aginst the xml representation above
        /// </summary>
        /// <param name="obj"></param>
        private void AssertValidXmlRemote(Fakes.ParserRootOne obj)
        {
            Assert.IsNotNull(obj);
            Assert.IsTrue(String.IsNullOrEmpty(obj.Name));

            //Complex-Element
            Assert.IsNotNull(obj.Complex);
            Assert.AreEqual("implemented", obj.Complex.Inheritable);
            Assert.AreEqual(4, obj.Complex.Index);

            //Collection-One
            Assert.IsNotNull(obj.CollectionOne, "No Collection-One data");
            Assert.AreEqual(3, obj.CollectionOne.Count);
            Assert.IsInstanceOfType(obj.CollectionOne[0], typeof(Fakes.ParserInnerComplex));
            Assert.IsInstanceOfType(obj.CollectionOne[1], typeof(Fakes.More.ParserDifferentComplex)); //Different namespace
            Assert.IsInstanceOfType(obj.CollectionOne[2], typeof(Fakes.ParserInnerComplex));          //remote reference
            Assert.AreEqual("ShimFile", obj.CollectionOne[2].Inheritable);                            //Check the inner propeties set in resolver.

            //Default collection

            Assert.IsNotNull(obj.DefaultCollection);
            Assert.AreEqual(2, obj.DefaultCollection.Count);

            Assert.IsInstanceOfType(obj.DefaultCollection[0], typeof(Fakes.More.ParserDifferentComplex));
            Fakes.More.ParserDifferentComplex dif = (Fakes.More.ParserDifferentComplex)obj.DefaultCollection[0];
            Assert.AreEqual((Scryber.Drawing.PDFUnit) 13, dif.Thickness.Left);

            Assert.IsInstanceOfType(obj.DefaultCollection[1], typeof(Fakes.ParserInnerComplex));
            Assert.AreEqual(42, obj.DefaultCollection[1].Index);
            Assert.AreEqual("ShimFile2//xpath/node", obj.DefaultCollection[1].Inheritable); //Check the inner propeties set in resolver.
        }
Example #2
0
        /// <summary>
        /// Checks the object aginst the xml representation above
        /// </summary>
        /// <param name="obj"></param>
        private void AssertValidXml2(Fakes.ParserRootOne obj)
        {
            Assert.IsNotNull(obj);
            Assert.IsTrue(String.IsNullOrEmpty(obj.Name));

            //Complex-Element
            Assert.IsNotNull(obj.Complex);
            Assert.AreEqual("implemented", obj.Complex.Inheritable);
            Assert.AreEqual(4, obj.Complex.Index);

            //Collection-One
            Assert.IsNotNull(obj.CollectionOne, "No Collection-One data");
            Assert.AreEqual(3, obj.CollectionOne.Count);
            Assert.IsInstanceOfType(obj.CollectionOne[0], typeof(Fakes.ParserInnerComplex));
            Assert.IsInstanceOfType(obj.CollectionOne[1], typeof(Fakes.More.ParserDifferentComplex)); //Different namespace
            Assert.IsInstanceOfType(obj.CollectionOne[2], typeof(Fakes.ParserInnerComplex));

            //Default collection

            Assert.IsNotNull(obj.DefaultCollection);
            Assert.AreEqual(2, obj.DefaultCollection.Count);

            Assert.IsInstanceOfType(obj.DefaultCollection[0], typeof(Fakes.More.ParserDifferentComplex));
            Fakes.More.ParserDifferentComplex dif = (Fakes.More.ParserDifferentComplex)obj.DefaultCollection[0];
            //Parsing order = Top Right Bottom Left.
            Assert.AreEqual((Scryber.Drawing.PDFUnit) 13, dif.Thickness.Left);

            Assert.IsInstanceOfType(obj.DefaultCollection[1], typeof(Fakes.ParserInnerComplex));
            Assert.AreEqual(42, obj.DefaultCollection[1].Index);
        }
Example #3
0
        /// <summary>
        /// Checks the object aginst the xml representation above
        /// </summary>
        /// <param name="obj"></param>
        private void AssertValidXml1(Fakes.ParserRootOne obj)
        {
            Assert.IsNotNull(obj);
            Assert.AreEqual("root component", obj.Name);
            Assert.IsNotNull(obj.Complex);
            Assert.AreEqual("implemented", obj.Complex.Inheritable);
            Assert.AreEqual(24, obj.Complex.Index);
            Assert.AreEqual(2.5, obj.Complex.Size);
            Assert.AreEqual(0, obj.Complex.AnotherIndex); //not set

            Assert.IsNull(obj.DefaultCollection);
            Assert.IsNull(obj.CollectionOne);
        }
Example #4
0
        public void RootComponentTest()
        {
            PDFGeneratorSettings settings = GetSettings();
            PDFXMLParser         target   = new PDFXMLParser(settings);
            IPDFComponent        expected = new Fakes.ParserRootOne();
            IPDFComponent        actual;

            //
            // if we set it, then it should stay as set
            //

            target.RootComponent = expected;
            string source = @"C:\Fake\File\Path.xml";

            using (Stream stream = ToStream(xmlValid1))
            {
                target.Parse(source, stream, ParseSourceType.DynamicContent); //not capturing the output - want to check the RootComponent
            }

            actual = target.RootComponent as IPDFComponent;
            Assert.AreSame(expected, actual); //Should not have changed

            //
            // if we don't set it then it becomes the output
            //

            target = new PDFXMLParser(settings);
            source = @"C:\Fake\File\Path.xml";
            using (Stream stream = ToStream(xmlValid1))
            {
                expected = target.Parse(source, stream, ParseSourceType.DynamicContent);
                AssertValidXml1(expected as Fakes.ParserRootOne);
            }

            actual = target.RootComponent as Fakes.ParserRootOne;  //root component should be the same as the returned value from parse
            Assert.AreSame(expected, actual);
        }
        public void IsSimpleObjectExplictCultureTest()
        {
            IFormatProvider   french = System.Globalization.CultureInfo.GetCultureInfo("fr-FR");
            PDFValueConverter converter;

            //Enumueration
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(Scryber.DrawingOrigin), out converter));
            Assert.AreEqual(Scryber.DrawingOrigin.BottomLeft, converter.Invoke("BottomLeft", typeof(Scryber.DrawingOrigin), french), "Enum failed");

            //Boolean
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(bool), out converter));
            Assert.AreEqual(true, converter.Invoke("true", typeof(bool), french), "Boolean failed");

            //Byte
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(byte), out converter));
            Assert.AreEqual((byte)2, converter.Invoke("2", typeof(byte), french), "Byte failed");

            //Char
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(char), out converter));
            Assert.AreEqual('c', converter.Invoke("c", typeof(char), french), "Char failed");

            //DateTime
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(DateTime), out converter));
            Assert.AreEqual(new DateTime(2014, 05, 25, 12, 11, 10), converter.Invoke("25 mai 2014 12:11:10", typeof(DateTime), french), "DateTime failed");

            //Decimal
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(decimal), out converter));
            Assert.AreEqual(-12.5M, converter.Invoke("-12,5", typeof(decimal), french), "Decimal failed");

            //Double
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(double), out converter));
            Assert.AreEqual(12.50, converter.Invoke("12,5", typeof(double), french), "Double failed");

            //Int16
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(short), out converter));
            Assert.AreEqual((short)12, converter.Invoke("12", typeof(short), french), "Short failed");

            //Int32
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(int), out converter));
            Assert.AreEqual(-12, converter.Invoke("-12", typeof(int), french), "Int32 failed");

            //Int64
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(long), out converter));
            Assert.AreEqual((long)12, converter.Invoke("12", typeof(long), french), "Long failed");

            //SByte
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(SByte), out converter));
            Assert.AreEqual((SByte)(-12), converter.Invoke("-12", typeof(sbyte), french), "SByte failed");

            //Float
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(float), out converter));
            Assert.AreEqual(12.4F, converter.Invoke("12,4", typeof(float), french), "Float failed");

            //String
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(string), out converter));
            Assert.AreEqual("value", converter.Invoke("value", typeof(string), french), "String failed");

            //UInt16
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(ushort), out converter));
            Assert.AreEqual((ushort)12, converter.Invoke("12", typeof(ushort), french), "UShort failed");

            //Int16
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(uint), out converter));
            Assert.AreEqual((uint)12, converter.Invoke("12", typeof(uint), french), "UInt32 failed");

            //Int16
            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(ulong), out converter));
            Assert.AreEqual((ulong)12, converter.Invoke("12", typeof(ulong), french), "UInt64 failed");

            //Guid
            string guidS = "{62261BCA-DEE5-4285-A406-8236BC8025FA}";
            Guid   guid  = new Guid(guidS);

            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(Guid), out converter));
            Assert.AreEqual(guid, converter.Invoke(guidS, typeof(Guid), french), "Guid failed");

            TimeSpan time  = new TimeSpan(234567);
            string   timeS = time.ToString();

            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(TimeSpan), out converter));
            Assert.AreEqual(time, converter.Invoke(timeS, typeof(TimeSpan), french), "TimeSpan failed");

            string url = "http://www.scryber.co.uk";
            Uri    uri = new Uri(url);

            Assert.IsTrue(ParserDefintionFactory.IsSimpleObjectType(typeof(Uri), out converter));
            Assert.AreEqual(uri, converter.Invoke(url, typeof(Uri), french), "URI failed");

            Fakes.ParserRootOne complex = new Fakes.ParserRootOne();
            Assert.IsFalse(ParserDefintionFactory.IsSimpleObjectType(complex.GetType(), out converter));
            Assert.IsNull(converter);
        }
Example #6
0
        public void ParseProcessingCultureTest()
        {
            PDFGeneratorSettings settings = GetSettings();
            PDFXMLParser         target   = new PDFXMLParser(settings);
            string source = @"C:\Fake\File\Path.xml";

            //Invariant format for dates and numbers

            using (Stream stream = ToStream(xmlValidInvariant))
            {
                IPDFComponent actual;
                actual = target.Parse(source, stream, ParseSourceType.DynamicContent);

                Assert.AreEqual(false, target.Settings.LogParserOutput);
                Assert.AreEqual(ParserConformanceMode.Strict, target.Mode);

                Assert.IsInstanceOfType(actual, typeof(Fakes.ParserRootOne));

                Fakes.ParserRootOne r1 = (Fakes.ParserRootOne)actual;
                Assert.AreEqual(r1.Complex.Size, 2.5, "Invariant number failed");
                Assert.AreEqual(r1.Complex.Date, new DateTime(2015, 12, 25, 13, 30, 24), "Invariant date failed");
            }

            //British format for dates and numbers

            settings = GetSettings();
            target   = new PDFXMLParser(settings);

            using (Stream stream = ToStream(xmlValidExplicitGB))
            {
                IPDFComponent actual;
                actual = target.Parse(source, stream, ParseSourceType.DynamicContent);

                Assert.AreEqual(false, target.Settings.LogParserOutput);
                Assert.AreEqual(ParserConformanceMode.Strict, target.Mode);

                Assert.IsInstanceOfType(actual, typeof(Fakes.ParserRootOne));

                Fakes.ParserRootOne r1 = (Fakes.ParserRootOne)actual;
                Assert.AreEqual(r1.Complex.Size, 2.5, "Britsh number failed");
                Assert.AreEqual(r1.Complex.Date, new DateTime(2015, 12, 25, 13, 30, 24), "Britsh date failed");
            }

            //French format for dates and numbers

            settings = GetSettings();
            target   = new PDFXMLParser(settings);

            using (Stream stream = ToStream(xmlValidExplicitFR))
            {
                IPDFComponent actual;
                actual = target.Parse(source, stream, ParseSourceType.DynamicContent);

                Assert.AreEqual(false, target.Settings.LogParserOutput);
                Assert.AreEqual(ParserConformanceMode.Strict, target.Mode);

                Assert.IsInstanceOfType(actual, typeof(Fakes.ParserRootOne));

                Fakes.ParserRootOne r1 = (Fakes.ParserRootOne)actual;
                Assert.AreEqual(r1.Complex.Size, 2.5, "French number failed");
                Assert.AreEqual(r1.Complex.Date, new DateTime(2015, 12, 25, 13, 30, 24), "French date failed");
            }

            //Make sure the current culture is ignored

            System.Globalization.CultureInfo current = System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Threading.Thread.CurrentThread.CurrentCulture   = System.Globalization.CultureInfo.GetCultureInfo("fr-FR");
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("fr-FR");

            //Invariant format for dates and numbers

            settings = GetSettings();
            target   = new PDFXMLParser(settings);

            using (Stream stream = ToStream(xmlValidInvariant))
            {
                IPDFComponent actual;
                actual = target.Parse(source, stream, ParseSourceType.DynamicContent);

                Assert.AreEqual(false, target.Settings.LogParserOutput);
                Assert.AreEqual(ParserConformanceMode.Strict, target.Mode);

                Assert.IsInstanceOfType(actual, typeof(Fakes.ParserRootOne));

                Fakes.ParserRootOne r1 = (Fakes.ParserRootOne)actual;
                Assert.AreEqual(r1.Complex.Size, 2.5, "Invariant number failed in french culture");
                Assert.AreEqual(r1.Complex.Date, new DateTime(2015, 12, 25, 13, 30, 24), "Invariant date failed in french culture");
            }

            //British format for dates and numbers

            settings = GetSettings();
            target   = new PDFXMLParser(settings);

            using (Stream stream = ToStream(xmlValidExplicitGB))
            {
                IPDFComponent actual;
                actual = target.Parse(source, stream, ParseSourceType.DynamicContent);

                Assert.AreEqual(false, target.Settings.LogParserOutput);
                Assert.AreEqual(ParserConformanceMode.Strict, target.Mode);

                Assert.IsInstanceOfType(actual, typeof(Fakes.ParserRootOne));

                Fakes.ParserRootOne r1 = (Fakes.ParserRootOne)actual;
                Assert.AreEqual(r1.Complex.Size, 2.5, "Britsh number failed");
                Assert.AreEqual(r1.Complex.Date, new DateTime(2015, 12, 25, 13, 30, 24), "Britsh date failed");
            }

            //French format for dates and numbers

            settings = GetSettings();
            target   = new PDFXMLParser(settings);

            using (Stream stream = ToStream(xmlValidExplicitFR))
            {
                IPDFComponent actual;
                actual = target.Parse(source, stream, ParseSourceType.DynamicContent);

                Assert.AreEqual(false, target.Settings.LogParserOutput);
                Assert.AreEqual(ParserConformanceMode.Strict, target.Mode);

                Assert.IsInstanceOfType(actual, typeof(Fakes.ParserRootOne));

                Fakes.ParserRootOne r1 = (Fakes.ParserRootOne)actual;
                Assert.AreEqual(r1.Complex.Size, 2.5, "French number failed");
                Assert.AreEqual(r1.Complex.Date, new DateTime(2015, 12, 25, 13, 30, 24), "French date failed");
            }

            System.Threading.Thread.CurrentThread.CurrentCulture = current;
        }