diff options
author | Hugh Bellamy <hughbellars@gmail.com> | 2016-05-26 11:29:58 +0300 |
---|---|---|
committer | Hugh Bellamy <hughbellars@gmail.com> | 2016-05-26 11:29:58 +0300 |
commit | 072d14f160ddfb5df17f34040316ebba64708d21 (patch) | |
tree | 815e5f197adc4b640a0c59bee7843ff7dd3d9251 /src/System.Collections.NonGeneric/tests/ArrayList | |
parent | 9645ae61f070bb606518b52633ad74841921e848 (diff) |
Add ArrayList IList tests
- Fix IList_NonGeneric tests to work with fixed size lists
Diffstat (limited to 'src/System.Collections.NonGeneric/tests/ArrayList')
-rw-r--r-- | src/System.Collections.NonGeneric/tests/ArrayList/ArrayList.IList.Tests.cs | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/System.Collections.NonGeneric/tests/ArrayList/ArrayList.IList.Tests.cs b/src/System.Collections.NonGeneric/tests/ArrayList/ArrayList.IList.Tests.cs new file mode 100644 index 0000000000..2c189c7e77 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/ArrayList/ArrayList.IList.Tests.cs @@ -0,0 +1,95 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using Xunit; + +namespace System.Collections.Tests +{ + public class ArrayListBasicTests : ArrayListIListTestBase + { + protected override IList NonGenericIListFactory() => new ArrayList(); + } + + public class ArrayListSynchronizedTests : ArrayListIListTestBase + { + protected override bool ExpectedIsSynchronized => true; + + protected override IList NonGenericIListFactory() => NonGenericIListFactory(0); + protected override IList NonGenericIListFactory(int count) => ArrayList.Synchronized(Helpers.CreateIntArrayList(count)); + } + + public class ArrayListSynchronizedILstTests : ArrayListIListTestBase + { + protected override bool ExpectedIsSynchronized => true; + + protected override IList NonGenericIListFactory() => NonGenericIListFactory(0); + protected override IList NonGenericIListFactory(int count) => ArrayList.Synchronized((IList)Helpers.CreateIntArrayList(count)); + } + + public class ArrayListFixedSizeTests : ArrayListIListTestBase + { + protected override bool ExpectedFixedSize => true; + + protected override IList NonGenericIListFactory() => NonGenericIListFactory(0); + protected override IList NonGenericIListFactory(int count) => ArrayList.FixedSize(Helpers.CreateIntArrayList(count)); + } + + public class ArrayListFixedIListSizeTests : ArrayListIListTestBase + { + protected override bool ExpectedFixedSize => true; + + protected override IList NonGenericIListFactory() => NonGenericIListFactory(0); + protected override IList NonGenericIListFactory(int count) => ArrayList.FixedSize((IList)Helpers.CreateIntArrayList(count)); + } + + public class ArrayListReadOnlyTests : ArrayListIListTestBase + { + protected override bool ExpectedFixedSize => true; + protected override bool IsReadOnly => true; + + protected override IList NonGenericIListFactory() => NonGenericIListFactory(0); + protected override IList NonGenericIListFactory(int count) => ArrayList.ReadOnly(Helpers.CreateIntArrayList(count)); + } + + public class ArrayListReadOnlyIListTests : ArrayListIListTestBase + { + protected override bool ExpectedFixedSize => true; + protected override bool IsReadOnly => true; + + protected override IList NonGenericIListFactory() => NonGenericIListFactory(0); + protected override IList NonGenericIListFactory(int count) => ArrayList.ReadOnly((IList)Helpers.CreateIntArrayList(count)); + } + + public class ArrayListAdapterTests : ArrayListIListTestBase + { + protected override IList NonGenericIListFactory() => NonGenericIListFactory(0); + protected override IList NonGenericIListFactory(int count) => ArrayList.Adapter(Helpers.CreateIntArrayList(count)); + } + + public class ArrayListRangeTests : ArrayListIListTestBase + { + protected override IList NonGenericIListFactory() => NonGenericIListFactory(0); + protected override IList NonGenericIListFactory(int count) => Helpers.CreateIntArrayList(count).GetRange(0, count); + } + + public abstract class ArrayListIListTestBase : IList_NonGeneric_Tests + { + protected override bool Enumerator_Current_UndefinedOperation_Throws => true; + + protected override Type ICollection_NonGeneric_CopyTo_ArrayOfEnumType_ThrowType => typeof(InvalidCastException); + protected override Type ICollection_NonGeneric_CopyTo_ArrayOfIncorrectReferenceType_ThrowType => typeof(InvalidCastException); + protected override Type ICollection_NonGeneric_CopyTo_ArrayOfIncorrectValueType_ThrowType => typeof(InvalidCastException); + protected override Type ICollection_NonGeneric_CopyTo_NonZeroLowerBound_ThrowType => typeof(ArgumentOutOfRangeException); + + protected override object CreateT(int seed) + { + int stringLength = seed % 10 + 5; + Random rand = new Random(seed); + byte[] bytes = new byte[stringLength]; + rand.NextBytes(bytes); + return Convert.ToBase64String(bytes); + } + } +} |