Ejemplo n.º 1
0
        public void TestTrackableCollection_TryPop(bool track)
        {
            var             acc  = new Accumulator("test");
            IStack <Simple> coll = new TrackableCollection <Simple>(acc, track);

            Assert.AreEqual(0, coll.Count());
            var a = new Simple("a");
            var b = new Simple("b");

            coll.Push(a);
            coll.Push(b);
            Assert.IsTrue(coll.TryPop(out var b1));
            Assert.AreEqual(b, b1);
            Assert.AreEqual(1, coll.Count());
            Assert.IsTrue(coll.TryPop(out var a1));
            Assert.AreEqual(a, a1);
            Assert.AreEqual(0, coll.Count());
            Assert.IsFalse(coll.TryPop(out var c1));

            if (track)
            {
                Assert.AreEqual(4, acc.Records.Count);
            }
            else
            {
                Assert.AreEqual(0, acc.Records.Count);
            }
        }
        public void Add(Accumulator scope, ScopeState state)
        {
            switch (state)
            {
            case ScopeState.Do:
                _redoables.Clear();
                _undoables.Push(scope);
                break;

            case ScopeState.Undo:
                _undoables.Push(scope);
                break;

            case ScopeState.Redo:
                _redoables.Push(scope);
                break;
            }
        }
Ejemplo n.º 3
0
        public void TestTrackableCollection_Push(bool track)
        {
            var             acc  = new Accumulator("test");
            IStack <Simple> coll = new TrackableCollection <Simple>(acc, track);

            Assert.AreEqual(0, coll.Count());
            coll.Push(new Simple("a"));
            Assert.AreEqual(1, coll.Count());
            coll.Push(new Simple("b"));
            Assert.AreEqual(2, coll.Count());

            if (track)
            {
                Assert.AreEqual(2, acc.Records.Count);
            }
            else
            {
                Assert.AreEqual(0, acc.Records.Count);
            }
        }