public void NoSpecialCharacters ( ) { // 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 = \"Local\"\r\n" + // ProjectType = "Local" " ProductVersion = \"7.10.3022\"\r\n" + // ProductVersion = "7.10.3022" " >\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 20 characters. char[] characterBuffer = new char[20]; int exceptionCount = 0; int charactersRead = 0; // Read the first 20 characters into our buffer. charactersRead = reader.Read(characterBuffer, 0, 20); Assert.AreEqual(20, charactersRead); Assert.AreEqual("<VisualStudioProject", new string(characterBuffer)); // Read the next 20 characters into our buffer. charactersRead = reader.Read(characterBuffer, 0, 20); Assert.AreEqual(20, charactersRead); Assert.AreEqual(">\r\n\r\n <VisualBasic\r", new string(characterBuffer)); // Read the next 10 characters into our buffer starting at position 5. charactersRead = reader.Read(characterBuffer, 5, 10); Assert.AreEqual(10, charactersRead); Assert.AreEqual(">\r\n\r\n\n Projeasic\r", new string(characterBuffer)); // Try reading the next 30 characters. Since there's not enough room in our // buffer for 30 characters, this will fail. try { charactersRead = reader.Read(characterBuffer, 5, 30); } catch (ArgumentException) { exceptionCount++; } // Confirm that the proper exception was thrown and that the buffer // was not touched. Assert.AreEqual(1, exceptionCount); Assert.AreEqual(">\r\n\r\n\n Projeasic\r", new string(characterBuffer)); // Read to the end of the current line. string readLine = reader.ReadLine(); Assert.AreEqual("ctType = \"Local\"", readLine); // Read the next line. readLine = reader.ReadLine(); Assert.AreEqual(" ProductVersion = \"7.10.3022\"", readLine); // Read the next character. int character = reader.Read(); Assert.AreEqual(' ', character); // Read the next character. character = reader.Read(); Assert.AreEqual(' ', character); // Peek at the next character, but don't advance the read pointer. character = reader.Peek(); Assert.AreEqual('>', character); // Read the next 20 characters into our buffer. charactersRead = reader.Read(characterBuffer, 0, 20); // Read the next 20 characters into our buffer. charactersRead = reader.Read(characterBuffer, 0, 20); // Read the next 20 characters into our buffer. But actually, since // we're almost at the end of the file, we expect that only 7 characters // will actually be read. charactersRead = reader.Read(characterBuffer, 0, 20); Assert.AreEqual(7, charactersRead); Assert.AreEqual("ject>\r\nsualStudioPro", new string(characterBuffer)); // Read the next 20 characters into our buffer. Now, we're really // at the end of the file already, so it should come back with zero // characters read. charactersRead = reader.Read(characterBuffer, 0, 20); Assert.AreEqual(0, charactersRead); Assert.AreEqual("ject>\r\nsualStudioPro", new string(characterBuffer)); // Clean up. reader.Close(); this.DeleteTemporaryProjectFile(projectFilename); }
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<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<.\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.>3022\"\r\n A=\"blah>\" B=\"bloo<\"\r\n >\r\n </VisualBasic>\r\n\r\n</VisualStudioProject>\r\n", restOfFile); // Clean up. reader.Close(); this.DeleteTemporaryProjectFile(projectFilename); }