}
}
+ protected virtual Type ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentException);
+
#endregion
#region IEnumerable<T> Helper Methods
if (!DefaultValueAllowed && !IsReadOnly)
{
if (DefaultValueWhenNotAllowed_Throws)
- Assert.ThrowsAny<ArgumentNullException>(() => collection.Contains(default(T)));
+ Assert.Throws<ArgumentNullException>("item", () => collection.Contains(default(T)));
else
Assert.False(collection.Contains(default(T)));
}
ICollection<T> collection = GenericICollectionFactory(count);
T[] array = new T[count];
if (count > 0)
- Assert.Throws<ArgumentException>(() =>collection.CopyTo(array, count));
+ Assert.Throws<ArgumentException>(() => collection.CopyTo(array, count));
else
collection.CopyTo(array, count); // does nothing since the array is empty
}
{
ICollection<T> collection = GenericICollectionFactory(count);
T[] array = new T[count];
- Assert.ThrowsAny<ArgumentException>(() =>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]
{
ICollection<T> collection = GenericICollectionFactory(count);
T[] array = new T[count];
- Assert.Throws<ArgumentException>(() =>collection.CopyTo(array, 1));
+ Assert.Throws<ArgumentException>(() => collection.CopyTo(array, 1));
}
}
ICollection<T> collection = GenericICollectionFactory(count);
Assert.All(InvalidValues, value =>
{
- Assert.ThrowsAny<ArgumentException>(() => collection.Remove(value));
+ Assert.Throws<ArgumentException>(() => collection.Remove(value));
});
Assert.Equal(count, collection.Count);
}
if (!DefaultValueAllowed && !IsReadOnly)
{
if (DefaultValueWhenNotAllowed_Throws)
- Assert.ThrowsAny<ArgumentNullException>(() => collection.Remove(default(T)));
+ Assert.Throws<ArgumentNullException>(() => collection.Remove(default(T)));
else
Assert.False(collection.Remove(default(T)));
}
/// </summary>
protected virtual Type ICollection_NonGeneric_SyncRootType => typeof(object);
+ /// <summary>
+ /// Used for the ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowsArgumentException tests. Some
+ /// implementations throw a different exception type (e.g. ArgumentOutOfRangeException).
+ /// </summary>
+ protected virtual Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentException);
+
#endregion
#region IEnumerable Helper Methods
{
ICollection collection = NonGenericICollectionFactory(count);
object[] array = new object[count];
- Assert.ThrowsAny<ArgumentException>(() => 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]
if (!DefaultValueAllowed && !IsReadOnly)
{
if (DefaultValueWhenNotAllowed_Throws)
- Assert.ThrowsAny<ArgumentNullException>(() => collection.Contains(default(KeyValuePair<TKey, TValue>)));
+ Assert.Throws<ArgumentNullException>(() => collection.Contains(default(KeyValuePair<TKey, TValue>)));
else
Assert.False(collection.Remove(default(KeyValuePair<TKey, TValue>)));
}
{
#region IGenericSharedAPI<T> 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<T> InvalidValues { get { return Array.Empty<T>(); } }
+ protected virtual bool DuplicateValuesAllowed => true;
+ protected virtual bool DefaultValueWhenNotAllowed_Throws => true;
+ protected virtual bool IsReadOnly => false;
+ protected virtual bool DefaultValueAllowed => true;
+ protected virtual IEnumerable<T> InvalidValues => Array.Empty<T>();
+
+ /// <summary>
+ /// Used for the IGenericSharedAPI_CopyTo_IndexLargerThanArrayCount_ThrowsArgumentException tests. Some
+ /// implementations throw a different exception type (e.g. ArgumentOutOfRangeException).
+ /// </summary>
+ protected virtual Type IGenericSharedAPI_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentException);
protected virtual void AddToCollection(IEnumerable<T> collection, int numberOfItemsToAdd)
{
if (!DefaultValueAllowed && !IsReadOnly)
{
if (DefaultValueWhenNotAllowed_Throws)
- Assert.ThrowsAny<ArgumentNullException>(() => Contains(collection, default(T)));
+ Assert.Throws<ArgumentNullException>(() => Contains(collection, default(T)));
else
Assert.False(Contains(collection, default(T)));
}
{
IEnumerable<T> collection = GenericIEnumerableFactory(count);
T[] array = new T[count];
- Assert.ThrowsAny<ArgumentException>(() => CopyTo(collection, array, count + 1)); // some implementations throw ArgumentOutOfRangeException for this scenario
+ Assert.Throws(IGenericSharedAPI_CopyTo_IndexLargerThanArrayCount_ThrowType, () => CopyTo(collection, array, count + 1));
}
[Theory]
IList collection = NonGenericIListFactory(count);
Assert.All(InvalidValues, value =>
{
- Assert.ThrowsAny<ArgumentException>(() => collection.Remove(value));
+ Assert.Throws<ArgumentException>(() => collection.Remove(value));
});
Assert.Equal(count, collection.Count);
}
{
public class Dictionary_Generic_Tests_Keys : ICollection_Generic_Tests<string>
{
- protected override bool DefaultValueAllowed { get { return false; } }
- protected override bool DuplicateValuesAllowed { get { return false; } }
- protected override bool IsReadOnly { get { return true; } }
- protected override IEnumerable<ModifyEnumerable> ModifyEnumerables { get { return new List<ModifyEnumerable>(); } }
+ protected override bool DefaultValueAllowed => false;
+ protected override bool DuplicateValuesAllowed => false;
+ protected override bool IsReadOnly => true;
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
protected override ICollection<string> GenericICollectionFactory()
{
return new Dictionary<string, string>().Keys;
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)
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<string, string>().Keys;
Debug.Assert(false);
}
- protected override IEnumerable<ModifyEnumerable> ModifyEnumerables { get { return new List<ModifyEnumerable>(); } }
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
{
public class Dictionary_Generic_Tests_Values : ICollection_Generic_Tests<string>
{
- protected override bool DefaultValueAllowed { get { return true; } }
- protected override bool DuplicateValuesAllowed { get { return true; } }
- protected override bool IsReadOnly { get { return true; } }
- protected override IEnumerable<ModifyEnumerable> ModifyEnumerables { get { return new List<ModifyEnumerable>(); } }
+ protected override bool DefaultValueAllowed => true;
+ protected override bool DuplicateValuesAllowed => true;
+ protected override bool IsReadOnly => true;
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
protected override ICollection<string> GenericICollectionFactory()
{
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)
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<ModifyEnumerable> ModifyEnumerables { get { return new List<ModifyEnumerable>(); } }
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
+
+ protected override Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException);
+
protected override ICollection NonGenericICollectionFactory()
{
- return (ICollection)(new Dictionary<string, string>().Values);
+ return new Dictionary<string, string>().Values;
}
protected override ICollection NonGenericICollectionFactory(int count)
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)
return new Dictionary<TKey, TValue>();
}
+ protected override Type ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException);
+
#endregion
#region Constructors
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<int, int>
{
- protected override bool DefaultValueAllowed { get { return true; } }
+ protected override bool DefaultValueAllowed => true;
protected override KeyValuePair<int, int> CreateT(int seed)
{
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<SimpleInt, int>
/// 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.
/// </summary>
- 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
return set;
}
- protected override bool Enumerator_Current_UndefinedOperation_Throws { get { return true; } }
+ protected override bool Enumerator_Current_UndefinedOperation_Throws => true;
/// <summary>
/// Returns a set of ModifyEnumerable delegates that modify the enumerable passed to them.
{
#region ISet<T> Helper Methods
- protected override bool ResetImplemented
- {
- get
- {
- return true;
- }
- }
+ protected override bool ResetImplemented => true;
protected override ISet<T> GenericISetFactory()
{
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<int>
/// </summary>
public abstract partial class LinkedList_Generic_Tests<T> : ICollection_Generic_Tests<T>
{
-
[Fact]
public void AddLast_T_Tests()
{
return new LinkedList<string>();
}
- protected override bool Enumerator_Current_UndefinedOperation_Throws { get { return true; } }
+ protected override bool Enumerator_Current_UndefinedOperation_Throws => true;
/// <summary>
/// Returns a set of ModifyEnumerable delegates that modify the enumerable passed to them.
return GenericLinkedListFactory();
}
+ protected override Type ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException);
+
#endregion
#region LinkedList<T> Helper Methods
// 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
{
{
#region IList_Generic_Tests
- protected override bool NullAllowed { get { return true; } }
+ protected override bool NullAllowed => true;
protected override IList NonGenericIListFactory()
{
public abstract partial class List_Generic_Tests<T> : IList_Generic_Tests<T>
{
private readonly Predicate<T> EqualsDefaultDelegate = (T item) => { return default(T) == null ? item == null : default(T).Equals(item);};
- private readonly Predicate<T> AlwaysTrueDelegate = (T item) => { return true; };
- private readonly Predicate<T> AlwaysFalseDelegate = (T item) => { return false; };
+ private readonly Predicate<T> AlwaysTrueDelegate = (T item) => true;
+ private readonly Predicate<T> AlwaysFalseDelegate = (T item) => false;
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
// 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
{
return Convert.ToBase64String(bytes);
}
- protected override bool IsReadOnly
- {
- get
- {
- return true;
- }
- }
+ protected override bool IsReadOnly => true;
protected override IList<string> GenericIListFactory(int setLength)
{
return GenericListFactory().AsReadOnly();
}
- protected override IEnumerable<ModifyEnumerable> ModifyEnumerables { get { return new List<ModifyEnumerable>(); } }
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
}
public class List_Generic_Tests_int_ReadOnly : List_Generic_Tests<int>
return rand.Next();
}
- protected override bool IsReadOnly
- {
- get
- {
- return true;
- }
- }
+ protected override bool IsReadOnly => true;
protected override IList<int> GenericIListFactory(int setLength)
{
{
return GenericListFactory().AsReadOnly();
}
- protected override IEnumerable<ModifyEnumerable> ModifyEnumerables { get { return new List<ModifyEnumerable>(); } }
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
}
}
return GenericQueueFactory(count);
}
- protected override int Count(IEnumerable<T> enumerable) { return ((Queue<T>)enumerable).Count; }
- protected override void Add(IEnumerable<T> enumerable, T value) { ((Queue<T>)enumerable).Enqueue(value); }
- protected override void Clear(IEnumerable<T> enumerable) { ((Queue<T>)enumerable).Clear(); }
- protected override bool Contains(IEnumerable<T> enumerable, T value) { return ((Queue<T>)enumerable).Contains(value); }
- protected override void CopyTo(IEnumerable<T> enumerable, T[] array, int index) { ((Queue<T>)enumerable).CopyTo(array, index); }
+ protected override int Count(IEnumerable<T> enumerable) => ((Queue<T>)enumerable).Count;
+ protected override void Add(IEnumerable<T> enumerable, T value) => ((Queue<T>)enumerable).Enqueue(value);
+ protected override void Clear(IEnumerable<T> enumerable) => ((Queue<T>)enumerable).Clear();
+ protected override bool Contains(IEnumerable<T> enumerable, T value) => ((Queue<T>)enumerable).Contains(value);
+ protected override void CopyTo(IEnumerable<T> enumerable, T[] array, int index) => ((Queue<T>)enumerable).CopyTo(array, index);
protected override bool Remove(IEnumerable<T> enumerable) { ((Queue<T>)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
return new Queue<string>();
}
- 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);
/// <summary>
/// Returns a set of ModifyEnumerable delegates that modify the enumerable passed to them.
{
public class SortedList_Generic_Tests_Keys : IList_Generic_Tests<string>
{
- 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<ModifyEnumerable> ModifyEnumerables { get { return new List<ModifyEnumerable>(); } }
+ protected override bool DefaultValueAllowed => false;
+ protected override bool DuplicateValuesAllowed => false;
+ protected override bool IsReadOnly => true;
+ protected override bool DefaultValueWhenNotAllowed_Throws => true;
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
protected override IList<string> GenericIListFactory()
{
Debug.Assert(false);
}
- protected override IEnumerable<ModifyEnumerable> ModifyEnumerables { get { return new List<ModifyEnumerable>(); } }
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
}
}
{
public class SortedList_Generic_Tests_Values : IList_Generic_Tests<string>
{
- protected override bool DefaultValueAllowed { get { return true; } }
- protected override bool DuplicateValuesAllowed { get { return true; } }
- protected override bool IsReadOnly { get { return true; } }
- protected override IEnumerable<ModifyEnumerable> ModifyEnumerables { get { return new List<ModifyEnumerable>(); } }
+ protected override bool DefaultValueAllowed => true;
+ protected override bool DuplicateValuesAllowed => true;
+ protected override bool IsReadOnly => true;
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
protected override IList<string> GenericIListFactory()
{
Debug.Assert(false);
}
- protected override IEnumerable<ModifyEnumerable> ModifyEnumerables { get { return new List<ModifyEnumerable>(); } }
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
}
}
if (count > 0)
Assert.True(enumerator.MoveNext());
}
-
+
+ protected override Type ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException);
+
#endregion
#region Constructor_IComparer
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<int, int>
{
- protected override bool DefaultValueAllowed { get { return true; } }
+ protected override bool DefaultValueAllowed => true;
protected override KeyValuePair<int, int> CreateT(int seed)
{
Random rand = new Random(seed);
return rand.Next();
}
- protected override int CreateTValue(int seed)
- {
- return CreateTKey(seed);
- }
+ protected override int CreateTValue(int seed) => CreateTKey(seed);
}
[OuterLoop]
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
return rand.Next();
}
- protected override bool DefaultValueAllowed
- {
- get
- {
- return true;
- }
- }
+ protected override bool DefaultValueAllowed => true;
}
[OuterLoop]
return stack;
}
+ protected override Type IGenericSharedAPI_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException);
+
#endregion
protected override IEnumerable<T> GenericIEnumerableFactory()
return GenericStackFactory(count);
}
- protected override int Count(IEnumerable<T> enumerable) { return ((Stack<T>)enumerable).Count; }
- protected override void Add(IEnumerable<T> enumerable, T value) { ((Stack<T>)enumerable).Push(value); }
- protected override void Clear(IEnumerable<T> enumerable) { ((Stack<T>)enumerable).Clear(); }
- protected override bool Contains(IEnumerable<T> enumerable, T value) { return ((Stack<T>)enumerable).Contains(value); }
- protected override void CopyTo(IEnumerable<T> enumerable, T[] array, int index) { ((Stack<T>)enumerable).CopyTo(array, index); }
+ protected override int Count(IEnumerable<T> enumerable) => ((Stack<T>)enumerable).Count;
+ protected override void Add(IEnumerable<T> enumerable, T value) => ((Stack<T>)enumerable).Push(value);
+ protected override void Clear(IEnumerable<T> enumerable) => ((Stack<T>)enumerable).Clear();
+ protected override bool Contains(IEnumerable<T> enumerable, T value) => ((Stack<T>)enumerable).Contains(value);
+ protected override void CopyTo(IEnumerable<T> enumerable, T[] array, int index) => ((Stack<T>)enumerable).CopyTo(array, index);
protected override bool Remove(IEnumerable<T> enumerable) { ((Stack<T>)enumerable).Pop(); return true; }
- protected override bool Enumerator_Current_UndefinedOperation_Throws { get { return true; } }
+ protected override bool Enumerator_Current_UndefinedOperation_Throws => true;
#endregion
return new Stack<string>();
}
- 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);
/// <summary>
/// Returns a set of ModifyEnumerable delegates that modify the enumerable passed to them.