How to write unit test for an insecure thread collection

I am writing a doubly linked list using the TDD approach. This type of collection is not thread safe. To implement the ICollection interface, my list class must have several public properties (including IsSynchronized and SyncRoot, which are used to provide a thread-safe way to use the collection). The code for these two properties is pretty simple:

public bool IsSynchronized { get { return false; } }

private readonly object _syncRoot = new object();
public object SyncRoot { get { return _syncRoot; } }

The question is how to write the correct unit test for it. This test should verify proper use and misuse.

+3
source share
2 answers

my list class should have several public properties (including IsSynchronized and SyncRoot

. .NET 1 . , . , . .NET 2.0. ICollection, ICollection<T>. , , IEnumerable, , , , . , .

, ICollection < > . , , O (n) . , O (1). .NET LinkedList < > , , .

+5

, . SyncRoot , -, , /, - . ( , , .)

, , , ( IsSynchronized return false); , .

, , ICollection SyncRoot ( null). - .

unit test , SyncRoot null.

0

Source: https://habr.com/ru/post/1787324/


All Articles