public void ShoulDisposeInnerCommand() { MockDbCommand dbCommandMock = new MockDbCommand(); Mock <ISyncPolicy> retryPolicyMock = new Mock <ISyncPolicy>(); var commandWrapper = new ReliableDbCommandWrapper(dbCommandMock, retryPolicyMock.Object); commandWrapper.Dispose(); Assert.Equal(1, dbCommandMock.DisposeCount); }
public void ShouldReturnNullTransactionWhenInnerCommandHasNoTransaction() { MockDbCommand dbCommandMock = new MockDbCommand(); Mock <ISyncPolicy> retryPolicyMock = new Mock <ISyncPolicy>(); var commandWrapper = new ReliableDbCommandWrapper(dbCommandMock, retryPolicyMock.Object); dbCommandMock.Transaction = null; Assert.Null(commandWrapper.Transaction); }
public void ShouldSetTransactionToInnerCommand() { MockDbCommand dbCommandMock = new MockDbCommand(); Mock <ISyncPolicy> retryPolicyMock = new Mock <ISyncPolicy>(); var commandWrapper = new ReliableDbCommandWrapper(dbCommandMock, retryPolicyMock.Object); MockDbTransaction mockDbTransaction = new MockDbTransaction(); commandWrapper.Transaction = mockDbTransaction; Assert.Equal(mockDbTransaction, dbCommandMock.Transaction); }
public void ShouldSetDbConnectionToInnerCommand() { Mock <DbConnection> testDbConnection = new Mock <DbConnection>(); MockDbCommand dbCommandMock = new MockDbCommand(); Mock <ISyncPolicy> retryPolicyMock = new Mock <ISyncPolicy>(); var commandWrapper = new ReliableDbCommandWrapper(dbCommandMock, retryPolicyMock.Object); commandWrapper.Connection = testDbConnection.Object; Assert.Equal(testDbConnection.Object, dbCommandMock.Connection); }
public void ShouldReadTransactionFromInnerCommandAndWrap() { MockDbCommand dbCommandMock = new MockDbCommand(); Mock <ISyncPolicy> retryPolicyMock = new Mock <ISyncPolicy>(); var commandWrapper = new ReliableDbCommandWrapper(dbCommandMock, retryPolicyMock.Object); MockDbTransaction mockDbTransaction = new MockDbTransaction(); dbCommandMock.Transaction = mockDbTransaction; Assert.True(commandWrapper.Transaction is ReliableDbTransactionWrapper); Assert.Equal(mockDbTransaction, ((ReliableDbTransactionWrapper)commandWrapper.Transaction).InnerTransaction); }
public void ShouldCreateNewParametersInInnerCommand() { MockDbCommand dbCommandMock = new MockDbCommand(); Mock <ISyncPolicy> retryPolicyMock = new Mock <ISyncPolicy>(); var commandWrapper = new ReliableDbCommandWrapper(dbCommandMock, retryPolicyMock.Object); Mock <DbParameter> mockDbParameter = new Mock <DbParameter>(); dbCommandMock.NextParameterToReturn = mockDbParameter.Object; var obtainedParameter = commandWrapper.CreateParameter(); Assert.Equal(mockDbParameter.Object, obtainedParameter); }
public void ShouldReadDbParameterCollectionFromInnerCommand() { MockDbCommand dbCommandMock = new MockDbCommand(); Mock <ISyncPolicy> retryPolicyMock = new Mock <ISyncPolicy>(); var commandWrapper = new ReliableDbCommandWrapper(dbCommandMock, retryPolicyMock.Object); Mock <DbParameterCollection> mockParameterCollection = new Mock <DbParameterCollection>(); mockParameterCollection.Setup(x => x.ToString()).Returns("TestParameterCollection"); dbCommandMock.NextParameterCollectionToReturn = mockParameterCollection.Object; Assert.Equal("TestParameterCollection", commandWrapper.Parameters.ToString()); }
public void ShouldExecuteDbDataReaderWithRetriesInInnerCommand() { MockDbCommand dbCommandMock = new MockDbCommand(); Mock <ISyncPolicy> retryPolicyMock = new Mock <ISyncPolicy>(); var commandWrapper = new ReliableDbCommandWrapper(dbCommandMock, retryPolicyMock.Object); Mock <DbDataReader> mockDbDataReader = new Mock <DbDataReader>(); mockDbDataReader.Setup(x => x.GetName(1)).Returns("TestColumnName"); retryPolicyMock.Setup(x => x.Execute <DbDataReader>(It.IsAny <Func <DbDataReader> >())) .Returns(mockDbDataReader.Object) .Callback <Func <DbDataReader> >(a => a.Invoke()); var obtainedReader = commandWrapper.ExecuteReader(); retryPolicyMock.Verify(x => x.Execute <DbDataReader>(It.IsAny <Func <DbDataReader> >())); Assert.Equal("TestColumnName", obtainedReader.GetName(1)); Assert.Equal(1, dbCommandMock.ExecuteDbDataReaderCount); }