public static void TestNullComparer()
        {
            AssertDefaultComparerBehavior(new ConcurrentDictionary <EqualityApiSpy, int>((IEqualityComparer <EqualityApiSpy>)null));

            AssertDefaultComparerBehavior(new ConcurrentDictionary <EqualityApiSpy, int>(new[] { new KeyValuePair <EqualityApiSpy, int>(new EqualityApiSpy(), 1) }, null));

            AssertDefaultComparerBehavior(new ConcurrentDictionary <EqualityApiSpy, int>(1, new[] { new KeyValuePair <EqualityApiSpy, int>(new EqualityApiSpy(), 1) }, null));

            AssertDefaultComparerBehavior(new ConcurrentDictionary <EqualityApiSpy, int>(1, 1, null));

            void AssertDefaultComparerBehavior(ConcurrentDictionary <EqualityApiSpy, int> dictionary)
            {
                var spyKey = new EqualityApiSpy();

                Assert.True(dictionary.TryAdd(spyKey, 1));
                Assert.False(dictionary.TryAdd(spyKey, 1));

                Assert.False(spyKey.ObjectApiUsed);
                Assert.True(spyKey.IEquatableApiUsed);
            }
        }
Example #2
0
        public static void TestNullComparer()
        {
            AssertDefaultComparerBehavior(new LurchTable <EqualityApiSpy, int>((IEqualityComparer <EqualityApiSpy>)null));

            AssertDefaultComparerBehavior(new LurchTable <EqualityApiSpy, int>(new[] { new KeyValuePair <EqualityApiSpy, int>(new EqualityApiSpy(), 1) }, null));

            AssertDefaultComparerBehavior(new LurchTable <EqualityApiSpy, int>(/*1,*/ new[] { new KeyValuePair <EqualityApiSpy, int>(new EqualityApiSpy(), 1) }, null));

            AssertDefaultComparerBehavior(new LurchTable <EqualityApiSpy, int>(/*1,*/ 1, LurchTableOrder.None, (IEqualityComparer <EqualityApiSpy>)null));

            void AssertDefaultComparerBehavior(LurchTable <EqualityApiSpy, int> dictionary)
            {
                var spyKey = new EqualityApiSpy();

                Assert.True(dictionary.TryAdd(spyKey, 1));
                Assert.False(dictionary.TryAdd(spyKey, 1));

                Assert.False(spyKey.ObjectApiUsed);
                Assert.True(spyKey.IEquatableApiUsed);
            }
        }