Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@@ -27,9 +27,9 @@ namespace System.Collections.Specialized
private const int FixedSizeCutoverPoint = 6;
// Instance variables. This keeps the HybridDictionary very light-weight when empty
private ListDictionary _list;
private Hashtable _hashtable;
private readonly bool _caseInsensitive;
private ListDictionary list; // Do not rename (binary serialization)
private Hashtable hashtable; // Do not rename (binary serialization)
private readonly bool caseInsensitive; // Do not rename (binary serialization)
public HybridDictionary()
{
@@ -41,21 +41,21 @@ namespace System.Collections.Specialized
public HybridDictionary(bool caseInsensitive)
{
_caseInsensitive = caseInsensitive;
this.caseInsensitive = caseInsensitive;
}
public HybridDictionary(int initialSize, bool caseInsensitive)
{
_caseInsensitive = caseInsensitive;
this.caseInsensitive = caseInsensitive;
if (initialSize >= FixedSizeCutoverPoint)
{
if (caseInsensitive)
{
_hashtable = new Hashtable(initialSize, StringComparer.OrdinalIgnoreCase);
hashtable = new Hashtable(initialSize, StringComparer.OrdinalIgnoreCase);
}
else
{
_hashtable = new Hashtable(initialSize);
hashtable = new Hashtable(initialSize);
}
}
}
@@ -68,10 +68,10 @@ namespace System.Collections.Specialized
// Although we never made the same guarantee for HybridDictionary,
// it is still nice to do the same thing here since we have recommended
// HybridDictionary as replacement for Hashtable.
ListDictionary cachedList = _list;
if (_hashtable != null)
ListDictionary cachedList = list;
if (hashtable != null)
{
return _hashtable[key];
return hashtable[key];
}
else if (cachedList != null)
{
@@ -90,26 +90,26 @@ namespace System.Collections.Specialized
}
set
{
if (_hashtable != null)
if (hashtable != null)
{
_hashtable[key] = value;
hashtable[key] = value;
}
else if (_list != null)
else if (list != null)
{
if (_list.Count >= CutoverPoint - 1)
if (list.Count >= CutoverPoint - 1)
{
ChangeOver();
_hashtable[key] = value;
hashtable[key] = value;
}
else
{
_list[key] = value;
list[key] = value;
}
}
else
{
_list = new ListDictionary(_caseInsensitive ? StringComparer.OrdinalIgnoreCase : null);
_list[key] = value;
list = new ListDictionary(caseInsensitive ? StringComparer.OrdinalIgnoreCase : null);
list[key] = value;
}
}
}
@@ -118,19 +118,19 @@ namespace System.Collections.Specialized
{
get
{
if (_list == null)
if (list == null)
{
_list = new ListDictionary(_caseInsensitive ? StringComparer.OrdinalIgnoreCase : null);
list = new ListDictionary(caseInsensitive ? StringComparer.OrdinalIgnoreCase : null);
}
return _list;
return list;
}
}
private void ChangeOver()
{
IDictionaryEnumerator en = _list.GetEnumerator();
IDictionaryEnumerator en = list.GetEnumerator();
Hashtable newTable;
if (_caseInsensitive)
if (caseInsensitive)
{
newTable = new Hashtable(InitialHashtableSize, StringComparer.OrdinalIgnoreCase);
}
@@ -146,18 +146,18 @@ namespace System.Collections.Specialized
// Keep the order of writing to hashtable and list.
// We assume we will see the change in hashtable if list is set to null in
// this method in another reader thread.
_hashtable = newTable;
_list = null;
hashtable = newTable;
list = null;
}
public int Count
{
get
{
ListDictionary cachedList = _list;
if (_hashtable != null)
ListDictionary cachedList = list;
if (hashtable != null)
{
return _hashtable.Count;
return hashtable.Count;
}
else if (cachedList != null)
{
@@ -174,9 +174,9 @@ namespace System.Collections.Specialized
{
get
{
if (_hashtable != null)
if (hashtable != null)
{
return _hashtable.Keys;
return hashtable.Keys;
}
else
{
@@ -221,9 +221,9 @@ namespace System.Collections.Specialized
{
get
{
if (_hashtable != null)
if (hashtable != null)
{
return _hashtable.Values;
return hashtable.Values;
}
else
{
@@ -234,52 +234,52 @@ namespace System.Collections.Specialized
public void Add(object key, object value)
{
if (_hashtable != null)
if (hashtable != null)
{
_hashtable.Add(key, value);
hashtable.Add(key, value);
}
else
{
if (_list == null)
if (list == null)
{
_list = new ListDictionary(_caseInsensitive ? StringComparer.OrdinalIgnoreCase : null);
_list.Add(key, value);
list = new ListDictionary(caseInsensitive ? StringComparer.OrdinalIgnoreCase : null);
list.Add(key, value);
}
else if (_list.Count + 1 >= CutoverPoint)
else if (list.Count + 1 >= CutoverPoint)
{
ChangeOver();
_hashtable.Add(key, value);
hashtable.Add(key, value);
}
else
{
_list.Add(key, value);
list.Add(key, value);
}
}
}
public void Clear()
{
if (_hashtable != null)
if (hashtable != null)
{
Hashtable cachedHashtable = _hashtable;
_hashtable = null;
Hashtable cachedHashtable = hashtable;
hashtable = null;
cachedHashtable.Clear();
}
if (_list != null)
if (list != null)
{
ListDictionary cachedList = _list;
_list = null;
ListDictionary cachedList = list;
list = null;
cachedList.Clear();
}
}
public bool Contains(object key)
{
ListDictionary cachedList = _list;
if (_hashtable != null)
ListDictionary cachedList = list;
if (hashtable != null)
{
return _hashtable.Contains(key);
return hashtable.Contains(key);
}
else if (cachedList != null)
{
@@ -294,9 +294,9 @@ namespace System.Collections.Specialized
public void CopyTo(Array array, int index)
{
if (_hashtable != null)
if (hashtable != null)
{
_hashtable.CopyTo(array, index);
hashtable.CopyTo(array, index);
}
else
{
@@ -306,39 +306,39 @@ namespace System.Collections.Specialized
public IDictionaryEnumerator GetEnumerator()
{
if (_hashtable != null)
if (hashtable != null)
{
return _hashtable.GetEnumerator();
return hashtable.GetEnumerator();
}
if (_list == null)
if (list == null)
{
_list = new ListDictionary(_caseInsensitive ? StringComparer.OrdinalIgnoreCase : null);
list = new ListDictionary(caseInsensitive ? StringComparer.OrdinalIgnoreCase : null);
}
return _list.GetEnumerator();
return list.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
if (_hashtable != null)
if (hashtable != null)
{
return _hashtable.GetEnumerator();
return hashtable.GetEnumerator();
}
if (_list == null)
if (list == null)
{
_list = new ListDictionary(_caseInsensitive ? StringComparer.OrdinalIgnoreCase : null);
list = new ListDictionary(caseInsensitive ? StringComparer.OrdinalIgnoreCase : null);
}
return _list.GetEnumerator();
return list.GetEnumerator();
}
public void Remove(object key)
{
if (_hashtable != null)
if (hashtable != null)
{
_hashtable.Remove(key);
hashtable.Remove(key);
}
else if (_list != null)
else if (list != null)
{
_list.Remove(key);
list.Remove(key);
}
else if (key == null)
{

View File

@@ -373,8 +373,7 @@ namespace System.Collections.Specialized
_current = null;
}
}
private class NodeKeyValueCollection : ICollection
{
private ListDictionary _list;
@@ -495,11 +494,14 @@ namespace System.Collections.Specialized
}
[Serializable]
private class DictionaryNode
#if !MONO
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public class DictionaryNode
{
public object key;
public object value;
public DictionaryNode next;
public object key; // Do not rename (binary serialization)
public object value; // Do not rename (binary serialization)
public DictionaryNode next; // Do not rename (binary serialization)
}
}
}

View File

@@ -22,21 +22,8 @@ namespace System.Collections.Specialized
/// the key or with the index.</para>
/// </devdoc>
[Serializable]
#if !MONO
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public abstract class NameObjectCollectionBase : ICollection, ISerializable, IDeserializationCallback
{
// const names used for serialization
private const String ReadOnlyName = "ReadOnly";
private const String CountName = "Count";
private const String ComparerName = "Comparer";
private const String HashCodeProviderName = "HashProvider";
private const String KeysName = "Keys";
private const String ValuesName = "Values";
private const String KeyComparerName = "KeyComparer";
private const String VersionName = "Version";
private bool _readOnly = false;
private ArrayList _entriesArray;
private IEqualityComparer _keyComparer;
@@ -44,8 +31,6 @@ namespace System.Collections.Specialized
private volatile NameObjectEntry _nullKeyEntry;
private KeysCollection _keys;
private int _version;
private SerializationInfo _serializationInfo;
[NonSerialized]
private Object _syncRoot;
private static readonly StringComparer s_defaultComparer = CultureInfo.InvariantCulture.CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);
@@ -94,146 +79,17 @@ namespace System.Collections.Specialized
protected NameObjectCollectionBase(SerializationInfo info, StreamingContext context)
{
_serializationInfo = info;
throw new PlatformNotSupportedException();
}
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException(nameof(info));
}
info.AddValue(ReadOnlyName, _readOnly);
// Maintain backward serialization compatibility if new APIs are not used.
if (_keyComparer == s_defaultComparer)
{
info.AddValue(HashCodeProviderName, CaseInsensitiveHashCodeProvider.DefaultInvariant, typeof(IHashCodeProvider));
info.AddValue(ComparerName, CaseInsensitiveComparer.DefaultInvariant, typeof(IComparer));
}
else if (_keyComparer == null)
{
info.AddValue(HashCodeProviderName, null, typeof(IHashCodeProvider));
info.AddValue(ComparerName, null, typeof(IComparer));
}
else if (_keyComparer is CompatibleComparer)
{
CompatibleComparer c = (CompatibleComparer)_keyComparer;
info.AddValue(HashCodeProviderName, c.HashCodeProvider, typeof(IHashCodeProvider));
info.AddValue(ComparerName, c.Comparer, typeof(IComparer));
}
else
{
info.AddValue(KeyComparerName, _keyComparer, typeof(IEqualityComparer));
}
int count = _entriesArray.Count;
info.AddValue(CountName, count);
string[] keys = new string[count];
object[] values = new object[count];
for (int i = 0; i < count; i++)
{
NameObjectEntry entry = (NameObjectEntry)_entriesArray[i];
keys[i] = entry.Key;
values[i] = entry.Value;
}
info.AddValue(KeysName, keys, typeof(String[]));
info.AddValue(ValuesName, values, typeof(Object[]));
info.AddValue(VersionName, _version);
throw new PlatformNotSupportedException();
}
public virtual void OnDeserialization(object sender)
{
if (_keyComparer != null)
{
//Somebody had a dependency on this and fixed us up before the ObjectManager got to it.
return;
}
if (_serializationInfo == null)
{
throw new SerializationException();
}
SerializationInfo info = _serializationInfo;
_serializationInfo = null;
bool readOnly = false;
int count = 0;
string[] keys = null;
object[] values = null;
IHashCodeProvider hashProvider = null;
IComparer comparer = null;
bool hasVersion = false;
int serializedVersion = 0;
SerializationInfoEnumerator enumerator = info.GetEnumerator();
while (enumerator.MoveNext())
{
switch (enumerator.Name)
{
case ReadOnlyName:
readOnly = info.GetBoolean(ReadOnlyName); ;
break;
case HashCodeProviderName:
hashProvider = (IHashCodeProvider)info.GetValue(HashCodeProviderName, typeof(IHashCodeProvider)); ;
break;
case ComparerName:
comparer = (IComparer)info.GetValue(ComparerName, typeof(IComparer));
break;
case KeyComparerName:
_keyComparer = (IEqualityComparer)info.GetValue(KeyComparerName, typeof(IEqualityComparer));
break;
case CountName:
count = info.GetInt32(CountName);
break;
case KeysName:
keys = (String[])info.GetValue(KeysName, typeof(String[]));
break;
case ValuesName:
values = (Object[])info.GetValue(ValuesName, typeof(Object[]));
break;
case VersionName:
hasVersion = true;
serializedVersion = info.GetInt32(VersionName);
break;
}
}
if (_keyComparer == null)
{
if (comparer == null || hashProvider == null)
{
throw new SerializationException();
}
else
{
// create a new key comparer for V1 Object
_keyComparer = new CompatibleComparer(hashProvider, comparer);
}
}
if (keys == null || values == null)
{
throw new SerializationException();
}
Reset(count);
for (int i = 0; i < count; i++)
{
BaseAdd(keys[i], values[i]);
}
_readOnly = readOnly; // after collection populated
if (hasVersion)
{
_version = serializedVersion;
}
throw new PlatformNotSupportedException();
}
//

View File

@@ -18,13 +18,10 @@ namespace System.Collections.Specialized
/// can be accessed either with the hash code of the key or with the index.</para>
/// </devdoc>
[Serializable]
#if !MONO
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public class NameValueCollection : NameObjectCollectionBase
{
private String[] _all;
private String[] _allKeys;
private String[] _all; // Do not rename (binary serialization)
private String[] _allKeys; // Do not rename (binary serialization)
//
// Constructors

View File

@@ -34,10 +34,10 @@ namespace System.Collections.Specialized
private Object _syncRoot;
private SerializationInfo _siInfo; //A temporary variable which we need during deserialization.
private const string KeyComparerName = "KeyComparer";
private const string ArrayListName = "ArrayList";
private const string ReadOnlyName = "ReadOnly";
private const string InitCapacityName = "InitialCapacity";
private const string KeyComparerName = "KeyComparer"; // Do not rename (binary serialization)
private const string ArrayListName = "ArrayList"; // Do not rename (binary serialization)
private const string ReadOnlyName = "ReadOnly"; // Do not rename (binary serialization)
private const string InitCapacityName = "InitialCapacity"; // Do not rename (binary serialization)
public OrderedDictionary() : this(0)
{

View File

@@ -21,7 +21,7 @@ namespace System.Collections.Specialized
// That means using ToLower in each property on this type. Also for backwards
// compatibility, we will be converting strings to lower-case, which has a
// problem for some Georgian alphabets.
private readonly Hashtable _contents = new Hashtable();
private readonly Hashtable contents = new Hashtable(); // Do not rename (binary serialization)
/// <devdoc>
@@ -41,7 +41,7 @@ namespace System.Collections.Specialized
{
get
{
return _contents.Count;
return contents.Count;
}
}
@@ -54,7 +54,7 @@ namespace System.Collections.Specialized
{
get
{
return _contents.IsSynchronized;
return contents.IsSynchronized;
}
}
@@ -70,7 +70,7 @@ namespace System.Collections.Specialized
throw new ArgumentNullException(nameof(key));
}
return (string)_contents[key.ToLowerInvariant()];
return (string)contents[key.ToLowerInvariant()];
}
set
{
@@ -79,7 +79,7 @@ namespace System.Collections.Specialized
throw new ArgumentNullException(nameof(key));
}
_contents[key.ToLowerInvariant()] = value;
contents[key.ToLowerInvariant()] = value;
}
}
@@ -90,7 +90,7 @@ namespace System.Collections.Specialized
{
get
{
return _contents.Keys;
return contents.Keys;
}
}
@@ -102,7 +102,7 @@ namespace System.Collections.Specialized
{
get
{
return _contents.SyncRoot;
return contents.SyncRoot;
}
}
@@ -113,7 +113,7 @@ namespace System.Collections.Specialized
{
get
{
return _contents.Values;
return contents.Values;
}
}
@@ -127,7 +127,7 @@ namespace System.Collections.Specialized
throw new ArgumentNullException(nameof(key));
}
_contents.Add(key.ToLowerInvariant(), value);
contents.Add(key.ToLowerInvariant(), value);
}
/// <devdoc>
@@ -135,7 +135,7 @@ namespace System.Collections.Specialized
/// </devdoc>
public virtual void Clear()
{
_contents.Clear();
contents.Clear();
}
/// <devdoc>
@@ -148,7 +148,7 @@ namespace System.Collections.Specialized
throw new ArgumentNullException(nameof(key));
}
return _contents.ContainsKey(key.ToLowerInvariant());
return contents.ContainsKey(key.ToLowerInvariant());
}
/// <devdoc>
@@ -156,7 +156,7 @@ namespace System.Collections.Specialized
/// </devdoc>
public virtual bool ContainsValue(string value)
{
return _contents.ContainsValue(value);
return contents.ContainsValue(value);
}
/// <devdoc>
@@ -165,7 +165,7 @@ namespace System.Collections.Specialized
/// </devdoc>
public virtual void CopyTo(Array array, int index)
{
_contents.CopyTo(array, index);
contents.CopyTo(array, index);
}
/// <devdoc>
@@ -173,7 +173,7 @@ namespace System.Collections.Specialized
/// </devdoc>
public virtual IEnumerator GetEnumerator()
{
return _contents.GetEnumerator();
return contents.GetEnumerator();
}
/// <devdoc>
@@ -186,7 +186,7 @@ namespace System.Collections.Specialized
throw new ArgumentNullException(nameof(key));
}
_contents.Remove(key.ToLowerInvariant());
contents.Remove(key.ToLowerInvariant());
}
}
}

View File

@@ -88,11 +88,11 @@ namespace System.Collections.Specialized.Tests
AssertExtensions.Throws<ArgumentNullException>("key", () => hybridDictionary.Add(null, "value"));
hybridDictionary.Add("key", "value");
Assert.Throws<ArgumentException>(null, () => hybridDictionary.Add("key", "value"));
AssertExtensions.Throws<ArgumentException>(null, () => hybridDictionary.Add("key", "value"));
if (caseInsensitive)
{
Assert.Throws<ArgumentException>(null, () => hybridDictionary.Add("KEY", "value"));
AssertExtensions.Throws<ArgumentException>(null, () => hybridDictionary.Add("KEY", "value"));
}
else
{

View File

@@ -69,7 +69,7 @@ namespace System.Collections.Specialized.Tests
Assert.Equal(i + 1, added.Count);
CollectionAsserts.Equal(keys, added.Keys);
CollectionAsserts.Equal(values, added.Values);
Assert.Throws<ArgumentException>(() => added.Add(key, value));
AssertExtensions.Throws<ArgumentException>(null, () => added.Add(key, value));
added[key] = value;
}
}
@@ -96,7 +96,7 @@ namespace System.Collections.Specialized.Tests
comparer.AssertCompared(i + 1, () => Assert.Equal(value, added[key]));
comparer.AssertCompared(i + 1, () => Assert.True(added.Contains(key)));
Assert.Equal(i + 1, added.Count);
comparer.AssertCompared(i + 1, () => Assert.Throws<ArgumentException>(() => added.Add(key, "duplicate")));
comparer.AssertCompared(i + 1, () => AssertExtensions.Throws<ArgumentException>(null, () => added.Add(key, "duplicate")));
}
Assert.Equal(s_dictionaryData.Length, added.Count);
@@ -110,7 +110,7 @@ namespace System.Collections.Specialized.Tests
Assert.True(added.Contains(middleKey));
// Index is 0-based, count is 1-based
// ... Add throws exception
comparer.AssertCompared(middleIndex + 1, () => Assert.Throws<ArgumentException>(() => added.Add(middleKey, "middleValue")));
comparer.AssertCompared(middleIndex + 1, () => AssertExtensions.Throws<ArgumentException>(null, () => added.Add(middleKey, "middleValue")));
Assert.Equal(middleValue, added[middleKey]);
Assert.True(added.Contains(middleKey));
}

View File

@@ -49,19 +49,19 @@ namespace System.Collections.Specialized.Tests
ICollection collection = nameObjectCollection;
AssertExtensions.Throws<ArgumentNullException>("array", () => collection.CopyTo(null, 0));
Assert.Throws<ArgumentException>(() => collection.CopyTo(new string[count, count], 0));
AssertExtensions.Throws<ArgumentException>("array", null, () => collection.CopyTo(new string[count, count], 0));
if (count > 0)
{
Assert.Throws<ArgumentException>(null, () => collection.CopyTo(new string[0], 0));
Assert.Throws<ArgumentException>(null, () => collection.CopyTo(new string[count - 1], 0));
AssertExtensions.Throws<ArgumentException>(null, () => collection.CopyTo(new string[0], 0));
AssertExtensions.Throws<ArgumentException>(null, () => collection.CopyTo(new string[count - 1], 0));
Assert.Throws<InvalidCastException>(() => collection.CopyTo(new Foo[count], 0));
}
AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.CopyTo(new string[count], -1));
Assert.Throws<ArgumentException>(null, () => collection.CopyTo(new string[count], 1));
Assert.Throws<ArgumentException>(null, () => collection.CopyTo(new string[count], count + 1));
AssertExtensions.Throws<ArgumentException>(null, () => collection.CopyTo(new string[count], 1));
AssertExtensions.Throws<ArgumentException>(null, () => collection.CopyTo(new string[count], count + 1));
}
}
}

View File

@@ -156,19 +156,19 @@ namespace System.Collections.Specialized.Tests
ICollection keysCollection = keys;
AssertExtensions.Throws<ArgumentNullException>("array", () => keysCollection.CopyTo(null, 0));
Assert.Throws<ArgumentException>(() => keysCollection.CopyTo(new string[count, count], 0));
AssertExtensions.Throws<ArgumentException>("array", null, () => keysCollection.CopyTo(new string[count, count], 0));
if (count > 0)
{
Assert.Throws<ArgumentException>(null, () => keysCollection.CopyTo(new string[0], 0));
Assert.Throws<ArgumentException>(null, () => keysCollection.CopyTo(new string[count - 1], 0));
AssertExtensions.Throws<ArgumentException>(null, () => keysCollection.CopyTo(new string[0], 0));
AssertExtensions.Throws<ArgumentException>(null, () => keysCollection.CopyTo(new string[count - 1], 0));
Assert.Throws<InvalidCastException>(() => keysCollection.CopyTo(new Foo[count], 0));
}
AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => keysCollection.CopyTo(new string[count], -1));
Assert.Throws<ArgumentException>(null, () => keysCollection.CopyTo(new string[count], 1));
Assert.Throws<ArgumentException>(null, () => keysCollection.CopyTo(new string[count], count + 1));
AssertExtensions.Throws<ArgumentException>(null, () => keysCollection.CopyTo(new string[count], 1));
AssertExtensions.Throws<ArgumentException>(null, () => keysCollection.CopyTo(new string[count], count + 1));
}
}
}

View File

@@ -63,11 +63,11 @@ namespace System.Collections.Specialized.Tests
AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => nameValueCollection.CopyTo(new string[count], -1));
Assert.Throws<ArgumentException>(null, () => nameValueCollection.CopyTo(new string[count], 1));
Assert.Throws<ArgumentException>(null, () => nameValueCollection.CopyTo(new string[count], count + 1));
AssertExtensions.Throws<ArgumentException>(null, () => nameValueCollection.CopyTo(new string[count], 1));
AssertExtensions.Throws<ArgumentException>(null, () => nameValueCollection.CopyTo(new string[count], count + 1));
if (count > 0)
{
Assert.Throws<ArgumentException>(null, () => nameValueCollection.CopyTo(new string[count], count));
AssertExtensions.Throws<ArgumentException>(null, () => nameValueCollection.CopyTo(new string[count], count));
Assert.Throws<InvalidCastException>(() => nameValueCollection.CopyTo(new DictionaryEntry[count], 0));
}
else

View File

@@ -42,7 +42,7 @@ namespace System.Collections.Specialized.Tests
var eqComp = new CaseInsensitiveEqualityComparer();
var d1 = new OrderedDictionary(eqComp);
d1.Add("foo", "bar");
Assert.Throws<ArgumentException>(() => d1.Add("FOO", "bar"));
AssertExtensions.Throws<ArgumentException>(null, () => d1.Add("FOO", "bar"));
// The equality comparer should also test for a non-existent key
d1.Remove("foofoo");
@@ -322,12 +322,12 @@ namespace System.Collections.Specialized.Tests
d.Add("5", "foo6");
Assert.Equal("foo6", d["5"]);
Assert.Throws<ArgumentException>(() => d.Add((int)5, "foo"));
Assert.Throws<ArgumentException>(() => d.Add((double)5, "foo"));
Assert.Throws<ArgumentException>(() => d.Add((long)5, "foo"));
Assert.Throws<ArgumentException>(() => d.Add((short)5, "foo"));
Assert.Throws<ArgumentException>(() => d.Add((uint)5, "foo"));
Assert.Throws<ArgumentException>(() => d.Add("5", "foo"));
AssertExtensions.Throws<ArgumentException>(null, () => d.Add((int)5, "foo"));
AssertExtensions.Throws<ArgumentException>(null, () => d.Add((double)5, "foo"));
AssertExtensions.Throws<ArgumentException>(null, () => d.Add((long)5, "foo"));
AssertExtensions.Throws<ArgumentException>(null, () => d.Add((short)5, "foo"));
AssertExtensions.Throws<ArgumentException>(null, () => d.Add((uint)5, "foo"));
AssertExtensions.Throws<ArgumentException>(null, () => d.Add("5", "foo"));
Assert.Throws<ArgumentNullException>(() => d.Add(null, "foobar"));
}
@@ -403,7 +403,7 @@ namespace System.Collections.Specialized.Tests
Assert.Throws<ArgumentNullException>(() => d.CopyTo(null, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => d.CopyTo(arr, -1));
Assert.Throws<ArgumentException>(() => d.CopyTo(arr, 3));
AssertExtensions.Throws<ArgumentException>(null, () => d.CopyTo(arr, 3));
d.CopyTo(arr, 0);
for (int i = 0; i < 2; i++)
@@ -497,7 +497,7 @@ namespace System.Collections.Specialized.Tests
d.Insert(0, "foo", "bar");
Assert.Equal("bar", d["foo"]);
Assert.Equal("bar", d[0]);
Assert.Throws<ArgumentException>(() => d.Insert(0, "foo", "bar"));
AssertExtensions.Throws<ArgumentException>(null, () => d.Insert(0, "foo", "bar"));
d.Insert(0, "aaa", "bbb");
Assert.Equal("bbb", d["aaa"]);

View File

@@ -234,8 +234,8 @@ namespace System.Collections.Specialized.Tests
Assert.Throws<ArgumentOutOfRangeException>(() => collection.CopyTo(data, -1));
if (data.Length > 0)
{
Assert.Throws<ArgumentException>(() => collection.CopyTo(new string[0], data.Length - 1));
Assert.Throws<ArgumentException>(() => collection.CopyTo(new string[data.Length - 1], 0));
AssertExtensions.Throws<ArgumentException>("destinationArray", "", () => collection.CopyTo(new string[0], data.Length - 1));
AssertExtensions.Throws<ArgumentException>("destinationArray", "", () => collection.CopyTo(new string[data.Length - 1], 0));
}
// As explicit interface implementation
@@ -243,8 +243,8 @@ namespace System.Collections.Specialized.Tests
Assert.Throws<ArgumentOutOfRangeException>(() => ((ICollection)collection).CopyTo(data, -1));
if (data.Length > 0)
{
Assert.Throws<ArgumentException>(() => ((ICollection)collection).CopyTo(new string[0], data.Length - 1));
Assert.Throws<ArgumentException>(() => ((ICollection)collection).CopyTo(new string[data.Length - 1], 0));
AssertExtensions.Throws<ArgumentException>("destinationArray", "", () => ((ICollection)collection).CopyTo(new string[0], data.Length - 1));
AssertExtensions.Throws<ArgumentException>("destinationArray", "", () => ((ICollection)collection).CopyTo(new string[data.Length - 1], 0));
}
}

View File

@@ -44,9 +44,9 @@ namespace System.Collections.Specialized.Tests
AssertExtensions.Throws<ArgumentNullException>("key", () => stringDictionary.Add(null, "value"));
// Duplicate key
Assert.Throws<ArgumentException>(null, () => stringDictionary.Add("Key", "value"));
Assert.Throws<ArgumentException>(null, () => stringDictionary.Add("KEY", "value"));
Assert.Throws<ArgumentException>(null, () => stringDictionary.Add("key", "value"));
AssertExtensions.Throws<ArgumentException>(null, () => stringDictionary.Add("Key", "value"));
AssertExtensions.Throws<ArgumentException>(null, () => stringDictionary.Add("KEY", "value"));
AssertExtensions.Throws<ArgumentException>(null, () => stringDictionary.Add("key", "value"));
}
}
}

View File

@@ -48,10 +48,10 @@ namespace System.Collections.Specialized.Tests
Assert.Throws<ArgumentNullException>(() => stringDictionary.CopyTo(null, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => stringDictionary.CopyTo(new string[count], -1));
Assert.Throws<ArgumentException>(() => stringDictionary.CopyTo(new string[count], count / 2 + 1));
Assert.Throws<ArgumentException>(() => stringDictionary.CopyTo(new string[count], count));
Assert.Throws<ArgumentException>(() => stringDictionary.CopyTo(new string[count], count + 1));
Assert.Throws<ArgumentException>(() => stringDictionary.CopyTo(new string[count, count], 0));
AssertExtensions.Throws<ArgumentException>(null, () => stringDictionary.CopyTo(new string[count], count / 2 + 1));
AssertExtensions.Throws<ArgumentException>(null, () => stringDictionary.CopyTo(new string[count], count));
AssertExtensions.Throws<ArgumentException>(null, () => stringDictionary.CopyTo(new string[count], count + 1));
AssertExtensions.Throws<ArgumentException>("array", null, () => stringDictionary.CopyTo(new string[count, count], 0));
}
}
}

View File

@@ -8,9 +8,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="$(CommonTestPath)\System\AssertExtensions.cs">
<Link>Common\System\AssertExtensions.cs</Link>
</Compile>
<!-- Common Collections tests -->
<Compile Include="$(CommonTestPath)\System\Collections\CollectionAsserts.cs">
<Link>Common\System\Collections\CollectionAsserts.cs</Link>