From: Hugh Bellamy Date: Tue, 28 Jun 2016 18:03:46 +0000 (+0100) Subject: Remove uses of ThrowsAny in System.Collections test helpers X-Git-Tag: submit/tizen/20210909.063632~11031^2~11857^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f515f66929f467c158f2f50ace37d87a8721b2a5;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Remove uses of ThrowsAny in System.Collections test helpers Add customization points instead Also uses expression bodied members to enhance readability Commit migrated from https://github.com/dotnet/corefx/commit/803d77a37ac90d9ec4c0008772aed9a4085be023 --- diff --git a/src/libraries/Common/tests/System/Collections/ICollection.Generic.Tests.cs b/src/libraries/Common/tests/System/Collections/ICollection.Generic.Tests.cs index 1862e7b..1994a07 100644 --- a/src/libraries/Common/tests/System/Collections/ICollection.Generic.Tests.cs +++ b/src/libraries/Common/tests/System/Collections/ICollection.Generic.Tests.cs @@ -53,6 +53,8 @@ namespace System.Collections.Tests } } + protected virtual Type ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentException); + #endregion #region IEnumerable Helper Methods @@ -400,7 +402,7 @@ namespace System.Collections.Tests if (!DefaultValueAllowed && !IsReadOnly) { if (DefaultValueWhenNotAllowed_Throws) - Assert.ThrowsAny(() => collection.Contains(default(T))); + Assert.Throws("item", () => collection.Contains(default(T))); else Assert.False(collection.Contains(default(T))); } @@ -435,7 +437,7 @@ namespace System.Collections.Tests ICollection collection = GenericICollectionFactory(count); T[] array = new T[count]; if (count > 0) - Assert.Throws(() =>collection.CopyTo(array, count)); + Assert.Throws(() => collection.CopyTo(array, count)); else collection.CopyTo(array, count); // does nothing since the array is empty } @@ -446,7 +448,7 @@ namespace System.Collections.Tests { ICollection collection = GenericICollectionFactory(count); T[] array = new T[count]; - Assert.ThrowsAny(() =>collection.CopyTo(array, count + 1)); // some implementations throw ArgumentOutOfRangeException for this scenario + Assert.Throws(ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType, () => collection.CopyTo(array, count + 1)); } [Theory] @@ -457,7 +459,7 @@ namespace System.Collections.Tests { ICollection collection = GenericICollectionFactory(count); T[] array = new T[count]; - Assert.Throws(() =>collection.CopyTo(array, 1)); + Assert.Throws(() => collection.CopyTo(array, 1)); } } @@ -609,7 +611,7 @@ namespace System.Collections.Tests ICollection collection = GenericICollectionFactory(count); Assert.All(InvalidValues, value => { - Assert.ThrowsAny(() => collection.Remove(value)); + Assert.Throws(() => collection.Remove(value)); }); Assert.Equal(count, collection.Count); } @@ -622,7 +624,7 @@ namespace System.Collections.Tests if (!DefaultValueAllowed && !IsReadOnly) { if (DefaultValueWhenNotAllowed_Throws) - Assert.ThrowsAny(() => collection.Remove(default(T))); + Assert.Throws(() => collection.Remove(default(T))); else Assert.False(collection.Remove(default(T))); } diff --git a/src/libraries/Common/tests/System/Collections/ICollection.NonGeneric.Tests.cs b/src/libraries/Common/tests/System/Collections/ICollection.NonGeneric.Tests.cs index 3fd050b..29a2ec5 100644 --- a/src/libraries/Common/tests/System/Collections/ICollection.NonGeneric.Tests.cs +++ b/src/libraries/Common/tests/System/Collections/ICollection.NonGeneric.Tests.cs @@ -84,6 +84,12 @@ namespace System.Collections.Tests /// protected virtual Type ICollection_NonGeneric_SyncRootType => typeof(object); + /// + /// Used for the ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowsArgumentException tests. Some + /// implementations throw a different exception type (e.g. ArgumentOutOfRangeException). + /// + protected virtual Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentException); + #endregion #region IEnumerable Helper Methods @@ -291,7 +297,7 @@ namespace System.Collections.Tests { ICollection collection = NonGenericICollectionFactory(count); object[] array = new object[count]; - Assert.ThrowsAny(() => collection.CopyTo(array, count + 1)); // some implementations throw ArgumentOutOfRangeException for this scenario + Assert.Throws(ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType, () => collection.CopyTo(array, count + 1)); } [Theory] diff --git a/src/libraries/Common/tests/System/Collections/IDictionary.Generic.Tests.cs b/src/libraries/Common/tests/System/Collections/IDictionary.Generic.Tests.cs index e7fc820..50bb275 100644 --- a/src/libraries/Common/tests/System/Collections/IDictionary.Generic.Tests.cs +++ b/src/libraries/Common/tests/System/Collections/IDictionary.Generic.Tests.cs @@ -913,7 +913,7 @@ namespace System.Collections.Tests if (!DefaultValueAllowed && !IsReadOnly) { if (DefaultValueWhenNotAllowed_Throws) - Assert.ThrowsAny(() => collection.Contains(default(KeyValuePair))); + Assert.Throws(() => collection.Contains(default(KeyValuePair))); else Assert.False(collection.Remove(default(KeyValuePair))); } diff --git a/src/libraries/Common/tests/System/Collections/IGenericSharedAPI.Tests.cs b/src/libraries/Common/tests/System/Collections/IGenericSharedAPI.Tests.cs index 8c3b0af..337c25f 100644 --- a/src/libraries/Common/tests/System/Collections/IGenericSharedAPI.Tests.cs +++ b/src/libraries/Common/tests/System/Collections/IGenericSharedAPI.Tests.cs @@ -19,11 +19,17 @@ namespace System.Collections.Tests { #region IGenericSharedAPI Helper methods - protected virtual bool DuplicateValuesAllowed { get { return true; } } - protected virtual bool DefaultValueWhenNotAllowed_Throws { get { return true; } } - protected virtual bool IsReadOnly { get { return false; } } - protected virtual bool DefaultValueAllowed { get { return true; } } - protected virtual IEnumerable InvalidValues { get { return Array.Empty(); } } + protected virtual bool DuplicateValuesAllowed => true; + protected virtual bool DefaultValueWhenNotAllowed_Throws => true; + protected virtual bool IsReadOnly => false; + protected virtual bool DefaultValueAllowed => true; + protected virtual IEnumerable InvalidValues => Array.Empty(); + + /// + /// Used for the IGenericSharedAPI_CopyTo_IndexLargerThanArrayCount_ThrowsArgumentException tests. Some + /// implementations throw a different exception type (e.g. ArgumentOutOfRangeException). + /// + protected virtual Type IGenericSharedAPI_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentException); protected virtual void AddToCollection(IEnumerable collection, int numberOfItemsToAdd) { @@ -355,7 +361,7 @@ namespace System.Collections.Tests if (!DefaultValueAllowed && !IsReadOnly) { if (DefaultValueWhenNotAllowed_Throws) - Assert.ThrowsAny(() => Contains(collection, default(T))); + Assert.Throws(() => Contains(collection, default(T))); else Assert.False(Contains(collection, default(T))); } @@ -401,7 +407,7 @@ namespace System.Collections.Tests { IEnumerable collection = GenericIEnumerableFactory(count); T[] array = new T[count]; - Assert.ThrowsAny(() => CopyTo(collection, array, count + 1)); // some implementations throw ArgumentOutOfRangeException for this scenario + Assert.Throws(IGenericSharedAPI_CopyTo_IndexLargerThanArrayCount_ThrowType, () => CopyTo(collection, array, count + 1)); } [Theory] diff --git a/src/libraries/Common/tests/System/Collections/IList.NonGeneric.Tests.cs b/src/libraries/Common/tests/System/Collections/IList.NonGeneric.Tests.cs index 014e2f5..5365913 100644 --- a/src/libraries/Common/tests/System/Collections/IList.NonGeneric.Tests.cs +++ b/src/libraries/Common/tests/System/Collections/IList.NonGeneric.Tests.cs @@ -949,7 +949,7 @@ namespace System.Collections.Tests IList collection = NonGenericIListFactory(count); Assert.All(InvalidValues, value => { - Assert.ThrowsAny(() => collection.Remove(value)); + Assert.Throws(() => collection.Remove(value)); }); Assert.Equal(count, collection.Count); } diff --git a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.Keys.cs b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.Keys.cs index adb8493..2a10970 100644 --- a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.Keys.cs +++ b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.Keys.cs @@ -10,10 +10,10 @@ namespace System.Collections.Tests { public class Dictionary_Generic_Tests_Keys : ICollection_Generic_Tests { - protected override bool DefaultValueAllowed { get { return false; } } - protected override bool DuplicateValuesAllowed { get { return false; } } - protected override bool IsReadOnly { get { return true; } } - protected override IEnumerable ModifyEnumerables { get { return new List(); } } + protected override bool DefaultValueAllowed => false; + protected override bool DuplicateValuesAllowed => false; + protected override bool IsReadOnly => true; + protected override IEnumerable ModifyEnumerables => new List(); protected override ICollection GenericICollectionFactory() { return new Dictionary().Keys; @@ -37,6 +37,8 @@ namespace System.Collections.Tests return Convert.ToBase64String(bytes); } + protected override Type ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); + [Theory] [MemberData(nameof(ValidCollectionSizes))] public void Dictionary_Generic_KeyCollection_Constructor_NullDictionary(int count) @@ -58,12 +60,14 @@ namespace System.Collections.Tests public class Dictionary_Generic_Tests_Keys_AsICollection : ICollection_NonGeneric_Tests { - protected override bool NullAllowed { get { return false; } } - protected override bool DuplicateValuesAllowed { get { return false; } } - protected override bool IsReadOnly { get { return true; } } - protected override bool Enumerator_Current_UndefinedOperation_Throws { get { return true; } } + protected override bool NullAllowed => false; + protected override bool DuplicateValuesAllowed => false; + protected override bool IsReadOnly => true; + protected override bool Enumerator_Current_UndefinedOperation_Throws => true; protected override Type ICollection_NonGeneric_CopyTo_ArrayOfEnumType_ThrowType => typeof(ArgumentException); + protected override Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); + protected override ICollection NonGenericICollectionFactory() { return new Dictionary().Keys; @@ -92,7 +96,7 @@ namespace System.Collections.Tests Debug.Assert(false); } - protected override IEnumerable ModifyEnumerables { get { return new List(); } } + protected override IEnumerable ModifyEnumerables => new List(); [Theory] [MemberData(nameof(ValidCollectionSizes))] diff --git a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.Values.cs b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.Values.cs index 5df8507..d19e25c 100644 --- a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.Values.cs +++ b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.Values.cs @@ -10,10 +10,10 @@ namespace System.Collections.Tests { public class Dictionary_Generic_Tests_Values : ICollection_Generic_Tests { - protected override bool DefaultValueAllowed { get { return true; } } - protected override bool DuplicateValuesAllowed { get { return true; } } - protected override bool IsReadOnly { get { return true; } } - protected override IEnumerable ModifyEnumerables { get { return new List(); } } + protected override bool DefaultValueAllowed => true; + protected override bool DuplicateValuesAllowed => true; + protected override bool IsReadOnly => true; + protected override IEnumerable ModifyEnumerables => new List(); protected override ICollection GenericICollectionFactory() { @@ -38,6 +38,8 @@ namespace System.Collections.Tests return Convert.ToBase64String(bytes); } + protected override Type ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); + [Theory] [MemberData(nameof(ValidCollectionSizes))] public void Dictionary_Generic_ValueCollection_Constructor_NullDictionary(int count) @@ -59,15 +61,18 @@ namespace System.Collections.Tests public class Dictionary_Generic_Tests_Values_AsICollection : ICollection_NonGeneric_Tests { - protected override bool NullAllowed { get { return true; } } - protected override bool DuplicateValuesAllowed { get { return true; } } - protected override bool IsReadOnly { get { return true; } } - protected override bool Enumerator_Current_UndefinedOperation_Throws { get { return true; } } + protected override bool NullAllowed => true; + protected override bool DuplicateValuesAllowed => true; + protected override bool IsReadOnly => true; + protected override bool Enumerator_Current_UndefinedOperation_Throws => true; protected override Type ICollection_NonGeneric_CopyTo_ArrayOfEnumType_ThrowType => typeof(ArgumentException); - protected override IEnumerable ModifyEnumerables { get { return new List(); } } + protected override IEnumerable ModifyEnumerables => new List(); + + protected override Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); + protected override ICollection NonGenericICollectionFactory() { - return (ICollection)(new Dictionary().Values); + return new Dictionary().Values; } protected override ICollection NonGenericICollectionFactory(int count) @@ -76,7 +81,7 @@ namespace System.Collections.Tests int seed = 13453; for (int i = 0; i < count; i++) list.Add(CreateT(seed++), CreateT(seed++)); - return (ICollection)(list.Values); + return list.Values; } private string CreateT(int seed) diff --git a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.cs index f92d031..91e5ac8 100644 --- a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.Tests.cs @@ -21,6 +21,8 @@ namespace System.Collections.Tests return new Dictionary(); } + protected override Type ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); + #endregion #region Constructors diff --git a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.cs b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.cs index 82267a1..9f19542 100644 --- a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.cs +++ b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Generic.cs @@ -23,15 +23,12 @@ namespace System.Collections.Tests return Convert.ToBase64String(bytes1); } - protected override string CreateTValue(int seed) - { - return CreateTKey(seed); - } + protected override string CreateTValue(int seed) => CreateTKey(seed); } public class Dictionary_Generic_Tests_int_int : Dictionary_Generic_Tests { - protected override bool DefaultValueAllowed { get { return true; } } + protected override bool DefaultValueAllowed => true; protected override KeyValuePair CreateT(int seed) { @@ -45,10 +42,7 @@ namespace System.Collections.Tests return rand.Next(); } - protected override int CreateTValue(int seed) - { - return CreateTKey(seed); - } + protected override int CreateTValue(int seed) => CreateTKey(seed); } public class Dictionary_Generic_Tests_SimpleInt_int_With_Comparer_WrapStructural_SimpleInt : Dictionary_Generic_Tests diff --git a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs index ee6db0e..449c457 100644 --- a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs @@ -33,10 +33,9 @@ namespace System.Collections.Tests /// Creates an object that is dependent on the seed given. The object may be either /// a value type or a reference type, chosen based on the value of the seed. /// - protected override object CreateTValue(int seed) - { - return CreateTKey(seed); - } + protected override object CreateTValue(int seed) => CreateTKey(seed); + + protected override Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); #region IDictionary tests diff --git a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.AsNonGenericIEnumerable.cs b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.AsNonGenericIEnumerable.cs index 085bd2d..a09ceb1 100644 --- a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.AsNonGenericIEnumerable.cs +++ b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.AsNonGenericIEnumerable.cs @@ -17,7 +17,7 @@ namespace System.Collections.Tests return set; } - protected override bool Enumerator_Current_UndefinedOperation_Throws { get { return true; } } + protected override bool Enumerator_Current_UndefinedOperation_Throws => true; /// /// Returns a set of ModifyEnumerable delegates that modify the enumerable passed to them. diff --git a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs index a43383c..ff8d7cb 100644 --- a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs @@ -15,13 +15,7 @@ namespace System.Collections.Tests { #region ISet Helper Methods - protected override bool ResetImplemented - { - get - { - return true; - } - } + protected override bool ResetImplemented => true; protected override ISet GenericISetFactory() { diff --git a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.cs b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.cs index db190d1..0b7e131 100644 --- a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.cs +++ b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.cs @@ -27,7 +27,7 @@ namespace System.Collections.Tests return rand.Next(); } - protected override bool DefaultValueAllowed { get { return true; } } + protected override bool DefaultValueAllowed => true; } public class HashSet_Generic_Tests_int_With_Comparer_WrapStructural_Int : HashSet_Generic_Tests diff --git a/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.AddLast.cs b/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.AddLast.cs index 96c3402..2156250 100644 --- a/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.AddLast.cs +++ b/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.AddLast.cs @@ -12,7 +12,6 @@ namespace System.Collections.Tests /// public abstract partial class LinkedList_Generic_Tests : ICollection_Generic_Tests { - [Fact] public void AddLast_T_Tests() { diff --git a/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.AsNonGenericICollection.cs b/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.AsNonGenericICollection.cs index 64695a1..ae49445 100644 --- a/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.AsNonGenericICollection.cs +++ b/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.AsNonGenericICollection.cs @@ -23,7 +23,7 @@ namespace System.Collections.Tests return new LinkedList(); } - protected override bool Enumerator_Current_UndefinedOperation_Throws { get { return true; } } + protected override bool Enumerator_Current_UndefinedOperation_Throws => true; /// /// Returns a set of ModifyEnumerable delegates that modify the enumerable passed to them. diff --git a/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.cs index 0c7f337..954be34 100644 --- a/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/LinkedList/LinkedList.Generic.Tests.cs @@ -19,6 +19,8 @@ namespace System.Collections.Tests return GenericLinkedListFactory(); } + protected override Type ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); + #endregion #region LinkedList Helper Methods diff --git a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.AsNonGenericIList.cs b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.AsNonGenericIList.cs index 4e4c4c5..d861017 100644 --- a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.AsNonGenericIList.cs +++ b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.AsNonGenericIList.cs @@ -2,11 +2,7 @@ // 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; using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using Xunit; namespace System.Collections.Tests { @@ -17,7 +13,7 @@ namespace System.Collections.Tests { #region IList_Generic_Tests - protected override bool NullAllowed { get { return true; } } + protected override bool NullAllowed => true; protected override IList NonGenericIListFactory() { diff --git a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Find.cs b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Find.cs index 9b3fd31..91416cb 100644 --- a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Find.cs +++ b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Find.cs @@ -14,8 +14,8 @@ namespace System.Collections.Tests public abstract partial class List_Generic_Tests : IList_Generic_Tests { private readonly Predicate EqualsDefaultDelegate = (T item) => { return default(T) == null ? item == null : default(T).Equals(item);}; - private readonly Predicate AlwaysTrueDelegate = (T item) => { return true; }; - private readonly Predicate AlwaysFalseDelegate = (T item) => { return false; }; + private readonly Predicate AlwaysTrueDelegate = (T item) => true; + private readonly Predicate AlwaysFalseDelegate = (T item) => false; [Theory] [MemberData(nameof(ValidCollectionSizes))] diff --git a/src/libraries/System.Collections/tests/Generic/List/List.Generic.cs b/src/libraries/System.Collections/tests/Generic/List/List.Generic.cs index 5a2bac3..96170df 100644 --- a/src/libraries/System.Collections/tests/Generic/List/List.Generic.cs +++ b/src/libraries/System.Collections/tests/Generic/List/List.Generic.cs @@ -2,11 +2,7 @@ // 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; using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using Xunit; namespace System.Collections.Tests { @@ -42,13 +38,7 @@ namespace System.Collections.Tests return Convert.ToBase64String(bytes); } - protected override bool IsReadOnly - { - get - { - return true; - } - } + protected override bool IsReadOnly => true; protected override IList GenericIListFactory(int setLength) { @@ -60,7 +50,7 @@ namespace System.Collections.Tests return GenericListFactory().AsReadOnly(); } - protected override IEnumerable ModifyEnumerables { get { return new List(); } } + protected override IEnumerable ModifyEnumerables => new List(); } public class List_Generic_Tests_int_ReadOnly : List_Generic_Tests @@ -71,13 +61,7 @@ namespace System.Collections.Tests return rand.Next(); } - protected override bool IsReadOnly - { - get - { - return true; - } - } + protected override bool IsReadOnly => true; protected override IList GenericIListFactory(int setLength) { @@ -88,6 +72,6 @@ namespace System.Collections.Tests { return GenericListFactory().AsReadOnly(); } - protected override IEnumerable ModifyEnumerables { get { return new List(); } } + protected override IEnumerable ModifyEnumerables => new List(); } } diff --git a/src/libraries/System.Collections/tests/Generic/Queue/Queue.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/Queue/Queue.Generic.Tests.cs index 4a45a87..f3a75e0 100644 --- a/src/libraries/System.Collections/tests/Generic/Queue/Queue.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Queue/Queue.Generic.Tests.cs @@ -44,13 +44,15 @@ namespace System.Collections.Tests return GenericQueueFactory(count); } - protected override int Count(IEnumerable enumerable) { return ((Queue)enumerable).Count; } - protected override void Add(IEnumerable enumerable, T value) { ((Queue)enumerable).Enqueue(value); } - protected override void Clear(IEnumerable enumerable) { ((Queue)enumerable).Clear(); } - protected override bool Contains(IEnumerable enumerable, T value) { return ((Queue)enumerable).Contains(value); } - protected override void CopyTo(IEnumerable enumerable, T[] array, int index) { ((Queue)enumerable).CopyTo(array, index); } + protected override int Count(IEnumerable enumerable) => ((Queue)enumerable).Count; + protected override void Add(IEnumerable enumerable, T value) => ((Queue)enumerable).Enqueue(value); + protected override void Clear(IEnumerable enumerable) => ((Queue)enumerable).Clear(); + protected override bool Contains(IEnumerable enumerable, T value) => ((Queue)enumerable).Contains(value); + protected override void CopyTo(IEnumerable enumerable, T[] array, int index) => ((Queue)enumerable).CopyTo(array, index); protected override bool Remove(IEnumerable enumerable) { ((Queue)enumerable).Dequeue(); return true; } - protected override bool Enumerator_Current_UndefinedOperation_Throws { get { return true; } } + protected override bool Enumerator_Current_UndefinedOperation_Throws => true; + + protected override Type IGenericSharedAPI_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); #endregion diff --git a/src/libraries/System.Collections/tests/Generic/Queue/Queue.Tests.cs b/src/libraries/System.Collections/tests/Generic/Queue/Queue.Tests.cs index 088b971..cdfb0bb 100644 --- a/src/libraries/System.Collections/tests/Generic/Queue/Queue.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Queue/Queue.Tests.cs @@ -27,7 +27,9 @@ namespace System.Collections.Tests return new Queue(); } - protected override bool Enumerator_Current_UndefinedOperation_Throws { get { return true; } } + protected override bool Enumerator_Current_UndefinedOperation_Throws => true; + + protected override Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); /// /// Returns a set of ModifyEnumerable delegates that modify the enumerable passed to them. diff --git a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.Keys.cs b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.Keys.cs index bc46f7c..db2437c 100644 --- a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.Keys.cs +++ b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.Keys.cs @@ -10,11 +10,11 @@ namespace System.Collections.Tests { public class SortedList_Generic_Tests_Keys : IList_Generic_Tests { - protected override bool DefaultValueAllowed { get { return false; } } - protected override bool DuplicateValuesAllowed { get { return false; } } - protected override bool IsReadOnly { get { return true; } } - protected override bool DefaultValueWhenNotAllowed_Throws { get { return true; } } - protected override IEnumerable ModifyEnumerables { get { return new List(); } } + protected override bool DefaultValueAllowed => false; + protected override bool DuplicateValuesAllowed => false; + protected override bool IsReadOnly => true; + protected override bool DefaultValueWhenNotAllowed_Throws => true; + protected override IEnumerable ModifyEnumerables => new List(); protected override IList GenericIListFactory() { @@ -91,6 +91,6 @@ namespace System.Collections.Tests Debug.Assert(false); } - protected override IEnumerable ModifyEnumerables { get { return new List(); } } + protected override IEnumerable ModifyEnumerables => new List(); } } diff --git a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.Values.cs b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.Values.cs index c557ac5..5e9c912 100644 --- a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.Values.cs +++ b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.Values.cs @@ -10,10 +10,10 @@ namespace System.Collections.Tests { public class SortedList_Generic_Tests_Values : IList_Generic_Tests { - protected override bool DefaultValueAllowed { get { return true; } } - protected override bool DuplicateValuesAllowed { get { return true; } } - protected override bool IsReadOnly { get { return true; } } - protected override IEnumerable ModifyEnumerables { get { return new List(); } } + protected override bool DefaultValueAllowed => true; + protected override bool DuplicateValuesAllowed => true; + protected override bool IsReadOnly => true; + protected override IEnumerable ModifyEnumerables => new List(); protected override IList GenericIListFactory() { @@ -90,6 +90,6 @@ namespace System.Collections.Tests Debug.Assert(false); } - protected override IEnumerable ModifyEnumerables { get { return new List(); } } + protected override IEnumerable ModifyEnumerables => new List(); } } diff --git a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.cs index c0fc466..2b28c67 100644 --- a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.Tests.cs @@ -33,7 +33,9 @@ namespace System.Collections.Tests if (count > 0) Assert.True(enumerator.MoveNext()); } - + + protected override Type ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); + #endregion #region Constructor_IComparer diff --git a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.cs b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.cs index 16e0993..c463e5f 100644 --- a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.cs +++ b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Generic.cs @@ -23,15 +23,12 @@ namespace System.Collections.Tests return Convert.ToBase64String(bytes1); } - protected override string CreateTValue(int seed) - { - return CreateTKey(seed); - } + protected override string CreateTValue(int seed) => CreateTKey(seed); } public class SortedList_Generic_Tests_int_int : SortedList_Generic_Tests { - protected override bool DefaultValueAllowed { get { return true; } } + protected override bool DefaultValueAllowed => true; protected override KeyValuePair CreateT(int seed) { Random rand = new Random(seed); @@ -44,10 +41,7 @@ namespace System.Collections.Tests return rand.Next(); } - protected override int CreateTValue(int seed) - { - return CreateTKey(seed); - } + protected override int CreateTValue(int seed) => CreateTKey(seed); } [OuterLoop] diff --git a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Tests.cs b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Tests.cs index 0a5140b..69e8f5b 100644 --- a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Tests.cs @@ -25,10 +25,9 @@ namespace System.Collections.Tests return Convert.ToBase64String(bytes); } - protected override object CreateTValue(int seed) - { - return CreateTKey(seed); - } + protected override object CreateTValue(int seed) => CreateTKey(seed); + + protected override Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); #endregion diff --git a/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.cs b/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.cs index 49efe06..ef1663e 100644 --- a/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.cs +++ b/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.cs @@ -27,13 +27,7 @@ namespace System.Collections.Tests return rand.Next(); } - protected override bool DefaultValueAllowed - { - get - { - return true; - } - } + protected override bool DefaultValueAllowed => true; } [OuterLoop] diff --git a/src/libraries/System.Collections/tests/Generic/Stack/Stack.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/Stack/Stack.Generic.Tests.cs index 6852de9..5c59e34 100644 --- a/src/libraries/System.Collections/tests/Generic/Stack/Stack.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Stack/Stack.Generic.Tests.cs @@ -32,6 +32,8 @@ namespace System.Collections.Tests return stack; } + protected override Type IGenericSharedAPI_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); + #endregion protected override IEnumerable GenericIEnumerableFactory() @@ -44,13 +46,13 @@ namespace System.Collections.Tests return GenericStackFactory(count); } - protected override int Count(IEnumerable enumerable) { return ((Stack)enumerable).Count; } - protected override void Add(IEnumerable enumerable, T value) { ((Stack)enumerable).Push(value); } - protected override void Clear(IEnumerable enumerable) { ((Stack)enumerable).Clear(); } - protected override bool Contains(IEnumerable enumerable, T value) { return ((Stack)enumerable).Contains(value); } - protected override void CopyTo(IEnumerable enumerable, T[] array, int index) { ((Stack)enumerable).CopyTo(array, index); } + protected override int Count(IEnumerable enumerable) => ((Stack)enumerable).Count; + protected override void Add(IEnumerable enumerable, T value) => ((Stack)enumerable).Push(value); + protected override void Clear(IEnumerable enumerable) => ((Stack)enumerable).Clear(); + protected override bool Contains(IEnumerable enumerable, T value) => ((Stack)enumerable).Contains(value); + protected override void CopyTo(IEnumerable enumerable, T[] array, int index) => ((Stack)enumerable).CopyTo(array, index); protected override bool Remove(IEnumerable enumerable) { ((Stack)enumerable).Pop(); return true; } - protected override bool Enumerator_Current_UndefinedOperation_Throws { get { return true; } } + protected override bool Enumerator_Current_UndefinedOperation_Throws => true; #endregion diff --git a/src/libraries/System.Collections/tests/Generic/Stack/Stack.Tests.cs b/src/libraries/System.Collections/tests/Generic/Stack/Stack.Tests.cs index 6c8783f..6231d58 100644 --- a/src/libraries/System.Collections/tests/Generic/Stack/Stack.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Stack/Stack.Tests.cs @@ -24,7 +24,9 @@ namespace System.Collections.Tests return new Stack(); } - protected override bool Enumerator_Current_UndefinedOperation_Throws { get { return true; } } + protected override bool Enumerator_Current_UndefinedOperation_Throws => true; + + protected override Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException); /// /// Returns a set of ModifyEnumerable delegates that modify the enumerable passed to them.