public void DoesNotResetSnapshotWhenItemWithGivenKeyWasNotRemoved() { var target = new TestableSnapshottingDictionary <object, object>(); IDictionary <object, object> oldSnapshot = target.GetSnapshot(); target.Remove(new object()); Assert.Same(oldSnapshot, target.Snapshot); }
public void ReturnsTrueIfItemWasRemovedSuccessfully() { var key = new object(); var target = new TestableSnapshottingDictionary <object, object> { { key, null } }; Assert.True(target.Remove(key)); }
public void ResetsSnapshotSoThatItIsRecreatedAtNextRead() { var target = new TestableSnapshottingDictionary <object, object>(); target.GetSnapshot(); target.Add(new object(), new object()); Assert.Null(target.Snapshot); }
public void AddsItemWithGivenKeyInDictionary() { var target = new TestableSnapshottingDictionary <object, object>(); var key = new object(); var value = new object(); target.Add(key, value); Assert.Same(value, target.Collection[key]); }
public void ReturnsValuesOfSnapshot() { var target = new TestableSnapshottingDictionary <object, object>(); var value = new object(); target.Snapshot = new Dictionary <object, object> { { new object(), value } }; Assert.True(target.Values.Contains(value)); }
public void ReturnsKeysOfSnapshot() { var target = new TestableSnapshottingDictionary <object, object>(); var key = new object(); target.Snapshot = new Dictionary <object, object> { { key, null } }; Assert.True(target.Keys.Contains(key)); }
public void RemovesItemWithGivenKeyFromDictionary() { var key = new object(); var target = new TestableSnapshottingDictionary <object, object> { { key, null } }; target.Remove(key); Assert.Equal(0, target.Collection.Count); }
public void GetterReturnsValueWithGivenKeyInSnapshot() { var target = new TestableSnapshottingDictionary <object, object>(); var key = new object(); var value = new object(); target.Snapshot = new Dictionary <object, object> { { key, value } }; Assert.Same(value, target[key]); }
public void LocksCollectionForThreadSafety() { Task anotherThread; var target = new TestableSnapshottingDictionary <object, object>(); lock (target.Collection) { anotherThread = TaskEx.Run(() => target.Add(new object(), new object())); Assert.False(anotherThread.Wait(20)); } Assert.True(anotherThread.Wait(20)); }
public void CreatesClonesGivenDictionary() { var target = new TestableSnapshottingDictionary <object, object>(); var key = new object(); var value = new object(); var input = new Dictionary <object, object> { { key, value } }; IDictionary <object, object> output = target.CreateSnapshot(input); Assert.Same(value, output[key]); }
public void SetterResetsSnapshotSoThatItIsRecreatedAtNextRead() { var key = new object(); var target = new TestableSnapshottingDictionary <object, object> { { key, null } }; target.GetSnapshot(); target[key] = new object(); Assert.Null(target.Snapshot); }
public void SetterReplacesItemWithGivenKeyInDictionary() { var key = new object(); var target = new TestableSnapshottingDictionary <object, object> { { key, null } }; var value = new object(); target[key] = value; Assert.Same(value, target.Collection[key]); }
public void SetterLocksCollectionForThreadSafety() { Task anotherThread; var key = new object(); var target = new TestableSnapshottingDictionary <object, object> { { key, null } }; lock (target.Collection) { anotherThread = TaskEx.Run(() => target[key] = new object()); Assert.False(anotherThread.Wait(20)); } Assert.True(anotherThread.Wait(20)); }
public void ReturnsValueWithGivenKeyInSnapshot() { var target = new TestableSnapshottingDictionary <object, object>(); var key = new object(); var value = new object(); target.Snapshot = new Dictionary <object, object> { { key, value } }; object returnedValue = null; bool result = target.TryGetValue(key, out returnedValue); Assert.True(result); Assert.Same(value, returnedValue); }
public void CreatesNewDictionary() { var target = new TestableSnapshottingDictionary <object, object>(); Assert.NotNull(target.Collection); }