blob: 557fb4739f0cd9079f189d83816cac5a25b4c66a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// 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 System.Diagnostics;
using Xunit;
namespace System.Collections.Tests
{
public class HashtableKeysTests : ICollection_NonGeneric_Tests
{
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 bool IsReadOnly => true;
protected override EnumerableOrder Order => EnumerableOrder.Unspecified;
protected override bool Enumerator_Current_UndefinedOperation_Throws => true;
protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
protected override ICollection NonGenericICollectionFactory() => new Hashtable().Keys;
protected override ICollection NonGenericICollectionFactory(int count)
{
Hashtable hashtable = new Hashtable();
int seed = 13453;
for (int i = 0; i < count; i++)
hashtable.Add(CreateT(seed++), CreateT(seed++));
return hashtable.Keys;
}
private string 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);
}
protected override void AddToCollection(ICollection collection, int numberOfItemsToAdd) => Debug.Assert(false);
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
public override void ICollection_NonGeneric_CopyTo_NonZeroLowerBound(int count)
{
ICollection collection = NonGenericICollectionFactory(count);
Array arr = Array.CreateInstance(typeof(object), new int[] { count }, new int[] { 2 });
Assert.Equal(1, arr.Rank);
Assert.Equal(2, arr.GetLowerBound(0));
// A bug in Hashtable.Keys.CopyTo means we don't check the lower bounds of the destination array
if (count == 0)
{
collection.CopyTo(arr, 0);
}
else
{
Assert.Throws<IndexOutOfRangeException>(() => collection.CopyTo(arr, 0));
}
}
}
}
|