public void CopyToTest() { var dict = new ShieldedDict <int, object>( Enumerable.Range(1, 1000).Select(i => new KeyValuePair <int, object>(i, new object())).ToArray()); Assert.AreEqual(1000, dict.Count); var array = new KeyValuePair <int, object> [1100]; // this works out of transaction (and consequently, so do ToArray and ToList), by opening // a transaction itself. that could not be done when you do a foreach. ((ICollection <KeyValuePair <int, object> >)dict).CopyTo(array, 100); Assert.IsTrue(array.Skip(100).OrderBy(kvp => kvp.Key).SequenceEqual(dict.OrderBy(kvp => kvp.Key))); }
public void EnumerationTest() { var ordinaryDict = new Dictionary <int, object>() { { 1, new object() }, { 101, new object() }, { 666999, new object() } }; var dict = new ShieldedDict <int, object>(ordinaryDict); var addedObject = new object(); // in preparation for the same changes done to dict inside transaction ordinaryDict.Add(2, addedObject); ordinaryDict.Remove(666999); Shield.InTransaction(() => { // as an IShielded implementor, the Dict is more complex and needs to be more carefully // tested for how well he manages thread-local data. So, we add some changes here. dict.Add(2, addedObject); dict.Remove(666999); Assert.IsTrue(dict.OrderBy(kvp => kvp.Key).SequenceEqual(ordinaryDict.OrderBy(kvp => kvp.Key))); }); }