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>(); }
public void testing_expected_Argument_InvalidOperation_and_IndexOutOfRangeException() { var a = new CKSortedArrayList <Mammal>((a1, a2) => a1.Name.CompareTo(a2.Name)); Assert.Throws <ArgumentNullException>(() => a.IndexOf(null)); Assert.Throws <ArgumentNullException>(() => a.IndexOf <Mammal>(new Mammal("Nothing"), null)); Assert.Throws <ArgumentNullException>(() => a.Add(null)); a.Add(new Mammal("A")); a.Add(new Mammal("B")); Assert.Throws <IndexOutOfRangeException>(() => { Mammal test = a[2]; }); Assert.Throws <IndexOutOfRangeException>(() => a.CheckPosition(2)); Assert.Throws <IndexOutOfRangeException>(() => { Mammal test = a[-1]; }); Assert.Throws <IndexOutOfRangeException>(() => a.CheckPosition(-1)); //Enumerator Exception var enumerator = a.GetEnumerator(); Assert.Throws <InvalidOperationException>(() => { Mammal temp = enumerator.Current; }); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.EqualTo(a[0])); enumerator.Reset(); Assert.Throws <InvalidOperationException>(() => { Mammal temp = enumerator.Current; }); a.Clear(); //change _version Assert.Throws <InvalidOperationException>(() => enumerator.Reset()); Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext()); //Exception IList <Mammal> testException = new CKSortedArrayList <Mammal>(); testException.Add(new Mammal("Nothing")); Assert.Throws <IndexOutOfRangeException>(() => testException[-1] = new Mammal("A")); Assert.Throws <IndexOutOfRangeException>(() => testException[1] = new Mammal("A")); Assert.Throws <ArgumentNullException>(() => testException[0] = null); Assert.Throws <IndexOutOfRangeException>(() => testException.Insert(-1, new Mammal("A"))); Assert.Throws <IndexOutOfRangeException>(() => testException.Insert(2, new Mammal("A"))); Assert.Throws <ArgumentNullException>(() => testException.Insert(0, null)); }