public void AddIfUniqueIEnumerableWithIEqualityComparer()
        {
            var TestObject = new ConcurrentBag <int>(new int[] { 1, 2, 3, 4, 5, 6 });

            Assert.False(TestObject.AddIfUnique(new GenericEqualityComparer <int>(), (IEnumerable <int>) new int[] { 1 }));
            Assert.True(TestObject.AddIfUnique(new GenericEqualityComparer <int>(), (IEnumerable <int>) new int[] { 7 }));
        }
        public void AddIfUniqueIEnumerable()
        {
            var TestObject = new ConcurrentBag <int>(new int[] { 1, 2, 3, 4, 5, 6 });

            Assert.False(TestObject.AddIfUnique((IEnumerable <int>) new int[] { 1 }));
            Assert.True(TestObject.AddIfUnique((IEnumerable <int>) new int[] { 7 }));
        }
        public void AddIfUniqueParamsWithNullPredicate()
        {
            var TestObject = new ConcurrentBag <int>(new int[] { 1, 2, 3, 4, 5, 6 });
            Func <int, int, bool> Comparer = null;

            Assert.False(TestObject.AddIfUnique(Comparer, new int[] { 1 }));
            Assert.False(TestObject.AddIfUnique(Comparer, new int[] { 7 }));
        }
        public void AddIfUniqueParamsWithNullIEqualityComparer()
        {
            var TestObject = new ConcurrentBag <int>(new int[] { 1, 2, 3, 4, 5, 6 });
            GenericEqualityComparer <int> Comparer = null;

            Assert.False(TestObject.AddIfUnique(Comparer, new int[] { 1 }));
            Assert.True(TestObject.AddIfUnique(Comparer, new int[] { 7 }));
        }
 public void AddIfUniqueTest()
 {
     var TestObject = new ConcurrentBag<int>(new int[] { 1, 2, 3, 4, 5, 6 });
     Assert.False(TestObject.AddIfUnique(1));
     Assert.True(TestObject.AddIfUnique(7));
     Assert.True(TestObject.AddIfUnique(new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }));
     Assert.Equal(8, TestObject.Count);
     TestObject = new ConcurrentBag<int>(new int[] { 1, 2, 3, 4, 5, 6 });
     Assert.False(TestObject.AddIfUnique((x, y) => x == y, 1));
     Assert.True(TestObject.AddIfUnique((x, y) => x == y, 7));
     Assert.True(TestObject.AddIfUnique((x, y) => x == y, new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }));
     Assert.Equal(8, TestObject.Count);
 }
        public void AddIfUniqueTest()
        {
            var TestObject = new ConcurrentBag <int>(new int[] { 1, 2, 3, 4, 5, 6 });

            Assert.False(TestObject.AddIfUnique(1));
            Assert.True(TestObject.AddIfUnique(7));
            Assert.True(TestObject.AddIfUnique(new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }));
            Assert.Equal(8, TestObject.Count);
            TestObject = new ConcurrentBag <int>(new int[] { 1, 2, 3, 4, 5, 6 });
            Assert.False(TestObject.AddIfUnique((x, y) => x == y, 1));
            Assert.True(TestObject.AddIfUnique((x, y) => x == y, 7));
            Assert.True(TestObject.AddIfUnique((x, y) => x == y, new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }));
            Assert.Equal(8, TestObject.Count);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds an item to the collection if it isn't already in the collection
 /// </summary>
 /// <typeparam name="T">Collection type</typeparam>
 /// <param name="collection">Collection to add to</param>
 /// <param name="items">Items to add to the collection</param>
 /// <returns>True if it is added, false otherwise</returns>
 public static bool AddIfUnique <T>(this ConcurrentBag <T> collection, IEnumerable <T> items) => collection.AddIfUnique(GenericEqualityComparer <T> .Comparer, items);