public void Convert_FromDocumentModelToXDocument()
        {
            var model        = MockAssets.SeedDocumentTestDocument();
            var expectedXDoc = MockAssets.SeedXDocumentDocument(model);

            var actualXDocument = _sut.Convert(model);

            actualXDocument.Should().BeEquivalentTo(expectedXDoc);
        }
        public void TestXml()
        {
            // Arrange
            Parser   parser    = new Parser();
            Text     text      = parser.Parse(@"Mary had a little lamb. Peter called for the wolf, and Aesop came.
                 Cinderella likes shoes.");
            IConvert converter = new XmlConverter();

            // Act
            string      xml = converter.Convert(text);
            XmlDocument xd  = new XmlDocument();

            xd.LoadXml(xml);

            // Assert
            Assert.AreEqual(2, xd.ChildNodes.Count);
            Assert.AreEqual("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>",
                            xd.ChildNodes[0].OuterXml);

            Assert.AreEqual("<sentence><word>a</word><word>had</word><word>lamb</word><word>little</word><word>Mary</word></sentence>",
                            xd.ChildNodes[1].ChildNodes[0].OuterXml);
            Assert.AreEqual("<sentence><word>Aesop</word><word>and</word><word>called</word><word>came</word><word>for</word><word>Peter</word><word>the</word><word>wolf</word></sentence>",
                            xd.ChildNodes[1].ChildNodes[1].OuterXml);
            Assert.AreEqual("<sentence><word>Cinderella</word><word>likes</word><word>shoes</word></sentence>",
                            xd.ChildNodes[1].ChildNodes[2].OuterXml);
        }
Exemple #3
0
        public void CustomInsertTypesRenderAsBlock()
        {
            var ops = JArray.Parse(@"[
               {insert: 'hello '},
               { insert: { myblot: 'my friend' } },
               { insert: '!' },
               {insert: {myblot: 'how r u?'}, attributes: {renderAsBlock: true}}
            ]");
            XmlCustomRenderer renderer = (doc, op, contextOp) =>
            {
                var insert = (InsertDataCustom)op.Insert;
                if (insert.CustomType == "myblot")
                {
                    var textNode = doc.CreateTextNode(insert.Value.ToString());
                    if (op.Attributes.RenderAsBlock == true)
                    {
                        var div = doc.CreateElement("div");
                        div.AppendChild(textNode);
                        return(div);
                    }
                    return(textNode);
                }
                return(doc.CreateTextNode("unknown"));
            };
            var qdc = new XmlConverter(ops,
                                       new XmlConverterOptions {
                CustomRenderer = renderer
            });
            var xml = qdc.Convert().OuterXml;

            xml.Should().Be("<template><p>hello my friend!</p><div>how r u?</div></template>");
        }
Exemple #4
0
        public fo.DicomDataset Convert(Stream xmlStream)
        {
            StreamReader reader    = new StreamReader(xmlStream);
            string       xmlString = reader.ReadToEnd( );

            return(XmlConverter.Convert(xmlString));
        }
Exemple #5
0
        public void CheckedAndUncheckedLists()
        {
            var ops4 = JArray.Parse(@"[
                { insert: ""hello"" },
                { insert: ""\n"", attributes: { list: 'checked' } },
                { insert: ""there"" },
                { insert: ""\n"", attributes: { list: 'unchecked' } },
                { insert: ""man"" },
                { insert: ""\n"", attributes: { list: 'checked' } },
                { insert: 'not done'},
                { insert: ""\n"", attributes: {indent:1, list: 'unchecked'}}
             ]");
            var qdc  = new XmlConverter(ops4);
            var xml  = qdc.Convert().OuterXml;

            xml.Should().Be(
                "<template>" +
                "<ul>" +
                "<li data-checked=\"true\">hello</li>" +
                "<li data-checked=\"false\">there</li>" +
                "<li data-checked=\"true\">man" +
                "<ul><li data-checked=\"false\">not done</li></ul>" +
                "</li>" +
                "</ul>" +
                "</template>");
        }
Exemple #6
0
        public void Convert_OnBasicXml_OnElementWithAttribute_ShouldConvert()
        {
            const string xml = @"<el att=""value"" />";
            dynamic      act = XmlConverter.Convert(XDocument.Parse(xml));

            ((string)act.el.att).Should().Be("value");
        }
Exemple #7
0
        public void Convert_OnBasicXml_OnElementWithValue_ShouldConvert()
        {
            const string xml = @"<el>value</el>";
            dynamic      act = XmlConverter.Convert(XDocument.Parse(xml));

            ((string)act.el).Should().Be("value");
        }
Exemple #8
0
        public void Convert_OnBasicXml_OnElementAndAttributeWithTheSameName_ShouldConvert()
        {
            const string xml = @"<test test=""value1"">value2</test>";
            dynamic      act = XmlConverter.Convert(XDocument.Parse(xml));

            ((string)act.test.test).Should().Be("value1");
        }
Exemple #9
0
        public void Convert_Media()
        {
            Library library = Library.InstantiateLibrary();
            Media   media   = library.Create(Media.InstantiateOrphanedMedia(MediaType.Book, "Refactoring", "Programming"));

            Console.WriteLine(ConvertXmlDocumentToString(XmlConverter.Convert(media)));
        }
Exemple #10
0
        public void CustomBlotUsesGivenRenderer()
        {
            var ops = JArray.Parse(@"[
                { insert: { bolditalic: 'my text' } },
                { insert: { blah: 1 } }
             ]");
            XmlCustomRenderer renderer = (doc, op, contextOp) =>
            {
                var insert = (InsertDataCustom)op.Insert;
                if (insert.CustomType == "bolditalic")
                {
                    var b = doc.CreateElement("b");
                    var i = b.AppendChild(doc.CreateElement("i"))
                            .AppendChild(doc.CreateTextNode(
                                             insert.Value.ToString()));
                    return(b);
                }
                return(doc.CreateTextNode("unknown"));
            };
            var qdc = new XmlConverter(ops,
                                       new XmlConverterOptions {
                CustomRenderer = renderer
            });
            var xml = qdc.Convert().OuterXml;

            xml.Should().Be("<template><p><b><i>my text</i></b>unknown</p></template>");
        }
        private void XmbToXmlInDirectories(string[] dirs)
        {
            ClearMessages();
            IsProcessing = true;

            var task = Task.Run(() =>
            {
                var converter = new XmlConverter(XmlConverterMode.XmbToXml, this);
                converter.SearchDirectoriesForInputFiles(dirs);
                converter.Convert();
            });

            var scheduler = TaskScheduler.FromCurrentSynchronizationContext();

            task.ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    MessagesText += string.Format("XMB->XML failure {0}{1}",
                                                  Environment.NewLine, t.Exception.GetOnlyExceptionOrAll());
                }

                FinishProcessing();
            }, scheduler);
        }
Exemple #12
0
        public void BeforeRenderCalledWithBlockGroupTypeForAlignIndentAndDirection()
        {
            var ops = JArray.Parse(@"[
                { insert: 'align' },
                { insert: '\n', attributes: { align: 'right' } },
                { insert: 'rtl' },
                { insert: '\n', attributes: { direction: 'rtl' } },
                { insert: 'indent 1' },
                { insert: '\n', attributes: { indent: 1 } },
            ]");

            int blockCount = 0;
            XmlBeforeRenderer beforeRenderer = (doc, gtype, group) =>
            {
                if (gtype == GroupType.Block)
                {
                    ++blockCount;
                }
                return(null);
            };

            var qdc = new XmlConverter(ops,
                                       new XmlConverterOptions()
            {
                BeforeRenderer = beforeRenderer
            });

            qdc.Convert();
            blockCount.Should().Be(3);
        }
Exemple #13
0
        public void CustomRenderCallbacksAreUsed()
        {
            var ops = JArray.Parse(
                "[{ insert: { video: \"http\" } }, { insert: 'aa' }]");

            var qdc = new XmlConverter(ops);
            var xml = qdc.Convert().OuterXml;

            xml.Should().Contain("iframe");

            qdc = new XmlConverter(ops,
                                   new XmlConverterOptions
            {
                BeforeRenderer = (doc, gt, g) => null
            });
            xml = qdc.Convert().OuterXml;
            xml.Should().Contain("<iframe");
            xml.Should().Contain("aa");

            qdc = new XmlConverter(ops,
                                   new XmlConverterOptions
            {
                AfterRenderer = (doc, gt, g) => null
            });
            xml = qdc.Convert().OuterXml;
            xml.Should().Be("<template />");
        }
Exemple #14
0
        void RunTest(string c_code, string expectedXml)
        {
            StringReader reader = null;
            StringWriter writer = null;

            try
            {
                reader = new StringReader(c_code);
                writer = new StringWriter();
                var xWriter = new XmlnsHidingWriter(writer)
                {
                    Formatting = Formatting.Indented
                };
                var xc = new XmlConverter(reader, xWriter);
                xc.Convert();
                writer.Flush();
                Assert.AreEqual(expectedXml, writer.ToString());
            }
            catch
            {
                Debug.WriteLine(writer.ToString());
                throw;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Dispose();
                }
                if (reader != null)
                {
                    reader.Dispose();
                }
            }
        }
        public async Task HappyPath_ManyUniquePrnsGeneratedAndSeedUpdatedToExpectedValue()
        {
            // arrange
            var validXmlLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), @"ExampleXML\v3-valid-many-insertions.xml");
            var validXmlString   = File.ReadAllText(new Uri(validXmlLocation).LocalPath);
            var validXmlBytes    = File.ReadAllBytes(new Uri(validXmlLocation).LocalPath);

            using (var database = new DatabaseWrapper())
            {
                var modelHelper = new ModelHelper(database.Model);

                var org          = modelHelper.CreateOrganisation();
                var scheme       = modelHelper.CreateScheme(org);
                var memberUpload = modelHelper.CreateMemberUpload(scheme);

                var message = new ProcessXmlFile(org.Id, validXmlBytes, "File name");

                var initialSeed  = database.WeeeContext.SystemData.Select(sd => sd.LatestPrnSeed).First();
                var expectedSeed = ExpectedSeedAfterThisXml(validXmlString, initialSeed);

                var whiteSpaceCollapser = A.Fake <IWhiteSpaceCollapser>();

                var xmlConverter = new XmlConverter(whiteSpaceCollapser, new Deserializer());
                var schemeType   = xmlConverter.Deserialize <schemeType>(xmlConverter.Convert(message.Data));

                var producerCharges     = new Dictionary <string, ProducerCharge>();
                var anyAmount           = 30;
                var anyChargeBandAmount = A.Dummy <ChargeBandAmount>();

                foreach (var producerData in schemeType.producerList)
                {
                    var producerName = producerData.GetProducerName();
                    if (!producerCharges.ContainsKey(producerName))
                    {
                        producerCharges.Add(producerName,
                                            new ProducerCharge {
                            Amount = anyAmount, ChargeBandAmount = anyChargeBandAmount
                        });
                    }
                }

                database.Model.SaveChanges();

                var contextMemberUpload = database.WeeeContext.MemberUploads
                                          .Single(mu => mu.Id == memberUpload.Id);

                // act
                var producers = await new GenerateFromXml(
                    xmlConverter,
                    new GenerateFromXmlDataAccess(database.WeeeContext)).GenerateProducers(message, contextMemberUpload, producerCharges);

                // assert
                long newSeed = database.WeeeContext.SystemData.Select(sd => sd.LatestPrnSeed).First();
                Assert.Equal(expectedSeed, newSeed);

                var prns = producers.Select(p => p.RegisteredProducer.ProducerRegistrationNumber);
                Assert.Equal(prns.Distinct(), prns); // all prns should be unique
            }
        }
Exemple #16
0
        public void CodeBlockOneLine()
        {
            var qdc = new XmlConverter(new JArray(
                                           _codeBlockOps[0], _codeBlockOps[1]));
            var xml = qdc.Convert().OuterXml;

            xml.Should().Be("<template><pre>line 1</pre></template>");
        }
Exemple #17
0
        public void Convert_OnBasicXml_OnNestedElements_ShouldConvert()
        {
            const string xml = @"<main><el1 att=""el1_att_value"" /><el2 att=""el2_att_value"" /></main>";
            dynamic      act = XmlConverter.Convert(XDocument.Parse(xml));

            ((string)act.main.el1.att).Should().Be("el1_att_value");
            ((string)act.main.el2.att).Should().Be("el2_att_value");
        }
        public async Task HappyPath_ManyUniquePrnsGeneratedAndSeedUpdatedToExpectedValue()
        {
            // arrange
            var validXmlLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), @"ExampleXML\v3-valid-many-insertions.xml");
            var validXmlString = File.ReadAllText(new Uri(validXmlLocation).LocalPath);
            var validXmlBytes = File.ReadAllBytes(new Uri(validXmlLocation).LocalPath);

            using (var database = new DatabaseWrapper())
            {
                var modelHelper = new ModelHelper(database.Model);

                var org = modelHelper.CreateOrganisation();
                var scheme = modelHelper.CreateScheme(org);
                var memberUpload = modelHelper.CreateMemberUpload(scheme);

                var message = new ProcessXmlFile(org.Id, validXmlBytes, "File name");

                var initialSeed = database.WeeeContext.SystemData.Select(sd => sd.LatestPrnSeed).First();
                var expectedSeed = ExpectedSeedAfterThisXml(validXmlString, initialSeed);

                var whiteSpaceCollapser = A.Fake<IWhiteSpaceCollapser>();

                var xmlConverter = new XmlConverter(whiteSpaceCollapser, new Deserializer());
                var schemeType = xmlConverter.Deserialize<schemeType>(xmlConverter.Convert(message.Data));

                var producerCharges = new Dictionary<string, ProducerCharge>();
                var anyAmount = 30;
                var anyChargeBandAmount = A.Dummy<ChargeBandAmount>();

                foreach (var producerData in schemeType.producerList)
                {
                    var producerName = producerData.GetProducerName();
                    if (!producerCharges.ContainsKey(producerName))
                    {
                        producerCharges.Add(producerName,
                            new ProducerCharge { Amount = anyAmount, ChargeBandAmount = anyChargeBandAmount });
                    }
                }

                database.Model.SaveChanges();

                var contextMemberUpload = database.WeeeContext.MemberUploads
                    .Single(mu => mu.Id == memberUpload.Id);

                // act
                var producers = await new GenerateFromXml(
                    xmlConverter,
                    new GenerateFromXmlDataAccess(database.WeeeContext)).GenerateProducers(message, contextMemberUpload, producerCharges);

                // assert
                long newSeed = database.WeeeContext.SystemData.Select(sd => sd.LatestPrnSeed).First();
                Assert.Equal(expectedSeed, newSeed);

                var prns = producers.Select(p => p.RegisteredProducer.ProducerRegistrationNumber);
                Assert.Equal(prns.Distinct(), prns); // all prns should be unique
            }
        }
Exemple #19
0
        public void PositionalStylesUseDefaultTag()
        {
            var qdc = new XmlConverter(_posOps);
            var xml = qdc.Convert().OuterXml;

            xml.Should().Contain("<p class=\"ql-align");
            xml.Should().Contain("<p class=\"ql-direction");
            xml.Should().Contain("<p class=\"ql-indent");
        }
        public void Convert_Xml_InvalidInput_Test()
        {
            string     input        = "**876769898.898&*$$$$980";
            IConverter xmlConverter = new XmlConverter(logger);
            string     result       = xmlConverter.Convert(input);
            XDocument  xDoc         = XDocument.Parse(result);

            Assert.IsNotNull(xDoc);
            Assert.IsFalse(xDoc.XPathSelectElements("/text/sentence").Count() > 0);
        }
Exemple #21
0
        public void TargetAttrDefaultLinkTarget()
        {
            var qdc = new XmlConverter(_targetOps);
            var xml = qdc.Convert().OuterXml;

            xml.Should().Be(
                "<template><p><a href=\"http://#\" target=\"_self\">A</a>" +
                "<a href=\"http://#\" target=\"_blank\">B</a>" +
                "<a href=\"http://#\" target=\"_blank\">C</a></p></template>");
        }
Exemple #22
0
        public void CodeBlockSimple()
        {
            //console.log(encodeHtml("<p>line 4</p>"));
            var qdc = new XmlConverter(_codeBlockOps);
            var xml = qdc.Convert().OuterXml;

            xml.Should().Be("<template><pre>line 1\nline 2\nline 3\n" +
                            XmlHelpers.EncodeXml("<p>line 4</p>") +
                            "</pre></template>");
        }
Exemple #23
0
        public void CustomBlotEmptyStringWithNoRenderer()
        {
            var ops = JArray.Parse(@"[
                { insert: { customstuff: 'my val' } }
            ]");
            var qdc = new XmlConverter(ops);
            var xml = qdc.Convert().OuterXml;

            xml.Should().Be("<template><p /></template>");
        }
        public void AddData <T>(T dataObject, string resourceName, string id)
        {
            var resourceCacheLocation = CacheFilePath + resourceName + id + CacheFileExtension;

            using (var streamWriter = new StreamWriter(resourceCacheLocation))
            {
                IObjectConverter objectConverter = new XmlConverter();
                streamWriter.WriteLine(objectConverter.Convert(dataObject).ResultString);
                streamWriter.Close();
            }
        }
        public void Convert_Xml_Working_Test()
        {
            string     input        = "I am writing simple sentence.";
            IConverter xmlConverter = new XmlConverter(logger);
            string     result       = xmlConverter.Convert(input);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Length > 0);
            Assert.IsTrue(result.Contains("I") && result.Contains("am") && result.Contains("writing") &&
                          result.Contains("simple") && result.Contains("sentence"));
        }
        public void Convert_Xml_CheckFullResult_ThreeSentences_Test()
        {
            string     input        = "I am writing simple sentence. Its done now. It seems to be very cloudy outside.";
            IConverter xmlConverter = new XmlConverter(logger);
            string     result       = xmlConverter.Convert(input);

            Assert.IsNotNull(result);
            XDocument xDoc = XDocument.Parse(result);

            Assert.IsTrue(xDoc.XPathSelectElements("/text/sentence").Count() == 3);
        }
Exemple #27
0
        public void ConstructorSetsDefaultInlineStyles()
        {
            var qdc = new XmlConverter(_hugeOps,
                                       new XmlConverterOptions()
            {
                InlineStyles = new InlineStyles()
            });
            var xml = qdc.Convert().OuterXml;

            xml.Should().Contain("<span style=\"font-size: 2.5em\">huge</span>");
        }
Exemple #28
0
        public void CustomInsertTypesInCodeBlocks()
        {
            var qdc = new XmlConverter(new JArray(
                                           _customTypeCodeBlockOps[0], _customTypeCodeBlockOps[1]),
                                       new XmlConverterOptions {
                CustomRenderer = _customTypeCodeBlockRenderer
            });
            var xml = qdc.Convert().OuterXml;

            xml.Should().Be("<template><pre>:</pre></template>");
        }
Exemple #29
0
        public void CodeBlockNoMultiline()
        {
            var qdc = new XmlConverter(_codeBlockOps,
                                       new XmlConverterOptions {
                MultiLineCodeblock = false
            });
            var xml = qdc.Convert().OuterXml;

            xml.Should().Be(
                "<template><pre>line 1</pre><pre>line 2</pre><pre>line 3</pre>" +
                "<pre>" + XmlHelpers.EncodeXml("<p>line 4</p>") + "</pre></template>");
        }
Exemple #30
0
        public void ConstructorReturnsProperXml()
        {
            var qdc = new XmlConverter(_deltaOps,
                                       new XmlConverterOptions
            {
                ClassPrefix = "noz"
            }
                                       );
            var xml = qdc.Convert().OuterXml;

            xml.Should().Be(_deltaXml);
        }
Exemple #31
0
        public void CustomInsertTypesInHeaders2()
        {
            var qdc = new XmlConverter(
                _customTypeHeaderOps,
                new XmlConverterOptions()
            {
                CustomRenderer = _customTypeHeaderRenderer
            });
            var xml = qdc.Convert().OuterXml;

            xml.Should().Be("<template><h1>:<br />hello<br />:</h1></template>");
        }
Exemple #32
0
 public void ConvertNodeWithoutAttributes(string input, string expected)
 {
     var sut = new XmlConverter(attributeBullet: null);
     var output = sut.Convert(input);
     Assert.AreEqual(expected, output);
 }
Exemple #33
0
 public void ConvertNode(string input, string expected)
 {
     var sut = new XmlConverter();
     var output = sut.Convert(input);
     Assert.AreEqual(expected, output);
 }