Example #1
0
        public void GetOrAdd(string input)
        {
            StringCache stringCache = new StringCache();
            string      added       = stringCache.GetOrAdd(input);

            Assert.AreEqual(added, input);
        }
Example #2
0
        public void AddStringTwice()
        {
            StringCache stringCache = new StringCache();
            string      test        = "test";
            string      added       = stringCache.GetOrAdd(test);

            Assert.IsTrue(object.ReferenceEquals(added, test));

            // build the same string using a StringBuilder, so that it's a different string object
            StringBuilder sb = new StringBuilder("te");

            sb.Append("st");
            string added2 = stringCache.GetOrAdd(sb.ToString());

            Assert.IsTrue(object.ReferenceEquals(added, added2));
        }
Example #3
0
        public void GetOrAdd(string?input)
        {
            var stringCache = new StringCache();
            var added       = stringCache.GetOrAdd(input);

            Assert.AreEqual(added, input);
        }