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);
        }
Пример #2
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);
        }
        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);
        }
Пример #4
0
        public PDFGeneratorSettings(Type literaltype, Type templategenerator, Type templateinstance,
                                    PDFReferenceResolver resolver, ParserConformanceMode conformance, ParserLoadType loadtype,
                                    PDFTraceLog log, PDFPerformanceMonitor perfmon, object controllerInstance)
        {
            this._textLiteralType      = literaltype;
            this._tempateGenType       = templategenerator;
            this._templateinstanceType = templateinstance;
            this._resolver             = resolver;
            this._conformance          = conformance;
            this._loadtype             = loadtype;
            this._log                = log;
            this._perfmon            = perfmon;
            this._controllerInstance = controllerInstance;
            this._controllerType     = (null == controllerInstance) ? null : controllerInstance.GetType();

            //Get the default culture from the config - can be overridden in the processing instructions, or at generation time in code
            var config        = ServiceProvider.GetService <IScryberConfigurationService>();
            var parserOptions = config.ParsingOptions;

            this.MissingReferenceAction = parserOptions.MissingReferenceAction;
            this.SpecificCulture        = parserOptions.GetDefaultCulture();
        }
        public string MapPath(ParserLoadType loadtype, string reference, string parent, out bool isFile)
        {
            if (Uri.IsWellFormedUriString(reference, UriKind.Absolute))
            {
                isFile = false;
                return(reference);
            }
            else if (Uri.IsWellFormedUriString(reference, UriKind.Relative) && !string.IsNullOrEmpty(parent) && Uri.IsWellFormedUriString(parent, UriKind.Absolute))
            {
                if (reference.StartsWith("/"))
                {
                    // a starting / on the reference is from the beginning of the authority
                    isFile = false;
                    Uri uri = new Uri(parent);
                    return(uri.Scheme + "://" + uri.Authority + reference);
                }

                if (!parent.EndsWith("/")) // we have a file as the parent reference so go up one.
                {
                    parent = parent.Substring(0, parent.LastIndexOf("/"));
                }
                while (reference.StartsWith("../")) // traverse up the tree for ../
                {
                    parent    = parent.Substring(0, parent.LastIndexOf("/"));
                    reference = reference.Substring(3);
                }

                if (reference.StartsWith("./")) // ./ is where we are at.
                {
                    reference = reference.Substring(2);
                }

                isFile = false;
                if (parent.EndsWith("/"))
                {
                    if (reference.StartsWith("/"))
                    {
                        return(parent + reference.Substring(1));
                    }
                    else
                    {
                        return(parent + reference);
                    }
                }
                else if (reference.StartsWith("/"))
                {
                    return(parent + reference);
                }
                else
                {
                    return(parent + "/" + reference);
                }
            }

            isFile = true;

            //Replace any alternate separator chars with the actual character.
            var dirSep = System.IO.Path.DirectorySeparatorChar;

            if (dirSep == '/')
            {
                reference = reference.Replace('\\', '/');
            }
            else if (dirSep == '\\')
            {
                reference = reference.Replace('/', '\\');
            }

            if (System.IO.Path.IsPathRooted(reference))
            {
                return(reference);
            }
            else if (reference.StartsWith("~"))
            {
                var dir      = System.Environment.CurrentDirectory;
                var combined = System.IO.Path.Combine(dir, reference.Substring(1));
                var clean    = System.IO.Path.GetFullPath(combined);
                return(clean);
            }
            else if (!string.IsNullOrEmpty(parent))
            {
                var dir      = System.IO.Path.GetDirectoryName(parent);
                var combined = System.IO.Path.Combine(dir, reference);
                var clean    = System.IO.Path.GetFullPath(combined);
                return(clean);
            }
            else
            {
                var dir      = System.Environment.CurrentDirectory;
                var combined = System.IO.Path.Combine(dir, reference);
                var clean    = System.IO.Path.GetFullPath(combined);
                return(clean);
            }
        }