public void ProcessTemplateContextCompositeShouldReturnDatabaseName()
        {
            string expected = "HelloWorldDatabase";
            var    databaseNameContextHandler = new DatabaseNameDatabaseContextHandler(_templateHandlerNew);
            TemplateContextComposite templateContextComposite = new TemplateContextComposite()
            {
                current = new DatabaseTemplateContext()
                {
                    StartIndex            = 0,
                    ContextDepth          = 0,
                    InnerContent          = string.Empty,
                    StartContextDelimiter = databaseNameContextHandler.StartContext,
                    EndContextDelimiter   = databaseNameContextHandler.EndContext,
                },
                childs = null,
            };
            var actual = _tested.ProcessTemplateContextComposite(templateContextComposite, new ProcessorDatabaseContext()
            {
                Database = new DatabaseModel()
                {
                    Name = expected,
                }
            });

            Assert.AreEqual(expected, actual);
        }
예제 #2
0
 public StartAndEndIndexSplitter ToStartAndEndIndexPair(TemplateContextComposite templateContextComposite)
 {
     return(new StartAndEndIndexSplitter()
     {
         StartIndex = templateContextComposite.current.StartIndex,
         EndIndex = templateContextComposite.current.StartIndex + templateContextComposite.current.Content.Length,
     });
 }
        public TemplateContextComposite ToQualifiedTemplateContext(TemplateContextComposite converted)
        {
            var result = new TemplateContextComposite();

            result.current = ToQualifiedTemplateContext(converted.current);
            result.childs  = converted?.childs?.Select(ToQualifiedTemplateContext)?.ToList() ?? new List <TemplateContextComposite>();
            return(result);
        }
예제 #4
0
 private string PreProcess(string templateFileContent, TemplateContextComposite contextComposite,
                           IDictionary <string, AbstactPreprocessorContextHandler> handlersByStartContext)
 {
     if (!handlersByStartContext.TryGetValue(contextComposite.current.StartContextDelimiter, out var handler))
     {
         return(templateFileContent);
     }
     return(handler.ProcessContext(templateFileContent, null));
 }
예제 #5
0
        public string ProcessTemplateContextComposite(TemplateContextComposite processed, IDatabaseContext databaseContext)
        {
            if (processed.current.InnerContent == null)
            {
                throw new ArgumentException($"{nameof(processed)}.{nameof(processed.current)}.{nameof(processed.current.InnerContent)} cannot be null");
            }
            var result = processed.current.Content;

            if (processed.childs?.Any() ?? false)
            {
                var minContextDepth                 = processed.childs.Min(m => m.current.ContextDepth);
                var childs                          = processed.childs.Where(m => m.current.ContextDepth == minContextDepth).OrderBy(m => m.current.StartIndex).ToList();
                var childAndProcessedContexts       = childs.Select(m => Tuple.Create(m, ProcessTemplateContextComposite(m, databaseContext), ToStartAndEndIndexPair(m))).ToList();
                var splittedProcessedInnerContent   = Split(processed.current.InnerContent, childAndProcessedContexts.Select(m => m.Item3).ToList());
                var processedChildContext           = childAndProcessedContexts.Select(m => m.Item2).ToList();
                IEnumerable <string> chainedResults = childs.First().current.StartIndex == 0 ?
                                                      Chain(processedChildContext, splittedProcessedInnerContent) :
                                                      Chain(splittedProcessedInnerContent, processedChildContext);
                var newInnerContent = string.Join(string.Empty, chainedResults);
                result = string.Join(processed.current.StartContextDelimiter, newInnerContent, processed.current.EndContextDelimiter);
            }

            if (processed.current is DatabaseTemplateContext)
            {
                result = ProcessDatabaseTemplateContext(result, processed.current.StartContextDelimiter, databaseContext);
            }
            if (processed.current is TableTemplateContext)
            {
                result = ProcessTableTemplateContext(result, processed.current.StartContextDelimiter, databaseContext);
            }
            if (processed.current is ColumnTemplateContext)
            {
                result = ProcessColumnTemplateContext(result, processed.current.StartContextDelimiter, databaseContext);
            }
            if (processed.current is ConstraintTemplateContext)
            {
                result = ProcessConstraintTemplateContext(result, processed.current.StartContextDelimiter, databaseContext);
            }
            if (processed.current is FunctionTemplateContext)
            {
                result = ProcessFunctionTemplateContext(result, processed.current.StartContextDelimiter, databaseContext);
            }
            return(result);
        }
예제 #6
0
 private string ToContextValue(TemplateContextComposite contextComposite)
 {
     return($"{contextComposite.current.StartContextDelimiter}{contextComposite.current.InnerContent}{contextComposite.current.EndContextDelimiter}");
 }