Ejemplo n.º 1
0
        public void Regress322573
        (
        )
        {
            // The contents of the project file that we'll be testing.
            string projectFileContents =
                "<Elem1 StartArguments = \"???action=16&requestid=1000036&#14CA053601F66928BF0550E395A714E72C8D6066???  /HeadTraxStartversion 5.6.0.66 /RunningFromHeadTraxStart yes /HTXMutexName HTXMutex344\"/>";

            // Create a temp file on disk with the above contents.
            string projectFilename;

            this.CreateTemporaryProjectFile(projectFileContents, out projectFilename);

            // Instantiate our class with the project file.
            OldVSProjectFileReader reader = new OldVSProjectFileReader(projectFilename);

            // Read the whole file into a string.  Confirm that the & character within
            // an attribute value got translated correctly.
            string wholeFile = reader.ReadToEnd();

            Assert.AreEqual("<Elem1 StartArguments = \"???action=16&amp;requestid=1000036&amp;#14CA053601F66928BF0550E395A714E72C8D6066???  /HeadTraxStartversion 5.6.0.66 /RunningFromHeadTraxStart yes /HTXMutexName HTXMutex344\"/>\r\n",
                            wholeFile);

            // Clean up.
            reader.Close();
            this.DeleteTemporaryProjectFile(projectFilename);
        }
Ejemplo n.º 2
0
        public void MultipleElementsOnSameLine
        (
        )
        {
            // The contents of the project file that we'll be testing.  Look at the
            // right side, for a cleaner copy without all the escaping.
            string projectFileContents =

                "<Elem1 Attrib1=\"bl>>ah\"/><Elem2 Attrib2=\"bl<<oo\"/>";  //  <Elem1 Attrib1="bl>>ah"/><Elem2 Attrib2="bl<<oo"/>

            // Create a temp file on disk with the above contents.
            string projectFilename;

            this.CreateTemporaryProjectFile(projectFileContents, out projectFilename);

            // Instantiate our class with the project file.
            OldVSProjectFileReader reader = new OldVSProjectFileReader(projectFilename);

            // Read the whole file into a string.  Confirm that the < and > characters within
            // an attribute value got translated correctly, but the < and > characters occurring
            // *outside* an attribute value are not touched.
            string wholeFile = reader.ReadToEnd();

            Assert.AreEqual("<Elem1 Attrib1=\"bl&gt;&gt;ah\"/><Elem2 Attrib2=\"bl&lt;&lt;oo\"/>\r\n",
                            wholeFile);

            // Clean up.
            reader.Close();
            this.DeleteTemporaryProjectFile(projectFilename);
        }
Ejemplo n.º 3
0
        public void AttributeValueUsingSingleQuotes
        (
        )
        {
            // The contents of the project file that we'll be testing.
            string projectFileContents =
                "<Elem1 Attrib1 = '1234<56789 is a \"true\" statement'/>";

            // Create a temp file on disk with the above contents.
            string projectFilename;

            this.CreateTemporaryProjectFile(projectFileContents, out projectFilename);

            // Instantiate our class with the project file.
            OldVSProjectFileReader reader = new OldVSProjectFileReader(projectFilename);

            // Read the whole file into a string.  Confirm that the < and > characters within
            // an attribute value got translated correctly, but the < and > characters occurring
            // *outside* an attribute value are not touched.
            string wholeFile = reader.ReadToEnd();

            Assert.AreEqual("<Elem1 Attrib1 = '1234&lt;56789 is a \"true\" statement'/>\r\n",
                            wholeFile);

            // Clean up.
            reader.Close();
            this.DeleteTemporaryProjectFile(projectFilename);
        }
Ejemplo n.º 4
0
        public void Regress184573()
        {
            // The contents of the project file that we'll be testing.  Look at the
            // right side, for a cleaner copy without all the escaping.
            char   c = '�';
            string projectFileContents = new string(c, 1);

            // Create a temp file on disk with the above contents.
            string projectFilename;

            this.CreateTemporaryProjectFile(projectFileContents, out projectFilename);

            // Instantiate our class with the project file.
            OldVSProjectFileReader reader = new OldVSProjectFileReader(projectFilename);

            // Read the whole file into a string.
            string wholeFile = reader.ReadToEnd();

            Assert.IsTrue(wholeFile.Length > 0, "High-bit character was stripped.");

            // Create two different encodings.
            Encoding defaultEncoding = Encoding.Default;
            Encoding unicode         = Encoding.Unicode;

            // Convert the string into a byte array.
            byte[] unicodeBytes = unicode.GetBytes(projectFileContents);
            // Perform the conversion from one encoding to the other.
            byte[] defaultEncodingBytes = Encoding.Convert(unicode, defaultEncoding, unicodeBytes);

            // Convert the new byte[] into a char[] and then into a string.
            char[] defaultEncodingChars = new char[defaultEncoding.GetCharCount(defaultEncodingBytes, 0, defaultEncodingBytes.Length)];
            defaultEncoding.GetChars(defaultEncodingBytes, 0, defaultEncodingBytes.Length, defaultEncodingChars, 0);

            Assert.IsTrue(defaultEncodingChars.Length > 0);
            Assert.IsTrue(wholeFile[0] == defaultEncodingChars[0], String.Format("Expected ANSI encoding of '{0}' to result in '{0}'. Instead it was '{1}'", c, defaultEncodingChars[0], wholeFile[0])
                          );

            // Clean up.
            reader.Close();
            this.DeleteTemporaryProjectFile(projectFilename);
        }
Ejemplo n.º 5
0
        public void XmlAttributesWithSpecialCharacters
        (
        )
        {
            // The contents of the project file that we'll be testing.  Look at the
            // right side, for a cleaner copy without all the escaping.
            string projectFileContents =

                "<VisualStudioProject>\r\n" +                   //      <VisualStudioProject>
                "\r\n" +                                        //
                "  <VisualBasic\r\n" +                          //        <VisualBasic
                "    ProjectType = \"Lo<cal\"\r\n" +            //          ProjectType = "Lo<cal"
                "    ProductVersion = \"7<.10.>3022\"\r\n" +    //          ProductVersion = "7<.10.>3022"
                "    A=\"blah>\" B=\"bloo<\"\r\n" +             //          A="blah>" B="bloo<"
                "  >\r\n" +                                     //        >
                "  </VisualBasic>\r\n" +                        //        </VisualBasic>
                "\r\n" +                                        //
                "</VisualStudioProject>\r\n";                   //      </VisualStudioProject>

            // Create a temp file on disk with the above contents.
            string projectFilename;

            this.CreateTemporaryProjectFile(projectFileContents, out projectFilename);

            // Instantiate our class with the project file.
            OldVSProjectFileReader reader = new OldVSProjectFileReader(projectFilename);

            // Create a buffer to hold 30 characters.
            char[] characterBuffer = new char[30];
            int    charactersRead  = 0;

            // Read the first 30 characters into our buffer.
            charactersRead = reader.Read(characterBuffer, 0, 30);
            Assert.AreEqual(30, charactersRead);
            Assert.AreEqual("<VisualStudioProject>\r\n\r\n  <Vi", new string(characterBuffer));

            // Read the next 30 characters into our buffer.
            charactersRead = reader.Read(characterBuffer, 0, 30);
            Assert.AreEqual(30, charactersRead);
            Assert.AreEqual("sualBasic\r\n    ProjectType = \"", new string(characterBuffer));

            // Read the next 20 characters into our buffer starting at position 10.
            // Confirm that the < and > characters within an attribute value got translated correctly.
            charactersRead = reader.Read(characterBuffer, 10, 20);
            Assert.AreEqual(20, charactersRead);
            Assert.AreEqual("sualBasic\rLo&lt;cal\"\r\n    Prod", new string(characterBuffer));

            // Read the next 20 characters into our buffer.  Confirm that the < and > characters within
            // an attribute value got translated correctly.
            charactersRead = reader.Read(characterBuffer, 0, 20);
            Assert.AreEqual(20, charactersRead);
            Assert.AreEqual("uctVersion = \"7&lt;.\r\n    Prod", new string(characterBuffer));

            // Read the remainder of the file.  Confirm that the < and > characters within
            // an attribute value got translated correctly.
            string restOfFile = reader.ReadToEnd();

            Assert.AreEqual("10.&gt;3022\"\r\n    A=\"blah&gt;\" B=\"bloo&lt;\"\r\n  >\r\n  </VisualBasic>\r\n\r\n</VisualStudioProject>\r\n",
                            restOfFile);

            // Clean up.
            reader.Close();
            this.DeleteTemporaryProjectFile(projectFilename);
        }