Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 49e06fc

Browse files
committed
Test fixups
1 parent 16b1b21 commit 49e06fc

File tree

10 files changed

+17
-46
lines changed

10 files changed

+17
-46
lines changed

src/Common/tests/System/Collections/ICollection.NonGeneric.Tests.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ protected virtual ICollection NonGenericICollectionFactory(int count)
8383
/// </summary>
8484
protected virtual bool ICollection_NonGeneric_HasNullSyncRoot => false;
8585

86-
/// <summary>
87-
/// Used for the ICollection_NonGeneric_SyncRootType_MatchesExcepted test. Most SyncRoots are created
88-
/// using System.Threading.Interlocked.CompareExchange(ref _syncRoot, new Object(), null)
89-
/// so we should test that the SyncRoot is the type we expect.
90-
/// </summary>
91-
protected virtual Type ICollection_NonGeneric_SyncRootType => typeof(object);
92-
9386
/// <summary>
9487
/// Used for the ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowsArgumentException tests. Some
9588
/// implementations throw a different exception type (e.g. ArgumentOutOfRangeException).
@@ -147,22 +140,6 @@ public void ICollection_NonGeneric_SyncRoot(int count)
147140
{
148141
Assert.Equal(ICollection_NonGeneric_HasNullSyncRoot, collection.SyncRoot == null);
149142
Assert.Same(collection.SyncRoot, collection.SyncRoot);
150-
151-
if (!ICollection_NonGeneric_HasNullSyncRoot)
152-
{
153-
Assert.IsType(ICollection_NonGeneric_SyncRootType, collection.SyncRoot);
154-
155-
if (ICollection_NonGeneric_SyncRootType == collection.GetType())
156-
{
157-
// If we expect the SyncRoot to be the same type as the collection,
158-
// the SyncRoot should be the same as the collection (e.g. HybridDictionary)
159-
Assert.Same(collection, collection.SyncRoot);
160-
}
161-
else
162-
{
163-
Assert.NotSame(collection, collection.SyncRoot);
164-
}
165-
}
166143
}
167144
else
168145
{

src/System.Collections.NonGeneric/tests/ArrayListTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,12 +2576,12 @@ public void GetSyncRoot()
25762576
_arrGrandDaughter = ArrayList.Synchronized(arrMother2);
25772577
_arrDaughter = ArrayList.Synchronized(arrMother2);
25782578

2579-
Assert.False(arrMother2.SyncRoot is ArrayList);
2580-
Assert.False(arrSon1.SyncRoot is ArrayList);
2581-
Assert.False(arrSon2.SyncRoot is ArrayList);
2582-
Assert.False(_arrDaughter.SyncRoot is ArrayList);
2579+
Assert.True(arrMother2.SyncRoot is ArrayList);
2580+
Assert.True(arrSon1.SyncRoot is ArrayList);
2581+
Assert.True(arrSon2.SyncRoot is ArrayList);
2582+
Assert.True(_arrDaughter.SyncRoot is ArrayList);
25832583
Assert.Equal(arrSon1.SyncRoot, arrMother2.SyncRoot);
2584-
Assert.False(_arrGrandDaughter.SyncRoot is ArrayList);
2584+
Assert.True(_arrGrandDaughter.SyncRoot is ArrayList);
25852585

25862586
arrMother2 = new ArrayList();
25872587
for (int i = 0; i < NumberOfElements; i++)

src/System.Collections.NonGeneric/tests/CollectionBaseTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ public static void SyncRoot()
299299
// SyncRoot should be the reference to the underlying collection, not to MyCollection
300300
var collBase = new MyCollection();
301301
object syncRoot = collBase.SyncRoot;
302-
Assert.NotEqual(syncRoot, collBase);
303-
Assert.Equal(collBase.SyncRoot, collBase.SyncRoot);
302+
Assert.NotNull(syncRoot);
303+
Assert.Same(collBase.SyncRoot, collBase.SyncRoot);
304304
}
305305

306306
[Fact]

src/System.Collections.NonGeneric/tests/QueueTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ public void SyncRoot()
850850
{
851851
queueMother.Enqueue(i);
852852
}
853-
Assert.Equal(queueMother.SyncRoot.GetType(), typeof(object));
853+
Assert.Equal(queueMother.SyncRoot.GetType(), typeof(Queue));
854854

855855
var queueSon = Queue.Synchronized(queueMother);
856856
_queueGrandDaughter = Queue.Synchronized(queueSon);

src/System.Collections.NonGeneric/tests/ReadOnlyCollectionBaseTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private static MyReadOnlyCollectionBase CreateCollection()
2323
public static void SyncRoot()
2424
{
2525
MyReadOnlyCollectionBase collection = CreateCollection();
26-
Assert.False(collection.SyncRoot is ArrayList);
26+
Assert.True(collection.SyncRoot is ArrayList);
2727
Assert.Same(collection.SyncRoot, collection.SyncRoot);
2828
}
2929

src/System.Collections.NonGeneric/tests/StackTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ public void GetSyncRootBasic()
563563
stackMother.Push(i);
564564
}
565565

566-
Assert.Equal(typeof(object), stackMother.SyncRoot.GetType());
566+
Assert.Equal(typeof(Stack), stackMother.SyncRoot.GetType());
567567

568568
Stack stackSon = Stack.Synchronized(stackMother);
569569
_stackGrandDaughter = Stack.Synchronized(stackSon);

src/System.Collections.Specialized/tests/HybridDictionary/HybridDictionaryTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ public abstract class HybridDictionaryTestBase : IDictionary_NonGeneric_Tests
2323
protected override Type ICollection_NonGeneric_CopyTo_ArrayOfIncorrectReferenceType_ThrowType => typeof(InvalidCastException);
2424
protected override Type ICollection_NonGeneric_CopyTo_ArrayOfIncorrectValueType_ThrowType => typeof(InvalidCastException);
2525

26-
protected override Type ICollection_NonGeneric_SyncRootType => typeof(HybridDictionary);
27-
2826
protected override object CreateTKey(int seed)
2927
{
3028
int stringLength = seed % 10 + 5;

src/System.Collections.Specialized/tests/NameObjectCollectionBase/NameObjectCollectionBase.SyncRootTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void SyncRoot()
1717
Assert.False(nameObjectCollection1.IsSynchronized);
1818

1919
Assert.Same(nameObjectCollection1.SyncRoot, nameObjectCollection1.SyncRoot);
20-
Assert.NotEqual(nameObjectCollection1.SyncRoot, nameObjectCollection2.SyncRoot);
20+
Assert.NotSame(nameObjectCollection1.SyncRoot, nameObjectCollection2.SyncRoot);
2121
}
2222
}
2323
}

src/System.Collections.Specialized/tests/OrderedDictionary/OrderedDictionaryTests.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void KeysPropertyContainsAllKeys()
144144
ICollection keys = d.Keys;
145145

146146
Assert.False(keys.IsSynchronized);
147-
Assert.NotEqual(d, keys.SyncRoot);
147+
Assert.NotSame(d, keys.SyncRoot);
148148
Assert.Equal(d.Count, keys.Count);
149149

150150
foreach (var key in d.Keys)
@@ -186,16 +186,12 @@ public void SyncRootTests()
186186
object sync1 = orderedDictionary1.SyncRoot;
187187
object sync2 = orderedDictionary2.SyncRoot;
188188

189-
// Sync root does not refer to the dictionary
190-
Assert.NotEqual(sync1, orderedDictionary1);
191-
Assert.NotEqual(sync2, orderedDictionary2);
192-
193189
// Sync root objects for the same dictionaries are equivalent
194-
Assert.Equal(orderedDictionary1.SyncRoot, orderedDictionary1.SyncRoot);
195-
Assert.Equal(orderedDictionary2.SyncRoot, orderedDictionary2.SyncRoot);
190+
Assert.Same(orderedDictionary1.SyncRoot, orderedDictionary1.SyncRoot);
191+
Assert.Same(orderedDictionary2.SyncRoot, orderedDictionary2.SyncRoot);
196192

197193
// Sync root objects for different dictionaries are not equivalent
198-
Assert.NotEqual(sync1, sync2);
194+
Assert.NotSame(sync1, sync2);
199195
}
200196

201197
// bool System.Collections.IDictionary.IsFixedSize { get; }
@@ -274,7 +270,7 @@ public void ValuesPropertyContainsAllValues()
274270
ICollection values = d.Values;
275271

276272
Assert.False(values.IsSynchronized);
277-
Assert.NotEqual(d, values.SyncRoot);
273+
Assert.NotSame(d, values.SyncRoot);
278274
Assert.Equal(d.Count, values.Count);
279275

280276
foreach (var val in values)

src/System.Collections.Specialized/tests/StringCollectionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public static void SyncRootTest(StringCollection collection, string[] data)
639639
{
640640
object syncRoot = collection.SyncRoot;
641641
Assert.NotNull(syncRoot);
642-
Assert.IsType<object>(syncRoot);
642+
Assert.IsType<ArrayList>(syncRoot);
643643

644644
Assert.Same(syncRoot, collection.SyncRoot);
645645
Assert.NotSame(syncRoot, new StringCollection().SyncRoot);

0 commit comments

Comments
 (0)