Beispiel #1
0
 public void Setup()
 {
     provider = new TemplateManagerProvider()
         .WithLoader(new Loader())
         .WithTag("non-nested", new TestDescriptor.SimpleNonNestedTag())
         .WithTag("nested", new TestDescriptor.SimpleNestedTag())
         .WithTag("url", new TestUrlTag())
         ;
     provider = FilterManager.Initialize(provider);
     manager = provider.GetNewManager();
 }
Beispiel #2
0
 public void Setup()
 {
     provider = new TemplateManagerProvider()
                .WithLoader(new Loader())
                .WithTag("non-nested", new TestDescriptor.SimpleNonNestedTag())
                .WithTag("nested", new TestDescriptor.SimpleNestedTag())
                .WithTag("url", new TestUrlTag())
                .WithFilters(FilterManager.GetFilters())
     ;
     manager            = provider.GetNewManager();
     managerForDesigner = provider.WithSetting(Constants.EXCEPTION_IF_ERROR, false).GetNewManager();
 }
Beispiel #3
0
 public void Setup()
 {
     provider = new TemplateManagerProvider()
         .WithLoader(new Loader())
         .WithTag("non-nested", new TestDescriptor.SimpleNonNestedTag())
         .WithTag("nested", new TestDescriptor.SimpleNestedTag())
         .WithTag("url", new TestUrlTag())
         .WithFilters(FilterManager.GetFilters())
         ;
     manager = provider.GetNewManager();
     managerForDesigner = provider.WithSetting(Constants.EXCEPTION_IF_ERROR, false).GetNewManager();
 }
        private void ValidateSyntaxTree(NDjango.Interfaces.ITemplateManager manager)
        {
            ITemplate template = manager.GetTemplate(Template, new TestTyperesolver(),
                                                     new NDjango.TypeResolver.ModelDescriptor(new NDjango.TypeResolver.IDjangoType[]
            {
                new NDjango.TypeResolver.CLRTypeDjangoType("Standard", typeof(EmptyClass))
            }));

            //the same logic responsible for retriving nodes as in NodeProvider class (DjangoDesigner).
            List <INode> nodes = GetNodes(template.Nodes.ToList <INodeImpl>().ConvertAll
                                              (node => (INode)node)).FindAll(node =>
                                                                             (node is ICompletionValuesProvider) ||
                                                                             (node.NodeType == NodeType.ParsingContext) ||
                                                                             (node.ErrorMessage.Message != ""));
            List <DesignerData> actualResult = nodes.ConvertAll(
                node =>
            {
                var value_provider = node as ICompletionValuesProvider;
                var values         =
                    value_provider == null ?
                    new List <string>()
                            : value_provider.Values;
                List <string> contextValues = new List <string>(values);
                if (node.NodeType == NodeType.ParsingContext)
                {
                    contextValues.InsertRange(0, (node.Context.TagClosures));
                    return(new DesignerData(node.Position, node.Length, contextValues.ToArray(), node.ErrorMessage.Severity, node.ErrorMessage.Message));
                }
                else if (node.NodeType == NodeType.Reference)
                {
                    return(new DesignerData(node.Position, node.Length, GetModelValues(node.Context.Model, 2).ToArray(), node.ErrorMessage.Severity, node.ErrorMessage.Message));
                }
                else
                {
                    return(new DesignerData(node.Position, node.Length, new List <string>(values).ToArray(), node.ErrorMessage.Severity, node.ErrorMessage.Message));
                }
            });

            for (int i = 0; i < actualResult.Count; i++)
            {
                if (actualResult[i].Values.Length == 0)
                {
                    continue;
                }

                Assert.AreEqual(ResultForDesigner[i].Length, actualResult[i].Length, "Invalid Length");
                Assert.AreEqual(ResultForDesigner[i].Position, actualResult[i].Position, "Invalid Position");
                Assert.AreEqual(ResultForDesigner[i].Severity, actualResult[i].Severity, "Invalid Severity");
                Assert.AreEqual(ResultForDesigner[i].ErrorMessage, actualResult[i].ErrorMessage, "Invalid ErrorMessage");
                Assert.AreEqual(ResultForDesigner[i].Values, actualResult[i].Values, "Invalid Values Array");
            }
        }
        public string runTemplate(NDjango.Interfaces.ITemplateManager manager, string templateName, IDictionary <string, object> context)
        {
            Stopwatch stopwatch = new Stopwatch();
            string    retStr    = "";

            stopwatch.Start();
            for (int i = 0; i < 1; i++)
            {
                var template = manager.RenderTemplate(templateName, context);
                retStr = template.ReadToEnd();
            }
            using (TextWriter stream = System.IO.File.AppendText("Timers.txt"))
                stream.WriteLine(Name + "," + stopwatch.ElapsedTicks);
            return(retStr);
        }
        public void AnalyzeBlockNameNode(NDjango.Interfaces.ITemplateManager manager)
        {
            ITemplate template = manager.GetTemplate(Template);
            INode     bn_node  = GetNodes(template.Nodes.ToList <INodeImpl>().ConvertAll
                                              (node => (INode)node)).Find(node => node.NodeType == NodeType.BlockName);
            var           value_provider = bn_node as ICompletionValuesProvider;
            var           values         = (value_provider == null) ? new List <string>() : value_provider.Values;
            List <string> blockNames     = new List <string>(values);

            Assert.Greater(0, blockNames.Count(), "The dropdown with block names is empty");
            foreach (string name in Result)
            {
                Assert.Contains(name, blockNames, "Invalid block names list: there is no " + name);
            }
        }
        public void Run(NDjango.Interfaces.ITemplateManager manager)
        {
            if (ResultForDesigner != null)
            {
                ValidateSyntaxTree(manager);
                return;
            }

            var context = new Dictionary <string, object>();

            if (ContextValues != null)
            {
                for (int i = 0; i <= ContextValues.Length - 2; i += 2)
                {
                    context.Add(ContextValues[i].ToString(), ContextValues[i + 1]);
                }
            }

            try
            {
                if (resultGetter != null)
                {
                    Result = resultGetter();
                }
                Assert.AreEqual(Result[0], runTemplate(manager, Template, context), "** Invalid rendering result");
                //if (Vars.Length != 0)
                //    Assert.AreEqual(Vars, manager.GetTemplateVariables(Template), "** Invalid variable list");
            }
            catch (Exception ex)
            {
                // Result[0] is either some object, in which case this shouldn't have happened
                // or it's the type of the exception the calling code expects.
                if (resultGetter != null)
                {
                    Result = resultGetter();
                }
                Assert.AreEqual(Result[0], ex.GetType(), "Exception: " + ex.Message);
            }
        }
        private void ValidateSyntaxTree(NDjango.Interfaces.ITemplateManager manager)
        {
            ITemplate template = manager.GetTemplate(Template);

            //the same logic responsible for retriving nodes as in NodeProvider class (DjangoDesigner).
            List <INode> nodes = GetNodes(template.Nodes.ToList <INodeImpl>().ConvertAll
                                              (node => (INode)node)).FindAll(node =>
                                                                             (node.Values.ToList().Count != 0) ||
                                                                             (node.NodeType == NodeType.ParsingContext) ||
                                                                             (node.ErrorMessage.Message != ""));
            List <DesignerData> actualResult = nodes.ConvertAll(
                node =>
            {
                List <string> contextValues = new List <string>(node.Values);
                if (node.NodeType == NodeType.ParsingContext)
                {
                    contextValues.InsertRange(0, ((ParserNodes.ParsingContextNode)node).Context.TagClosures);
                    return(new DesignerData(node.Position, node.Length, contextValues.ToArray(), node.ErrorMessage.Severity, node.ErrorMessage.Message));
                }
                else
                {
                    return(new DesignerData(node.Position, node.Length, new List <string>(node.Values).ToArray(), node.ErrorMessage.Severity, node.ErrorMessage.Message));
                }
            });

            for (int i = 0; i < actualResult.Count; i++)
            {
                if (actualResult[i].Values.Length == 0)
                {
                    continue;
                }

                Assert.AreEqual(actualResult[i].Length, ResultForDesigner[i].Length, "Invalid Length");
                Assert.AreEqual(actualResult[i].Position, ResultForDesigner[i].Position, "Invalid Position");
                Assert.AreEqual(actualResult[i].Severity, ResultForDesigner[i].Severity, "Invalid Severity");
                Assert.AreEqual(actualResult[i].ErrorMessage, ResultForDesigner[i].ErrorMessage, "Invalid ErrorMessage");
                Assert.AreEqual(actualResult[i].Values, ResultForDesigner[i].Values, "Invalid Values");
            }
        }
Beispiel #9
0
 public DjangoView(NDjango.Interfaces.ITemplateManager iTemplateManager, string viewPath)
 {
     this.iTemplateManager = iTemplateManager;
     this.viewPath         = viewPath;
 }