Пример #1
0
        public void NodeReaderReadContentAsBase64WithEmptyXml()
        {
            var xmlDoc     = new XmlDocument();
            var nodeReader = new XmlNodeReader(xmlDoc);

            Assert.Equal(0, nodeReader.ReadContentAsBase64(null, 0, 0));
            Assert.Equal(0, nodeReader.ReadContentAsBase64(new byte[22], 10, 10));
        }
Пример #2
0
        public void NodeReaderReadContentAsBase64WithSimpleXml()
        {
            byte[]        byteData   = Encoding.ASCII.GetBytes("hello world");
            string        xml        = $"<root attr='{Convert.ToBase64String(byteData)}'><child /></root>"; //hello world encoded
            XmlNodeReader nodeReader = NodeReaderTestHelper.CreateNodeReader(xml);

            Assert.True(nodeReader.Read());
            Assert.Equal("root", nodeReader.Name);
            Assert.True(nodeReader.MoveToAttribute("attr"));
            Assert.True(nodeReader.CanReadBinaryContent);
            var resultArr = new byte[byteData.Length];

            Assert.Equal(byteData.Length, nodeReader.ReadContentAsBase64(resultArr, 0, byteData.Length));
            Assert.Equal(byteData, resultArr);
            Assert.Equal("hello world", Encoding.ASCII.GetString(resultArr));
            Assert.Equal(0, nodeReader.ReadContentAsBase64(new byte[33], 10, 10));
        }
        public void NodeReaderMoveToAttributeWithAttributeXml()
        {
            string        xml        = "<root catr='tal' xmlns:attr='cal' fatr='gal' xmlns:attr2='val'></root>";
            XmlNodeReader nodeReader = NodeReaderTestHelper.CreateNodeReader(xml);

            Assert.True(nodeReader.Read());
            Assert.True(nodeReader.MoveToAttribute("catr"));
            Assert.True(nodeReader.MoveToAttribute("attr", "http://www.w3.org/2000/xmlns/"));
            nodeReader.MoveToAttribute(0);

            nodeReader.ReadContentAsBase64(new byte[33], 10, 10);
            Assert.True(nodeReader.MoveToAttribute("fatr"));
            nodeReader.ReadContentAsBase64(new byte[33], 10, 10);
            Assert.True(nodeReader.MoveToAttribute("attr2", "http://www.w3.org/2000/xmlns/"));
            nodeReader.ReadContentAsBase64(new byte[33], 10, 10);
            nodeReader.MoveToAttribute(1);
        }
        public void NodeReaderMoveToNextAttributeWithAttributeXml()
        {
            string        xml        = "<root attr='cal' attr2='val'></root>";
            XmlNodeReader nodeReader = NodeReaderTestHelper.CreateNodeReader(xml);

            Assert.True(nodeReader.Read());
            Assert.True(nodeReader.MoveToNextAttribute());

            nodeReader.ReadContentAsBase64(new byte[33], 10, 10);
            Assert.True(nodeReader.MoveToNextAttribute());
        }
        public void NodeReaderMoveToElementWithSimpleXml()
        {
            string        xml        = "<root attr='cal'><child attr='val'><inner attr='val'></inner></child></root>";
            XmlNodeReader nodeReader = NodeReaderTestHelper.CreateNodeReader(xml);

            Assert.True(nodeReader.Read());
            nodeReader.MoveToFirstAttribute();
            Assert.True(nodeReader.MoveToElement());
            Assert.True(nodeReader.MoveToAttribute("attr"));
            nodeReader.ReadContentAsBase64(new byte[33], 10, 10);
            Assert.True(nodeReader.MoveToElement());
        }