Example #1
0
        public void Test001_DoubleEndedUniqueCollectionDoesntAcceptKeyDuplicates()
        {
            Assert.Throws <ArgumentException>(() =>
            {
                var delist = new DoubleEndedUniqueCollection <int>();
                delist.Add(123);
                Console.WriteLine("Added " + 123);
                delist.Add(789);
                Console.WriteLine("Added " + 789);
                delist.Add(456);
                Console.WriteLine("Added " + 456);

                var error = null as Exception;
                try
                {
                    Console.WriteLine("Trying to add " + 789 + " again");
                    delist.Add(789);
                    Console.WriteLine("Added " + 789);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Couldn't add " + 789 + " again... removing it...");
                    delist.Remove(789);
                    error = ex;
                }
                Assert.AreEqual(delist.Contains(789), false);

                Console.WriteLine("Re-adding " + 789);
                delist.Add(789);
                Console.WriteLine("Added " + 789);
                Assert.AreEqual(delist.Contains(789), true);

                if (error != null)
                {
                    Console.WriteLine("Re-throwing the exception we caught...");
                    throw error;
                }
            });
        }
        public void Test001_DoubleEndedUniqueCollectionDoesntAcceptKeyDuplicates()
        {
            var delist = new DoubleEndedUniqueCollection<int>();
            delist.Add(123);
            Console.WriteLine("Added " + 123);
            delist.Add(789);
            Console.WriteLine("Added " + 789);
            delist.Add(456);
            Console.WriteLine("Added " + 456);

            var error = null as Exception;
            try
            {
                Console.WriteLine("Trying to add " + 789 + " again");
                delist.Add(789);
                Console.WriteLine("Added " + 789);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Couldn't add " + 789 + " again... removing it...");
                delist.Remove(789);
                error = ex;
            }
            Assert.AreEqual(delist.Contains(789), false);

            Console.WriteLine("Re-adding " + 789);
            delist.Add(789);
            Console.WriteLine("Added " + 789);
            Assert.AreEqual(delist.Contains(789), true);

            if (error != null)
            {
                Console.WriteLine("Re-throwing the exception we caught...");
                throw error;
            }
        }