コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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());
        }
コード例 #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);
        }