public void testing_capacity_changes() { var a = new CKSortedArrayList <Mammal>((a1, a2) => a1.Name.CompareTo(a2.Name)); a.Capacity.Should().Be(0); a.Capacity = 3; a.Capacity.Should().Be(4); a.Capacity = 0; a.Capacity.Should().Be(0); a.Add(new Mammal("1")); a.Invoking(sut => sut.Capacity = 0).Should().Throw <ArgumentException>(); a.Add(new Mammal("2")); a.Add(new Mammal("3")); a.Add(new Mammal("4")); a.Add(new Mammal("5")); a.Capacity.Should().Be(8); a.Capacity = 5; a.Capacity.Should().Be(5); a.Add(new Mammal("6")); a.Add(new Mammal("7")); a.Add(new Mammal("8")); a.Add(new Mammal("9")); a.Add(new Mammal("10")); a.Capacity.Should().Be(10); a.Clear(); a.Capacity.Should().Be(10); }
public void testing_expected_Argument_InvalidOperation_and_IndexOutOfRangeException() { var a = new CKSortedArrayList <Mammal>((a1, a2) => a1.Name.CompareTo(a2.Name)); a.Invoking(sut => sut.IndexOf(null)).Should().Throw <ArgumentNullException>(); a.Invoking(sut => sut.IndexOf(null)).Should().Throw <ArgumentNullException>(); a.Invoking(sut => sut.IndexOf <Mammal>(new Mammal("Nothing"), null)).Should().Throw <ArgumentNullException>(); a.Invoking(sut => sut.Add(null)).Should().Throw <ArgumentNullException>(); a.Add(new Mammal("A")); a.Add(new Mammal("B")); a.Invoking(sut => { Mammal test = sut[2]; }).Should().Throw <IndexOutOfRangeException>(); a.Invoking(sut => sut.CheckPosition(2)).Should().Throw <IndexOutOfRangeException>(); a.Invoking(sut => { Mammal test = a[-1]; }).Should().Throw <IndexOutOfRangeException>(); //Enumerator Exception var enumerator = a.GetEnumerator(); enumerator.Invoking(sut => { Mammal temp = sut.Current; }).Should().Throw <InvalidOperationException>(); enumerator.MoveNext(); enumerator.Current.Should().Be(a[0]); enumerator.Reset(); enumerator.Invoking(sut => { Mammal temp = sut.Current; }).Should().Throw <InvalidOperationException>(); a.Clear(); //change _version enumerator.Invoking(sut => sut.Reset()).Should().Throw <InvalidOperationException>(); enumerator.Invoking(sut => sut.MoveNext()).Should().Throw <InvalidOperationException>(); //Exception IList <Mammal> testException = new CKSortedArrayList <Mammal>(); testException.Add(new Mammal("Nothing")); testException.Invoking(sut => sut[-1] = new Mammal("A")).Should().Throw <IndexOutOfRangeException>(); testException.Invoking(sut => sut[1] = new Mammal("A")).Should().Throw <IndexOutOfRangeException>(); testException.Invoking(sut => sut[0] = null).Should().Throw <ArgumentNullException>(); testException.Invoking(sut => sut.Insert(-1, new Mammal("A"))).Should().Throw <IndexOutOfRangeException>(); testException.Invoking(sut => sut.Insert(2, new Mammal("A"))).Should().Throw <IndexOutOfRangeException>(); testException.Invoking(sut => sut.Insert(0, null)).Should().Throw <ArgumentNullException>(); }