public void RemoveOneInstance()
        {
            ProjectStringCache cache = new ProjectStringCache();

            XmlDocument document = new XmlDocument();

            string stringToAdd = "Test1";
            string return1 = cache.Add(stringToAdd, document);
            Assert.AreEqual(1, cache.Count);

            XmlDocument document2 = new XmlDocument();
            string return2 = cache.Add(stringToAdd, document2);
            Assert.AreEqual(1, cache.Count);

            cache.Clear(document2);

            // Since there is still one document referencing the string, it should remain.
            Assert.AreEqual(1, cache.Count);

            // Build a new string guaranteed not to be optimized by the compiler into the same instance.
            StringBuilder builder = new StringBuilder();
            builder.Append("Test");
            builder.Append("1");
            XmlDocument document3 = new XmlDocument();

            string return3 = cache.Add(builder.ToString(), document3);

            // Returned references should be the same
            Assert.AreSame(return1, return3);

            // Still should only be one cached instance.
            Assert.AreEqual(1, cache.Count);
        }
        public void RemoveLastInstanceDeallocatesEntry()
        {
            ProjectStringCache cache = new ProjectStringCache();

            XmlDocument document = new XmlDocument();

            string stringToAdd = "Test1";
            string return1 = cache.Add(stringToAdd, document);

            cache.Clear(document);

            // Should be no instances left.
            Assert.AreEqual(0, cache.Count);

            // Build a new string guaranteed not to be optimized by the compiler into the same instance.
            StringBuilder builder = new StringBuilder();
            builder.Append("Test");
            builder.Append("1");
            XmlDocument document2 = new XmlDocument();

            string return2 = cache.Add(builder.ToString(), document2);

            // Returned references should NOT be the same
            Assert.AreNotSame(return1, return2);
        }