示例#1
0
        public void Redo_RedoOperationAvailable_InvokesRedoOperation()
        {
            var target = new UndoManager();

            var invokableMock = new Mock <ITarget>(MockBehavior.Strict);

            invokableMock.Setup(i => i.UndoOperation())
            .Callback(() => target.RegisterInvokation(invokableMock.Object, i => i.RedoOperation()));
            invokableMock.Setup(i => i.RedoOperation());

            target.RegisterInvokation(invokableMock.Object, i => i.UndoOperation());

            target.Undo();
            target.Redo();

            invokableMock.Verify(i => i.UndoOperation(), Times.Once());
            invokableMock.Verify(i => i.RedoOperation(), Times.Once());
            Assert.False(target.CanUndo);
            Assert.False(target.CanRedo);
        }
        public void RegisterInvocation_WithTransaction_RegistersInvocationWithPublicTransaction()
        {
            TransactionFactoryStub factory = new TransactionFactoryStub();
            UndoManager            target  = new UndoManager(factory);

            factory.Transaction = new TransactionStub(target);

            Mock <IInvokable> invokableMock = new Mock <IInvokable>(MockBehavior.Strict);

            using (ITransaction transaction = target.CreateTransaction())
            {
                target.RegisterInvokation(invokableMock.Object);
            }

            Assert.True(factory.TransactionCreated);
            Assert.True(((TransactionStub)factory.Transaction).InvokationRegistered);
            Assert.True(((TransactionStub)factory.Transaction).Commited);

            Assert.True(target.CanUndo);
            Assert.False(target.CanRedo);
        }
示例#3
0
        public void RegisterInvocation_DelegateNullReference_ThrowsException()
        {
            var target = new UndoManager();

            Assert.Throws <ArgumentNullException>(() => target.RegisterInvokation((Action <string>)null, string.Empty));
        }
示例#4
0
        public void RegisterInvocation_InvokationNullReference_ThrowsException()
        {
            var target = new UndoManager();

            Assert.Throws <ArgumentNullException>(() => target.RegisterInvokation((IInvokable)null));
        }
示例#5
0
        public void Redo_NoRedoInvocationsRegistered_ThrowsException()
        {
            var target = new UndoManager();

            Assert.Throws <InvalidOperationException>(() => target.Redo());
        }