public void VerifyThatSameItemCannotBeAddedTwice()
 {
     var list = new OrderedItemList<Thing>(this.person, true);
     var email_0 = new EmailAddress(Guid.NewGuid(), null, null);
     
     list.Add(email_0);
     
     Assert.Throws<InvalidOperationException>(() => list.Add(email_0));
 }
        public void VerifyThatMoveThrowsException4()
        {
            var testlist = new OrderedItemList<Thing>(this.person, true);
            var email0 = new EmailAddress(Guid.NewGuid(), null, null);
            var email1 = new EmailAddress(Guid.NewGuid(), null, null);

            testlist.Add(email0);
            testlist.Add(email1);

            Assert.Throws<ArgumentOutOfRangeException>(() => testlist.Move(0, 3));
        }
        public void VerifyThatFindIndexWorks()
        {
            var testlist = new OrderedItemList<Thing>(this.person, true);
            var email0 = new EmailAddress(Guid.NewGuid(), null, null);
            var email1 = new EmailAddress(Guid.NewGuid(), null, null);

            testlist.Add(email0);
            testlist.Add(email1);

            Assert.AreEqual(0, testlist.FindIndex(x => x.Iid == email0.Iid));
            Assert.AreEqual(-1, testlist.FindIndex(x => x.Iid == Guid.NewGuid()));
            Assert.Throws<ArgumentNullException>(() => testlist.FindIndex(null));
        }
 public void VerifyThatArgumentNullExceptionWhenNullIsSet()
 {
     var list = new OrderedItemList<Thing>(this.person, false);
     var email = new EmailAddress(Guid.NewGuid(), null, null);
     list.Add(email);
     Assert.Throws<ArgumentNullException>(() => list[0] = null);
 }
        public void VerifyThatMoveWorks()
        {
            var testlist = new OrderedItemList<Thing>(this.person, true);
            var email0 = new EmailAddress(Guid.NewGuid(), null, null);
            var email1 = new EmailAddress(Guid.NewGuid(), null, null);
            var email2 = new EmailAddress(Guid.NewGuid(), null, null);
            var email3 = new EmailAddress(Guid.NewGuid(), null, null);
            var email4 = new EmailAddress(Guid.NewGuid(), null, null);
            
            testlist.Add(email0);
            testlist.Add(email1);
            testlist.Add(email2);
            testlist.Add(email3);
            testlist.Add(email4);

            Assert.AreSame(email0, testlist[0]);
            Assert.AreSame(email1, testlist[1]);
            Assert.AreSame(email2, testlist[2]);
            Assert.AreSame(email3, testlist[3]);
            Assert.AreSame(email4, testlist[4]);

            // move 1st to last
            testlist.Move(0, 4);
            Assert.AreSame(email1, testlist[0]);
            Assert.AreSame(email2, testlist[1]);
            Assert.AreSame(email3, testlist[2]);
            Assert.AreSame(email4, testlist[3]);
            Assert.AreSame(email0, testlist[4]);

            // move last to first
            testlist.Move(4, 0);
            Assert.AreSame(email0, testlist[0]);
            Assert.AreSame(email1, testlist[1]);
            Assert.AreSame(email2, testlist[2]);
            Assert.AreSame(email3, testlist[3]);
            Assert.AreSame(email4, testlist[4]);

            // does not do anything
            testlist.Move(0, 0);
            Assert.AreSame(email0, testlist[0]);
            Assert.AreSame(email1, testlist[1]);
            Assert.AreSame(email2, testlist[2]);
            Assert.AreSame(email3, testlist[3]);
            Assert.AreSame(email4, testlist[4]);
        }
        public void VerifyThatContainsWorks()
        {
            this.testList = new OrderedItemList<Thing>(this.person, true);
            var inserted = new Person(Guid.NewGuid(), null, null);

            testList.Add(inserted);

            Assert.IsTrue(this.testList.Contains(inserted));
        }
        public void VerifyThatCopyToWorks()
        {
            this.testList = new OrderedItemList<Thing>(this.person, true);
            var inserted = new Person(Guid.NewGuid(), null, null);

            testList.Add(inserted);

            var array = new Thing[1];
            this.testList.CopyTo(array, 0);

            Assert.IsNotNull(array[0]);
        }
        public void VerifyThatIfInsertAtIndexGreaterThatCountItemIsAppendedToList()
        {
            var list = new OrderedItemList<Thing>(this.person, false);
            var email1 = new EmailAddress(Guid.NewGuid(), null, null);
            list.Add(email1);

            var index = list.Count + 1;
            var email2 = new EmailAddress(Guid.NewGuid(), null, null);
            list.Insert(index, email2);

            Assert.AreSame(email1, list[0]);
            Assert.AreSame(email2, list[1]);
        }
        public void VerifyThatArgumentOutOfRangeIsThrownWhenIndexIsOutOfRange()
        {
            var list = new OrderedItemList<Thing>(this.person, false);
            EmailAddress email;
            Assert.Throws<ArgumentOutOfRangeException>(() => email = (EmailAddress)list[-1]);

            email = new EmailAddress(Guid.NewGuid(), null, null);
            list.Add(email);
            var invalidIndex = list.Count;
            Assert.Throws<ArgumentOutOfRangeException>(() => email = (EmailAddress)list[invalidIndex]);

            Assert.Throws<ArgumentOutOfRangeException>(() => list[-1] = email);
            Assert.Throws<ArgumentOutOfRangeException>(() => list[invalidIndex] = email);
        }