Exemplo n.º 1
0
        private static void AddCompleteItems(Type type, SortedDictionary <string, AutoCompleteItem> completeItems)
        {
            foreach (var member in type.GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                completeItems.Add(new AutoCompleteItem(member));
            }
            foreach (var member in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                     .Where(info => info.GetIndexParameters().Length == 0))
            {
                completeItems.Add(new AutoCompleteItem(member));
            }
            foreach (var member in type.GetEvents(BindingFlags.Public | BindingFlags.Instance))
            {
                completeItems.Add(new AutoCompleteItem(member));
            }

            if (!type.IsValueType && !typeof(Delegate).IsAssignableFrom(type))
            {
                completeItems.Add(new AutoCompleteItem(AttachedMemberConstants.DataContext,
                                                       AttachedMemberConstants.DataContext, MemberTypes.Custom));
            }
            foreach (var attachedName in BindingServiceProvider.MemberProvider.GetAttachedMembers(type))
            {
                if (!completeItems.ContainsKey(attachedName.Key) && XmlTokenizer.IsValidName(attachedName.Key))
                {
                    completeItems.Add(new AutoCompleteItem(attachedName.Key, attachedName.Key, MemberTypes.Custom,
                                                           attachedName.Value.Type));
                }
            }
        }
Exemplo n.º 2
0
        public void NewspaperDtdComplete()
        {
            var s = new SourceManager(@"<!DOCTYPE NEWSPAPER [

 <!ELEMENT NEWSPAPER (ARTICLE+)>
 <!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)>
 <!ELEMENT HEADLINE (#PCDATA)>
 <!ELEMENT BYLINE (#PCDATA)>
 <!ELEMENT LEAD (#PCDATA)>
 <!ELEMENT BODY (#PCDATA)>
 <!ELEMENT NOTES (#PCDATA)>

 <!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
 <!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
 <!ATTLIST ARTICLE DATE CDATA #IMPLIED>
 <!ATTLIST ARTICLE EDITION CDATA #IMPLIED>

 <!ENTITY NEWSPAPER ""Vervet Logic Times"">
 <!ENTITY PUBLISHER ""Vervet Logic Press"">
 <!ENTITY COPYRIGHT 'Copyright 1998 Vervet Logic Press'>

 ]>");
            var t = new XmlTokenizer(s);

            t.DTD.Reset();
            var e = t.Get();

            Assert.AreEqual(XmlTokenType.DOCTYPE, e.Type);
            var d = (XmlDoctypeToken)e;

            Assert.IsFalse(d.IsNameMissing);
            Assert.AreEqual("NEWSPAPER", d.Name);
            Assert.IsTrue(d.IsSystemIdentifierMissing);
            Assert.AreEqual(14, t.DTD.Count);
        }
        public static FlowDocument ColorizeXAML(string xamlText, FlowDocument targetDoc)
        {
            XmlTokenizer     tokenizer = new XmlTokenizer();
            XmlTokenizerMode mode      = XmlTokenizerMode.OutsideElement;

            List <XmlToken> tokens     = tokenizer.Tokenize(xamlText, ref mode);
            List <string>   tokenTexts = new List <string>(tokens.Count);
            List <Color>    colors     = new List <Color>(tokens.Count);
            int             position   = 0;

            foreach (XmlToken token in tokens)
            {
                string tokenText = xamlText.Substring(position, token.Length);
                tokenTexts.Add(tokenText);
                Color color = ColorForToken(token, tokenText);
                colors.Add(color);
                position += token.Length;
            }

            Paragraph p = new Paragraph();

            // Loop through tokens
            for (int i = 0; i < tokenTexts.Count; i++)
            {
                Run r = new Run(tokenTexts[i]);
                r.Foreground = new SolidColorBrush(colors[i]);
                p.Inlines.Add(r);
            }

            targetDoc.Blocks.Add(p);

            return(targetDoc);
        }
Exemplo n.º 4
0
        public void EmptyXmlDocumentTokenization()
        {
            var s = new TextSource("");
            var t = new XmlTokenizer(s, null);
            var e = t.Get();

            Assert.IsInstanceOf <XmlEndOfFileToken>(e);
        }
Exemplo n.º 5
0
        public void EmptyXmlDocumentTokenization()
        {
            var s = new SourceManager("");
            var t = new XmlTokenizer(s);
            var e = t.Get();

            Assert.AreEqual(XmlToken.EOF, e);
        }
Exemplo n.º 6
0
        public void ValidXmlDeclarationOnlyVersion()
        {
            var s = new TextSource("<?xml version=\"1.0\"?>");
            var t = new XmlTokenizer(s, null);
            var e = t.Get();

            Assert.AreEqual(XmlTokenType.Declaration, e.Type);
            Assert.AreEqual("1.0", ((XmlDeclarationToken)e).Version);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a new instance of the XML parser.
 /// </summary>
 /// <param name="document">The document instance to be filled.</param>
 internal XmlDomBuilder(Document document)
 {
     var resolver = document.Options.GetService<IEntityService>() ?? XmlEntityService.Resolver;
     _tokenizer = new XmlTokenizer(document.Source, document.Options.Events, resolver);
     _document = document;
     _standalone = false;
     _openElements = new List<Element>();
     _currentMode = XmlTreeMode.Initial;
 }
    /// <summary>
    /// Format Xml in the passed rich text box.
    /// </summary>
    /// <param name="xmlEditor"></param>
    public static void FormatXml(RichTextBox xmlEditor)
    {
        //  Stop redrawing
        RichTextDrawing.StopRedraw(xmlEditor);

        //  Tokenize the Xml string
        List <XmlToken> tokens = XmlTokenizer.Tokenize(xmlEditor.Text);

        foreach (XmlToken token in tokens)
        {
            xmlEditor.Select(token.Index, token.Text.Length);
            switch (token.Type)
            {
            case XmlTokenType.None:
                xmlEditor.SelectionColor = xmlEditor.ForeColor;
                break;

            case XmlTokenType.SpecialChar:
                xmlEditor.SelectionColor = specialCharColor;
                break;

            case XmlTokenType.Escape:
                xmlEditor.SelectionColor = escapeColor;
                break;

            case XmlTokenType.Element:
                xmlEditor.SelectionColor = elementColor;
                break;

            case XmlTokenType.Attribute:
                xmlEditor.SelectionColor = attributeColor;
                break;

            case XmlTokenType.Value:
                xmlEditor.SelectionColor = valueColor;
                break;

            case XmlTokenType.Comment:
                xmlEditor.SelectionColor = commentColor;
                break;
            }
        }

        //  Sample code to show that the perf problem is a RichTexBox problem
        //string content = xmlEditor.Text;
        //Random gen = new Random();
        //for (int i = 0; i < content.Length; i++)
        //{
        //    xmlEditor.Select(i, 1);
        //    Color c = Color.FromArgb(gen.Next(256), gen.Next(256), gen.Next(256));
        //    xmlEditor.SelectionColor = c;
        //}

        //  Resume redraw
        RichTextDrawing.RestoreRedraw(xmlEditor);
    }
Exemplo n.º 9
0
        async void GenerateOutput(Object obj)
        {
            CmdletObject cmd    = Tab.EditorContext.CurrentCmdlet;
            ModuleObject module = Tab.Module;

            if (cmd == null)
            {
                return;
            }

            BusyControlVisible = Visibility.Visible;
            RtbVisible         = Visibility.Collapsed;
            WebBrowserVisible  = Visibility.Collapsed;

            if (HtmlChecked)
            {
                HtmlText = await HtmlProcessor.GenerateHtmlView(cmd, module);

                HtmlText           = String.Format(Properties.Resources.HtmlTemplate, cmd.Name, HtmlText, cmd.ExtraHeader, cmd.ExtraFooter);
                BusyControlVisible = Visibility.Collapsed;
                RtbVisible         = Visibility.Collapsed;
                WebBrowserVisible  = Visibility.Visible;
                return;
            }

            IEnumerable <XmlToken> data = new List <XmlToken>();

            if (XmlChecked)
            {
                if (module.UpgradeRequired)
                {
                    Utils.MsgBox("Warning", "The module is offline and requires upgrade. Upgrade the project to allow XML view.", MessageBoxButton.OK, MessageBoxImage.Warning);
                    BusyControlVisible = Visibility.Collapsed;
                    return;
                }
                List <CmdletObject> cmdlets = new List <CmdletObject> {
                    cmd
                };
                StringBuilder SB = new StringBuilder();
                await XmlProcessor.XmlGenerateHelp(SB, cmdlets, null, module.IsOffline);

                data = XmlTokenizer.LoopTokenize(SB.ToString());
            }
            else if (HtmlSourceChecked)
            {
                data = await HtmlProcessor.GenerateHtmlSourceHelp(cmd, module);
            }
            Paragraph para = new Paragraph();

            para.Inlines.AddRange(ColorizeSource(data));
            Document = new FlowDocument();
            Document.Blocks.Add(para);
            BusyControlVisible = Visibility.Collapsed;
            WebBrowserVisible  = Visibility.Collapsed;
            RtbVisible         = Visibility.Visible;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Tries to parse the Xml.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="element">The element.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        public static bool TryParseXml <T>(IXPathNavigable element, out T to)
            where T : class, new()
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            return(XmlTokenizer <T> .TryParse(element, new TokenizerArgs(), out to));
        }
Exemplo n.º 11
0
        public void OneCommentInXmlDocument()
        {
            var c = "My comment";
            var s = new TextSource("<!--" + c + "-->");
            var t = new XmlTokenizer(s, null);
            var e = t.Get();

            Assert.AreEqual(XmlTokenType.Comment, e.Type);
            Assert.AreEqual(c, ((XmlCommentToken)e).Data);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Creates a new instance of the XML parser.
 /// </summary>
 /// <param name="document">The document instance to be filled.</param>
 /// <param name="creator">The optional non-standard creator to use.</param>
 internal XmlDomBuilder(Document document, Func<Document, String, String, Element> creator = null)
 {
     var resolver = document.Options.GetProvider<IEntityProvider>() ?? XmlEntityService.Resolver;
     _tokenizer = new XmlTokenizer(document.Source, resolver);
     _document = document;
     _standalone = false;
     _openElements = new List<Element>();
     _currentMode = XmlTreeMode.Initial;
     _creator = creator ?? CreateElement;
 }
Exemplo n.º 13
0
        public void ProductCatalogDtdComplete()
        {
            var s = new SourceManager(@"<!DOCTYPE CATALOG [

 <!ENTITY AUTHOR ""John Doe"">
 <!ENTITY COMPANY ""JD Power Tools, Inc."">
 <!ENTITY EMAIL ""*****@*****.**"">

 <!ELEMENT CATALOG (PRODUCT+)>

 <!ELEMENT PRODUCT
 (SPECIFICATIONS+,OPTIONS?,PRICE+,NOTES?)>
 <!ATTLIST PRODUCT
 NAME CDATA #IMPLIED
 CATEGORY (HandTool|Table|Shop-Professional) ""HandTool""
 PARTNUM CDATA #IMPLIED
 PLANT (Pittsburgh|Milwaukee|Chicago) ""Chicago""
 INVENTORY (InStock|Backordered|Discontinued) ""InStock"">

 <!ELEMENT SPECIFICATIONS (#PCDATA)>
 <!ATTLIST SPECIFICATIONS
 WEIGHT CDATA #IMPLIED
 POWER CDATA #IMPLIED>

 <!ELEMENT OPTIONS (#PCDATA)>
 <!ATTLIST OPTIONS
 FINISH (Metal|Polished|Matte) ""Matte""
 ADAPTER (Included|Optional|NotApplicable) ""Included""
 CASE (HardShell|Soft|NotApplicable) ""HardShell"">

 <!ELEMENT PRICE (#PCDATA)>
 <!ATTLIST PRICE
 MSRP CDATA #IMPLIED
 WHOLESALE CDATA #IMPLIED
 STREET CDATA #IMPLIED
 SHIPPING CDATA #IMPLIED>

 <!ELEMENT NOTES (#PCDATA)>

 ]>");
            var t = new XmlTokenizer(s);

            t.DTD.Reset();
            var e = t.Get();

            Assert.AreEqual(XmlTokenType.DOCTYPE, e.Type);
            var d = (XmlDoctypeToken)e;

            Assert.IsFalse(d.IsNameMissing);
            Assert.AreEqual("CATALOG", d.Name);
            Assert.IsTrue(d.IsSystemIdentifierMissing);
            Assert.AreEqual(13, t.DTD.Count);
        }
Exemplo n.º 14
0
        public void XmlTokenizerStringAndCustomEntityToken()
        {
            var resolver = new MockEntityProvider(str => str.Equals("bar;") ? "foo" : null);
            var s        = new TextSource("test&bar;");
            var t        = new XmlTokenizer(s, resolver);
            var test     = t.Get();
            var end      = t.Get();

            Assert.AreEqual(XmlTokenType.Character, test.Type);
            Assert.AreEqual("testfoo", ((XmlCharacterToken)test).Data);
            Assert.AreEqual(XmlTokenType.EndOfFile, end.Type);
        }
Exemplo n.º 15
0
        public void ValidXmlDeclarationVersionAndEncoding()
        {
            var s = new TextSource("<?xml version=\"1.1\" encoding=\"utf-8\" ?>");
            var t = new XmlTokenizer(s, null);
            var e = t.Get();

            Assert.AreEqual(XmlTokenType.Declaration, e.Type);
            var x = (XmlDeclarationToken)e;

            Assert.AreEqual("1.1", x.Version);
            Assert.IsFalse(x.IsEncodingMissing);
            Assert.AreEqual("utf-8", x.Encoding);
        }
Exemplo n.º 16
0
        public void OneDoctypeInXmlDocument()
        {
            var s = new TextSource("<!DOCTYPE root_element SYSTEM \"DTD_location\">");
            var t = new XmlTokenizer(s, null);
            var e = t.Get();

            Assert.AreEqual(XmlTokenType.Doctype, e.Type);
            var d = (XmlDoctypeToken)e;

            Assert.IsFalse(d.IsNameMissing);
            Assert.AreEqual("root_element", d.Name);
            Assert.IsFalse(d.IsSystemIdentifierMissing);
            Assert.AreEqual("DTD_location", d.SystemIdentifier);
        }
Exemplo n.º 17
0
        public void ValidXmlDeclarationEverything()
        {
            var s = new TextSource("<?xml version='1.0' encoding='ISO-8859-1' standalone=\"yes\" ?>");
            var t = new XmlTokenizer(s, null);
            var e = t.Get();

            Assert.AreEqual(XmlTokenType.Declaration, e.Type);
            var x = (XmlDeclarationToken)e;

            Assert.AreEqual("1.0", x.Version);
            Assert.IsFalse(x.IsEncodingMissing);
            Assert.AreEqual("ISO-8859-1", x.Encoding);
            Assert.AreEqual(true, x.Standalone);
        }
Exemplo n.º 18
0
        public void TestSubscriptionOfSingleObserver()
        {
            using (ITokenizer tokenizer = new XmlTokenizer(this.BaseStream))
            {
                Mock <IObserver <ReadOnlySequence <byte> > > observerMock = new Mock <IObserver <ReadOnlySequence <byte> > >();

                List <String> actualMessages = new List <String>();

                using (ManualResetEventSlim sync = new ManualResetEventSlim())
                {
                    observerMock.Setup(x => x.OnNext(It.IsAny <ReadOnlySequence <byte> >())).Callback((ReadOnlySequence <byte> token) =>
                    {
                        String message = XmlSerializationSettings.Encoding.GetString(token.ToArray());

                        actualMessages.Add(message);
                    });

                    observerMock.Setup(x => x.OnCompleted()).Callback(() =>
                    {
                        sync.Set();
                    });

                    using (IDisposable subscription = tokenizer.Subscribe(observerMock.Object))
                    {
                        sync.Wait();

                        // Number of calls depends on buffer size.
                        observerMock.Verify(x => x.OnNext(It.IsAny <ReadOnlySequence <byte> >()), Times.Exactly(this.Messages.Count));

                        Assert.AreEqual(actualMessages.Count, this.Messages.Count);

                        for (int i = 0; i < actualMessages.Count; i++)
                        {
                            String expected = this.Messages[i];
                            String actual   = actualMessages[i];

                            XmlComparer.AreEqual(expected, actual);
                        }

                        Assert.IsNotNull(subscription);
                    }
                }
            }
        }
Exemplo n.º 19
0
        public void WithDefaultTokenizationOptions_ShouldUseOptionsWhenSearchingWithNoTokenizerOptions()
        {
            var factory      = new Mock <ITokenizerFactory>();
            var tokenizer    = new FakeTokenizer();
            var xmlTokenizer = new XmlTokenizer();

            factory.Setup(f => f.Create(It.Is <TokenizationOptions>(o => o.TokenizerKind == TokenizerKind.XmlContent))).Returns(xmlTokenizer);
            factory.Setup(f => f.Create(It.Is <TokenizationOptions>(o => o.TokenizerKind == TokenizerKind.PlainText))).Returns(tokenizer);
            var parser = this.ConfigureQueryParserMock();

            this.sut.WithTokenizerFactory(factory.Object);
            this.sut.WithDefaultTokenizationOptions(o => o.XmlContent());

            var index = this.sut.Build();

            index.Search("test").Should().BeEmpty();
            index.Search("test with tokenization options", TokenizationOptions.Default).Should().BeEmpty();
            parser.Verify(p => p.Parse(It.IsAny <IIndexedFieldLookup>(), "test", xmlTokenizer), Times.Once);
            parser.Verify(p => p.Parse(It.IsAny <IIndexedFieldLookup>(), "test with tokenization options", tokenizer), Times.Once);
        }
Exemplo n.º 20
0
        public void TestSubscriptionOfMultipleObservers()
        {
            using (ITokenizer tokenizer = new XmlTokenizer(this.BaseStream, Diagnostics.NullInteractionLog.Instance, bufferSize: 16, XmlSerializationSettings.MaximumMessageSize))
            {
                Mock <IObserver <ReadOnlySequence <byte> > > observerMockFirst  = new();
                Mock <IObserver <ReadOnlySequence <byte> > > observerMockSecond = new();

                using (ManualResetEventSlim observerMockFirstSync = new ManualResetEventSlim())
                {
                    using (ManualResetEventSlim observerMockSecondSync = new ManualResetEventSlim())
                    {
                        observerMockFirst.Setup(x => x.OnCompleted()).Callback(() =>
                        {
                            observerMockFirstSync.Set();
                        });

                        observerMockSecond.Setup(x => x.OnCompleted()).Callback(() =>
                        {
                            observerMockSecondSync.Set();
                        });

                        IConnectableObservable <ReadOnlySequence <byte> > observable = (from token in tokenizer
                                                                                        select token).Publish();

                        observable.Subscribe(observerMockFirst.Object);
                        observable.Subscribe(observerMockSecond.Object);

                        observable.Connect();

                        observerMockFirstSync.Wait();
                        observerMockSecondSync.Wait();

                        // Number of calls depends on buffer size.
                        observerMockFirst.Verify(x => x.OnNext(It.IsAny <ReadOnlySequence <byte> >()), Times.AtLeast(this.Messages.Count));
                        observerMockSecond.Verify(x => x.OnNext(It.IsAny <ReadOnlySequence <byte> >()), Times.AtLeast(this.Messages.Count));
                    }
                }
            }
        }
Exemplo n.º 21
0
        public void TVScheduleDtdSubset()
        {
            var dtd  = @"<!ELEMENT TVSCHEDULE (CHANNEL+)>
 <!ELEMENT CHANNEL (BANNER,DAY+)>
 <!ELEMENT BANNER (#PCDATA)>
 <!ELEMENT DAY (DATE,(HOLIDAY|PROGRAMSLOT+)+)>
 <!ELEMENT HOLIDAY (#PCDATA)>
 <!ELEMENT DATE (#PCDATA)>
 <!ELEMENT PROGRAMSLOT (TIME,TITLE,DESCRIPTION?)>
 <!ELEMENT TIME (#PCDATA)>
 <!ELEMENT TITLE (#PCDATA)> 
 <!ELEMENT DESCRIPTION (#PCDATA)>

 <!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED>
 <!ATTLIST CHANNEL CHAN CDATA #REQUIRED>
 <!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED>
 <!ATTLIST TITLE RATING CDATA #IMPLIED>
 <!ATTLIST TITLE LANGUAGE CDATA #IMPLIED>";
            var text = "<!DOCTYPE TVSCHEDULE [" + dtd + "]>";
            var s    = new SourceManager(text);

            var t = new XmlTokenizer(s);

            t.DTD.Reset();
            var e = t.Get();

            Assert.AreEqual(XmlTokenType.DOCTYPE, e.Type);
            var d = (XmlDoctypeToken)e;

            Assert.IsFalse(d.IsNameMissing);
            Assert.AreEqual("TVSCHEDULE", d.Name);
            Assert.IsTrue(d.IsSystemIdentifierMissing);
            Assert.AreEqual(15, t.DTD.Count);

            //Unfortunately C# counts newlines with 2 characters since \r\n is used
            Assert.AreEqual(dtd.Replace("\r\n", "\n"), d.InternalSubset);
            //This is annoying but meh - what can we do? W3C specifies we need to use
            //\n for newlines and omit \r completely.
        }
Exemplo n.º 22
0
 /// <summary>
 /// Tries to write XML.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="xmlWriter">The XML writer.</param>
 /// <param name="value">The value.</param>
 /// <param name="args">The args.</param>
 /// <returns></returns>
 public static bool TryWriteXml <T>(XmlWriter xmlWriter, T value, TokenizerArgs args)
     where T : class, new()
 {
     return(XmlTokenizer <T> .TryWrite(xmlWriter, value, args));
 }
Exemplo n.º 23
0
 public void XmlTokenizerStringAndCustomEntityToken()
 {
     var resolver = new MockEntityResolver(str => str.Equals("bar") ? "foo" : null);
     var s = new TextSource("test&bar;");
     var t = new XmlTokenizer(s, null, resolver);
     var test = t.Get();
     var end = t.Get();
     Assert.AreEqual(XmlTokenType.Character, test.Type);
     Assert.AreEqual("testfoo", ((XmlCharacterToken)test).Data);
     Assert.AreEqual(XmlTokenType.EndOfFile, end.Type);
 }
Exemplo n.º 24
0
        public void XmlWorkSplittingNew()
        {
            var splitter = new XmlTokenizer();

            splitter.Process(WikipediaData.SampleData[0].text).ToList();
        }
Exemplo n.º 25
0
        public void TVScheduleDtdComplete()
        {
            var dtd = @"<!DOCTYPE TVSCHEDULE [

 <!ELEMENT TVSCHEDULE (CHANNEL+)>
 <!ELEMENT CHANNEL (BANNER,DAY+)>
 <!ELEMENT BANNER (#PCDATA)>
 <!ELEMENT DAY (DATE,(HOLIDAY|PROGRAMSLOT+)+)>
 <!ELEMENT HOLIDAY (#PCDATA)>
 <!ELEMENT DATE (#PCDATA)>
 <!ELEMENT PROGRAMSLOT (TIME,TITLE,DESCRIPTION?)>
 <!ELEMENT TIME (#PCDATA)>
 <!ELEMENT TITLE (#PCDATA)> 
 <!ELEMENT DESCRIPTION (#PCDATA)>

 <!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED>
 <!ATTLIST CHANNEL CHAN CDATA #REQUIRED>
 <!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED>
 <!ATTLIST TITLE RATING CDATA #IMPLIED>
 <!ATTLIST TITLE LANGUAGE CDATA #IMPLIED>
 ]>";
            var s   = new SourceManager(dtd);

            var t = new XmlTokenizer(s);

            t.DTD.Reset();
            var e = t.Get();

            Assert.IsTrue(t.DTD[0] is ElementDeclaration);

            var f1 = (t.DTD[0] as ElementDeclaration);

            Assert.AreEqual("TVSCHEDULE", f1.Name);
            Assert.AreEqual(ElementContentType.Children, f1.Entry.Type);
            Assert.IsTrue(f1.Entry is ElementChoiceDeclarationEntry);

            var g1 = (f1.Entry as ElementChoiceDeclarationEntry);

            Assert.AreEqual(ElementQuantifier.One, g1.Quantifier);
            Assert.AreEqual(1, g1.Choice.Count);
            Assert.IsTrue(g1.Choice[0] is ElementNameDeclarationEntry);

            var h1 = (g1.Choice[0] as ElementNameDeclarationEntry);

            Assert.AreEqual(ElementQuantifier.OneOrMore, h1.Quantifier);
            Assert.AreEqual("CHANNEL", h1.Name);

            Assert.IsTrue(t.DTD[3] is ElementDeclaration);

            var f2 = (t.DTD[3] as ElementDeclaration);

            Assert.AreEqual("DAY", f2.Name);
            Assert.AreEqual(ElementContentType.Children, f2.Entry.Type);
            Assert.IsTrue(f2.Entry is ElementSequenceDeclarationEntry);

            var g2 = (f2.Entry as ElementSequenceDeclarationEntry);

            Assert.AreEqual(ElementQuantifier.One, g2.Quantifier);
            Assert.AreEqual(2, g2.Sequence.Count);
            Assert.AreEqual(ElementQuantifier.One, g2.Sequence[0].Quantifier);
            Assert.AreEqual(ElementQuantifier.OneOrMore, g2.Sequence[1].Quantifier);
            Assert.IsTrue(g2.Sequence[0] is ElementNameDeclarationEntry);
            Assert.IsTrue(g2.Sequence[1] is ElementChoiceDeclarationEntry);

            var g3 = (g2.Sequence[0] as ElementNameDeclarationEntry);
            var g4 = (g2.Sequence[1] as ElementChoiceDeclarationEntry);

            Assert.AreEqual("DATE", g3.Name);
            Assert.AreEqual(2, g4.Choice.Count);
            Assert.IsTrue(g4.Choice[0] is ElementNameDeclarationEntry);
            Assert.IsTrue(g4.Choice[1] is ElementNameDeclarationEntry);

            var g5 = (g4.Choice[0] as ElementNameDeclarationEntry);
            var g6 = (g4.Choice[1] as ElementNameDeclarationEntry);

            Assert.AreEqual("HOLIDAY", g5.Name);
            Assert.AreEqual("PROGRAMSLOT", g6.Name);
            Assert.AreEqual(ElementQuantifier.One, g5.Quantifier);
            Assert.AreEqual(ElementQuantifier.OneOrMore, g6.Quantifier);

            Assert.IsTrue(t.DTD[10] is AttributeDeclaration);
            var f7 = (t.DTD[10] as AttributeDeclaration);

            Assert.AreEqual("TVSCHEDULE", f7.Name);
            Assert.AreEqual(1, f7.Count);
            Assert.AreEqual("NAME", f7[0].Name);
            Assert.IsInstanceOfType(f7[0].Type, typeof(AttributeStringType));
            Assert.IsInstanceOfType(f7[0].Default, typeof(AttributeRequiredValue));
        }
Exemplo n.º 26
0
 public XmlTokenizerTests()
 {
     this.sut = new XmlTokenizer();
     ((ITokenizer)this.sut).Configure(TokenizationOptions.Default);
 }