Пример #1
0
            public void ReusesPreviouslyCreatedSnapshotToImprovePerformance()
            {
                var target = new TestableSnapshottingCollection <object>(new List <object>());
                var previouslyCreatedSnapshot = new List <object>();

                target.Snapshot = previouslyCreatedSnapshot;

                var returnedSnapshot = target.GetSnapshot();

                Assert.Same(previouslyCreatedSnapshot, returnedSnapshot);
            }
            public void ResetsSnapshotSoThatItsRecreatedAtNextRead()
            {
                var target = new TestableSnapshottingCollection <object>(new List <object> {
                    null
                });

                target.GetSnapshot();

                target.Remove(null);

                Assert.Null(target.Snapshot);
            }
            public void LocksCollectionWhileCreatingSnapshotForThreadSafety()
            {
                bool isCollectionLocked = false;
                var  target             = new TestableSnapshottingCollection <object>(new List <object>());

                target.OnCreateSnapshot = c =>
                {
                    isCollectionLocked = Monitor.IsEntered(c);
                    return(null);
                };

                var dummy = target.GetSnapshot();

                Assert.True(isCollectionLocked);
            }
            public void InvokesCreateSnapshotMethodToLetConcreteChildrenDoItEfficiently()
            {
                IList <object> actualCollection   = null;
                var            expectedCollection = new List <object>();
                var            target             = new TestableSnapshottingCollection <object>(new List <object>());

                target.OnCreateSnapshot = c =>
                {
                    actualCollection = expectedCollection;
                    return(null);
                };

                var dummy = target.GetSnapshot();

                Assert.Same(expectedCollection, actualCollection);
            }