public void MustUseSameInstanceForAllOperations() { var first = true; var operation = operationMock.Object; IOperation initialize() { if (first) { first = false; return(operation); } return(new Mock <IOperation>().Object); }; var sut = new LazyInitializationOperation(initialize); sut.Perform(); sut.Revert(); operationMock.Verify(o => o.Perform(), Times.Once); operationMock.Verify(o => o.Revert(), Times.Once); }
public void MustNotInstantiateOperationOnRevert() { IOperation initialize() { return(operationMock.Object); }; var sut = new LazyInitializationOperation(initialize); sut.Revert(); }
public void MustReturnCorrectOperationResult() { IOperation initialize() { return(operationMock.Object); }; operationMock.Setup(o => o.Perform()).Returns(OperationResult.Success); operationMock.Setup(o => o.Revert()).Returns(OperationResult.Failed); var sut = new LazyInitializationOperation(initialize); var perform = sut.Perform(); var revert = sut.Revert(); Assert.AreEqual(OperationResult.Success, perform); Assert.AreEqual(OperationResult.Failed, revert); }