예제 #1
0
        /// <summary>
        /// Based on the above remote components there should be 2 calls to this resolver each resolving to a different path
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="xpath"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        IPDFComponent ShimResolver(string filename, string xpath, PDFGeneratorSettings settings)
        {
            resolverCallCount++;
            IPDFComponent resolverReturnValue;

            Assert.IsNotNull(settings);

            if (string.Equals(filename, "ShimFile2.pcfx"))
            {
                Assert.AreEqual("//xpath/node", xpath);
                Fakes.ParserInnerComplex complex = new Fakes.ParserInnerComplex();
                complex.Inheritable = "ShimFile2" + xpath;
                complex.Index       = 42;
                resolverReturnValue = complex;
            }
            else if (string.Equals(filename, "ShimFile.pcfx"))
            {
                Assert.IsTrue(String.IsNullOrEmpty(xpath));
                Fakes.ParserInnerComplex complex = new Fakes.ParserInnerComplex();
                complex.Inheritable = "ShimFile";
                resolverReturnValue = complex;
            }
            else
            {
                throw new ArgumentOutOfRangeException("Unknown remote file : " + filename);
            }

            return(resolverReturnValue);
        }
        public void PDFGeneratorSettingsConstructorTest()
        {
            Type literaltype                  = typeof(Scryber.Components.TextLiteral);
            Type templategenerator            = typeof(Scryber.Data.ParsableTemplateGenerator);
            Type templateinstance             = typeof(Scryber.Data.TemplateInstance);
            PDFReferenceResolver  resolver    = new PDFReferenceResolver(this.ShimResolver);
            ParserConformanceMode conformance = ParserConformanceMode.Lax;
            ParserLoadType        loadtype    = ParserLoadType.ReflectiveParser;
            PDFTraceLog           log         = new Scryber.Logging.DoNothingTraceLog(TraceRecordLevel.Off);
            PDFPerformanceMonitor mon         = new PDFPerformanceMonitor(true);

            Mocks.MockControllerClass controller = new Mocks.MockControllerClass();

            PDFGeneratorSettings target = new PDFGeneratorSettings(literaltype, templategenerator, templateinstance, resolver, conformance, loadtype, log, mon, controller);

            Assert.IsNotNull(target);
            Assert.AreSame(literaltype, target.TextLiteralType);
            Assert.AreSame(templategenerator, target.TempateGeneratorType);
            Assert.AreSame(resolver, target.Resolver);
            Assert.AreEqual(conformance, target.ConformanceMode);
            Assert.AreEqual(loadtype, target.LoadType);
            Assert.AreSame(log, target.TraceLog);
            Assert.AreSame(mon, target.PerformanceMonitor);
            Assert.AreSame(controller, target.Controller);
            Assert.AreEqual(controller.GetType(), target.ControllerType);
        }
예제 #3
0
        public void PDFXMLParserConstructorTest()
        {
            PDFGeneratorSettings settings = GetSettings();
            PDFXMLParser         target   = new PDFXMLParser(settings);

            Assert.IsNotNull(target);
            Assert.AreSame(settings, target.Settings);
        }
예제 #4
0
        public void SettingsTest()
        {
            PDFGeneratorSettings settings = this.GetSettings();
            PDFXMLParser         target   = new PDFXMLParser(settings);
            PDFGeneratorSettings actual;

            actual = target.Settings;
            Assert.AreSame(settings, actual);
        }
예제 #5
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        //
        // support methods
        //


        private PDFGeneratorSettings GetSettings()
        {
            Type literaltype                  = typeof(Scryber.Components.TextLiteral);
            Type templategenerator            = typeof(Scryber.Data.ParsableTemplateGenerator);
            Type templateinstance             = typeof(Scryber.Data.TemplateInstance);
            PDFReferenceResolver  resolver    = new PDFReferenceResolver(this.ShimResolver);
            ParserConformanceMode conformance = ParserConformanceMode.Lax;
            ParserLoadType        loadtype    = ParserLoadType.ReflectiveParser;
            PDFTraceLog           log         = new Scryber.Logging.DoNothingTraceLog(TraceRecordLevel.Off);
            PDFPerformanceMonitor perfmon     = new PDFPerformanceMonitor(true);
            PDFGeneratorSettings  settings    = new PDFGeneratorSettings(literaltype, templategenerator, templateinstance, resolver, conformance, loadtype, log, perfmon, null);

            return(settings);
        }
예제 #6
0
        public void ParseProcessingInstructionsTest()
        {
            PDFGeneratorSettings settings = GetSettings();
            PDFXMLParser         target   = new PDFXMLParser(settings);
            string source = @"C:\Fake\File\Path.xml";

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

                Assert.AreEqual(false, target.Settings.LogParserOutput);
                Assert.AreEqual(ParserConformanceMode.Strict, target.Mode);
            }
        }
예제 #7
0
        public void Parse_XmlValid2_Test()
        {
            PDFGeneratorSettings settings = GetSettings();
            PDFXMLParser         target   = new PDFXMLParser(settings);

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

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

                AssertValidXml2(result as Fakes.ParserRootOne);
            }
        }
예제 #8
0
        public void Parse_XmlValidRemote_Test()
        {
            PDFGeneratorSettings settings = GetSettings();
            PDFXMLParser         target   = new PDFXMLParser(settings);
            string source = @"C:\Fake\File\Path.xml";

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

                Assert.AreEqual(2, resolverCallCount);
                AssertValidXmlRemote(actual as Fakes.ParserRootOne);
            }
        }
        public void ConformanceModeTest()
        {
            Type literaltype                  = typeof(Scryber.Components.TextLiteral);
            Type templategenerator            = typeof(Scryber.Data.ParsableTemplateGenerator);
            Type templateinstance             = typeof(Scryber.Data.TemplateInstance);
            PDFReferenceResolver  resolver    = new PDFReferenceResolver(this.ShimResolver);
            ParserConformanceMode conformance = ParserConformanceMode.Lax;
            ParserLoadType        loadtype    = ParserLoadType.ReflectiveParser;
            PDFTraceLog           log         = new Scryber.Logging.DoNothingTraceLog(TraceRecordLevel.Off);
            PDFPerformanceMonitor mon         = new PDFPerformanceMonitor(true);
            PDFGeneratorSettings  target      = new PDFGeneratorSettings(literaltype, templategenerator, templateinstance, resolver, conformance, loadtype, log, mon, null);

            Assert.AreEqual(conformance, target.ConformanceMode);

            ParserConformanceMode expected = ParserConformanceMode.Strict;
            ParserConformanceMode actual;

            target.ConformanceMode = expected;
            actual = target.ConformanceMode;
            Assert.AreEqual(expected, actual);
        }
예제 #10
0
        public void Parse_XmlValid1_Test()
        {
            PDFGeneratorSettings settings = GetSettings();
            PDFXMLParser         target   = new PDFXMLParser(settings);
            string source = @"C:\Fake\File\Path.xml";

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

                AssertValidXml1(result as Fakes.ParserRootOne);
            }

            //Check with stream reader

            using (Stream stream = ToStream(xmlValid1))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    IPDFComponent actual;
                    actual = target.Parse(source, reader, ParseSourceType.DynamicContent);

                    AssertValidXml1(actual as Fakes.ParserRootOne);
                }
            }

            //Check with XMLReader

            using (Stream stream = ToStream(xmlValid1))
            {
                using (XmlReader reader = XmlReader.Create(stream))
                {
                    IPDFComponent actual;
                    actual = target.Parse(source, reader, ParseSourceType.DynamicContent);

                    AssertValidXml1(actual as Fakes.ParserRootOne);
                }
            }
        }
예제 #11
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);
        }
예제 #12
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;
        }
 IPDFComponent ShimResolver(string filename, string xpath, PDFGeneratorSettings settings)
 {
     return(null);
 }