public void ContentIsSameAcrossInstances()
        {
            string content = ObjectModelHelpers.CleanupFileContents(@"
                    <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
                        <ItemGroup>
                           Item group content
                        </ItemGroup>
                    </Project>
                    ");

            string path = FileUtilities.GetTemporaryFile();

            try
            {
                File.WriteAllText(path, content);

                ProjectStringCache cache = new ProjectStringCache();
                XmlDocumentWithLocation document1 = new XmlDocumentWithLocation();
                document1.StringCache = cache;
                document1.Load(path);

                XmlDocumentWithLocation document2 = new XmlDocumentWithLocation();
                document2.StringCache = cache;
                document2.Load(path);

                XmlNodeList nodes1 = document1.GetElementsByTagName("ItemGroup");
                XmlNodeList nodes2 = document2.GetElementsByTagName("ItemGroup");

                Assert.AreEqual(1, nodes1.Count);
                Assert.AreEqual(1, nodes2.Count);

                XmlNode node1 = nodes1[0].FirstChild;
                XmlNode node2 = nodes2[0].FirstChild;

                Assert.IsNotNull(node1);
                Assert.IsNotNull(node2);
                Assert.AreNotSame(node1, node2);
                Assert.AreSame(node1.Value, node2.Value);
            }
            finally
            {
                File.Delete(path);
            }
        }
        public void ContentCanBeModified()
        {
            string content = ObjectModelHelpers.CleanupFileContents(@"
                    <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
                        <ItemGroup attr1='attr1value'>
                           Item group content
                        </ItemGroup>
                    </Project>
                    ");

            string path = FileUtilities.GetTemporaryFile();

            try
            {
                File.WriteAllText(path, content);
                ProjectStringCache cache = new ProjectStringCache();
                XmlDocumentWithLocation document1 = new XmlDocumentWithLocation();
                document1.StringCache = cache;
                document1.Load(path);

                XmlDocumentWithLocation document2 = new XmlDocumentWithLocation();
                document2.StringCache = cache;
                document2.Load(path);

                string outerXml1 = document1.OuterXml;
                string outerXml2 = document2.OuterXml;
                Assert.AreEqual(outerXml1, outerXml2);

                XmlNodeList nodes1 = document1.GetElementsByTagName("ItemGroup");
                XmlNodeList nodes2 = document2.GetElementsByTagName("ItemGroup");

                Assert.AreEqual(1, nodes1.Count);
                Assert.AreEqual(1, nodes2.Count);

                XmlNode node1 = nodes1[0];
                XmlNode node2 = nodes2[0];
                Assert.IsNotNull(node1);
                Assert.IsNotNull(node2);
                Assert.AreNotSame(node1, node2);
                Assert.AreEqual(1, node1.Attributes.Count);
                Assert.AreEqual(1, node2.Attributes.Count);
                Assert.AreSame(node1.Attributes[0].Value, node2.Attributes[0].Value);

                node2.Attributes[0].Value = "attr1value";
                Assert.AreEqual(node1.Attributes[0].Value, node2.Attributes[0].Value);
                Assert.AreNotSame(node1.Attributes[0].Value, node2.Attributes[0].Value);

                node1 = nodes1[0].FirstChild;
                node2 = nodes2[0].FirstChild;
                Assert.AreNotSame(node1, node2);
                Assert.AreSame(node1.Value, node2.Value);

                XmlText newText = document2.CreateTextNode("New Value");
                XmlNode parent = node2.ParentNode;
                parent.ReplaceChild(newText, node2);

                Assert.AreNotEqual(outerXml1, document2.OuterXml);
            }
            finally
            {
                File.Delete(path);
            }
        }