public void ShouldNotOpenInnerConnectionWhenAlreadyOpen() { Mock <DbConnection> dbConnectionMock = new Mock <DbConnection>(); Mock <ISyncPolicy> retryPolicyMock = new Mock <ISyncPolicy>(); var connectionWrapper = new ReliableDbConnectionWrapper(dbConnectionMock.Object, retryPolicyMock.Object); dbConnectionMock.Setup(x => x.State).Returns(ConnectionState.Open); connectionWrapper.Open(); dbConnectionMock.Verify(x => x.Open(), Times.Never); }
public void ShouldOpenInnerConnectionWithRetriesWhenInStatusOtherThanOpen() { Mock <DbConnection> dbConnectionMock = new Mock <DbConnection>(); Mock <ISyncPolicy> retryPolicyMock = new Mock <ISyncPolicy>(); var connectionWrapper = new ReliableDbConnectionWrapper(dbConnectionMock.Object, retryPolicyMock.Object); dbConnectionMock.Setup(x => x.State).Returns(ConnectionState.Closed); retryPolicyMock.Setup(x => x.Execute(It.IsAny <Action>())).Callback <Action>(a => a.Invoke()); connectionWrapper.Open(); retryPolicyMock.Verify(x => x.Execute(It.IsAny <Action>())); dbConnectionMock.Verify(x => x.Open()); }