コード例 #1
0
            public void DoesNotResetSnapshotWhenItemWithGivenKeyWasNotRemoved()
            {
                var target = new TestableSnapshottingDictionary <object, object>();
                IDictionary <object, object> oldSnapshot = target.GetSnapshot();

                target.Remove(new object());

                Assert.Same(oldSnapshot, target.Snapshot);
            }
コード例 #2
0
            public void ReturnsTrueIfItemWasRemovedSuccessfully()
            {
                var key    = new object();
                var target = new TestableSnapshottingDictionary <object, object> {
                    { key, null }
                };

                Assert.True(target.Remove(key));
            }
コード例 #3
0
            public void ResetsSnapshotSoThatItIsRecreatedAtNextRead()
            {
                var target = new TestableSnapshottingDictionary <object, object>();

                target.GetSnapshot();

                target.Add(new object(), new object());

                Assert.Null(target.Snapshot);
            }
コード例 #4
0
            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]);
            }
コード例 #5
0
            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));
            }
コード例 #6
0
            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));
            }
コード例 #7
0
            public void RemovesItemWithGivenKeyFromDictionary()
            {
                var key    = new object();
                var target = new TestableSnapshottingDictionary <object, object> {
                    { key, null }
                };

                target.Remove(key);

                Assert.Equal(0, target.Collection.Count);
            }
コード例 #8
0
            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]);
            }
コード例 #9
0
            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));
            }
コード例 #10
0
            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]);
            }
コード例 #11
0
            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);
            }
コード例 #12
0
            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]);
            }
コード例 #13
0
            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));
            }
コード例 #14
0
            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);
            }
コード例 #15
0
            public void CreatesNewDictionary()
            {
                var target = new TestableSnapshottingDictionary <object, object>();

                Assert.NotNull(target.Collection);
            }