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); }
public void RegisterInvocation_DelegateNullReference_ThrowsException() { var target = new UndoManager(); Assert.Throws <ArgumentNullException>(() => target.RegisterInvokation((Action <string>)null, string.Empty)); }
public void RegisterInvocation_InvokationNullReference_ThrowsException() { var target = new UndoManager(); Assert.Throws <ArgumentNullException>(() => target.RegisterInvokation((IInvokable)null)); }
public void Redo_NoRedoInvocationsRegistered_ThrowsException() { var target = new UndoManager(); Assert.Throws <InvalidOperationException>(() => target.Redo()); }