public void GetLanguage_WithValidXmlInputString_ShouldReturnXml()
        {
            string inputString = "<xml>Test</xml>";

            Assert.AreEqual(MsBuildHelpCodeBlockLanguage.Xml,
                            MsBuildElementHelpCodeBlockUtility.GetLanguage(inputString));
        }
        public void Decode_WithStartAndEndIdentifierWithPowerShellCommentConvention_ShouldReplaceWithProperXmlComment()
        {
            string inputString    = "<# This is an encoded xml comment #>";
            string expectedString = "<!-- This is an encoded xml comment -->";

            Assert.AreEqual(expectedString, MsBuildElementHelpCodeBlockUtility.Decode(inputString));
        }
        public void Decode_WithStartAndEndIdentifierRepresentedByHtmlEncoded_ShouldDecode()
        {
            string inputString    = "&lt;!-- This is an encoded xml comment --&gt;";
            string expectedString = "<!-- This is an encoded xml comment -->";

            Assert.AreEqual(expectedString, MsBuildElementHelpCodeBlockUtility.Decode(inputString));
        }
        public void GetLanguage_WithValidXmlInputStringStartingWithComment_ShouldReturnXml()
        {
            string inputString = "<!-- This is a xml comment --><xml>Test</xml>";

            Assert.AreEqual(MsBuildHelpCodeBlockLanguage.Xml,
                            MsBuildElementHelpCodeBlockUtility.GetLanguage(inputString));
        }
        public void GetLanguage_WithInvalidXmlInputStringEndingWithComment_ShouldReturnBatch()
        {
            string inputString = "<xml>Test<xml><!-- This is a xml comment -->";

            Assert.AreEqual(MsBuildHelpCodeBlockLanguage.Sh,
                            MsBuildElementHelpCodeBlockUtility.GetLanguage(inputString));
        }
        public void Decode_WithStartAndEndIdentifierWithTildeAsMinus_ShouldReplaceTildeWithMinus()
        {
            string inputString    = "<!~~ This is an encoded xml comment ~~>";
            string expectedString = "<!-- This is an encoded xml comment -->";

            Assert.AreEqual(expectedString, MsBuildElementHelpCodeBlockUtility.Decode(inputString));
        }
        public void GetLanguage_WithMsBuildCommandLineCall_ShouldReturnBatch()
        {
            string inputString = "msbuild.exe test.targets /t:Print /p:File='C:/doc.txt'";

            Assert.AreEqual(MsBuildHelpCodeBlockLanguage.Sh,
                            MsBuildElementHelpCodeBlockUtility.GetLanguage(inputString));
        }
        public void Parse_WithBatchInput_ShouldReturnObjectWithLanguageSh()
        {
            string xmlInput = "msbuild test.targets /t:CallTest";

            MsBuildHelpElementCodeBlock codeBlock = MsBuildElementHelpCodeBlockUtility.Parse(xmlInput);

            Assert.AreEqual(MsBuildHelpCodeBlockLanguage.Sh, codeBlock.Language);
        }
        public void FormatXml_WithValidXmlInputStringInOneRowAndCommentOnTheEnd_ShouldReturnFormattedXml()
        {
            string inputString    = "<xml><node id='1'>Test</node></xml><!-- This is a xml comment -->";
            string expectedString = "<xml>\n  <node\n    id=\"1\">Test</node>\n</xml>\n<!-- This is a xml comment -->";

            Assert.AreEqual(expectedString,
                            MsBuildElementHelpCodeBlockUtility.FormatXml(inputString));
        }
        public void Parse_WithValidEncodedXmlCommentInput_ShouldDecodeStringContent()
        {
            string xmlInput = "<!~~ Test ~~>";

            MsBuildHelpElementCodeBlock codeBlock = MsBuildElementHelpCodeBlockUtility.Parse(xmlInput);

            Assert.AreEqual("<!-- Test -->", codeBlock.Content);
        }
        public void Parse_WithValidXmlInput_ShouldReturnObjectWithLanguageXml()
        {
            string xmlInput = "<xml>test</xml>";

            MsBuildHelpElementCodeBlock codeBlock = MsBuildElementHelpCodeBlockUtility.Parse(xmlInput);

            Assert.AreEqual(MsBuildHelpCodeBlockLanguage.Xml, codeBlock.Language);
        }
        public void FormatXml_WithMultipleRootNodeXmlInputStringInOneRow_ShouldReturnFormattedXml()
        {
            string inputString    = "<!-- This is a xml comment --><xml><node id='1'>Test</node></xml><xml><test/></xml>";
            string expectedString =
                "<!-- This is a xml comment -->\n<xml>\n  <node\n    id=\"1\">Test</node>\n</xml>\n<xml>\n  <test />\n</xml>";

            Assert.AreEqual(expectedString,
                            MsBuildElementHelpCodeBlockUtility.FormatXml(inputString));
        }
Exemple #13
0
        /// <summary>
        /// Append a section to the documentation containing the targets examples by using the
        /// xml based help. Therefore all examples are appended a code block.
        /// </summary>
        /// <param name="targetOverviewDocument">Document the section should be appended to.</param>
        /// <param name="target">The target for which the section should be created.</param>
        private void AppendExampleSection(IPrintableDocument targetOverviewDocument,
                                          IMsBuildTarget target)
        {
            if (target.Help.ContainsSection(MsBuildHelpSections.Example, StringComparison.OrdinalIgnoreCase) == false)
            {
                return;
            }

            foreach (IMsBuildElementHelpParagraph exampleHelpParagraph in target.Help.LookUp(
                         MsBuildHelpSections.Example, StringComparison.OrdinalIgnoreCase))
            {
                IPrintableDocumentChapter exampleChapter =
                    targetOverviewDocument.AddNewChapter(MsBuildHelpSections.Example);

                IPrintableDocumentCodeBlock exampleCodeBlock =
                    exampleChapter.AddNewContent <IPrintableDocumentCodeBlock>();

                var codeBlock = MsBuildElementHelpCodeBlockUtility.Parse(exampleHelpParagraph.Content);

                exampleCodeBlock.AppendContentLine(codeBlock.Content);
                exampleCodeBlock.SetLanguage(codeBlock.Language.ToString());
            }
        }
        public void IsStringXml_WithOrdinalStringInput_ShouldReturnFalse()
        {
            string input = "This is an ordinal string value";

            Assert.IsFalse(MsBuildElementHelpCodeBlockUtility.IsStringXml(input));
        }
        public void IsStringXml_WithNullInput_ShouldReturnFalse()
        {
            string input = null;

            Assert.IsFalse(MsBuildElementHelpCodeBlockUtility.IsStringXml(input));
        }
        public void IsStringXml_WithLeadingXmlComment_ShouldReturnTrue()
        {
            string input = "<!-- This is a decoded comment --><TestValue></TestValue>";

            Assert.IsTrue(MsBuildElementHelpCodeBlockUtility.IsStringXml(input));
        }
 public void Decode_WithEmptyInputValue_ShouldReturnEmptyValue()
 {
     Assert.AreEqual(string.Empty, MsBuildElementHelpCodeBlockUtility.Decode(string.Empty));
 }
        public void IsStringXml_WithOrdinalStringInputLookingLikeXml_ShouldReturnFalse()
        {
            string input = "<xml><xml>bullshit<xml><xml>";

            Assert.IsFalse(MsBuildElementHelpCodeBlockUtility.IsStringXml(input));
        }
        public void IsStringXml_WithXmlFragmentInput_ShouldReturnTrue()
        {
            string input = "<element /><xml>bullshit</xml>";

            Assert.IsTrue(MsBuildElementHelpCodeBlockUtility.IsStringXml(input));
        }
        public void IsStringXml_WithTwoRootNodesInput_ShouldReturnTrue()
        {
            string input = "<root><element /><xml>bullshit</xml></root><root><test /></root>";

            Assert.IsTrue(MsBuildElementHelpCodeBlockUtility.IsStringXml(input));
        }