Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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());
        }
Exemple #8
0
        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);
        }