public void ShouldInitaliseNotCommandTimeoutWhenNotSet()
        {
            //Given
            var dataQuery = new DataQuery();

            //When
            _databaseCommandFactory.CreateCommandFor(dataQuery);

            //Then
            _dbCommand.VerifySet(x => x.CommandTimeout = It.IsAny<int>(), Times.Never());
        }
        public void ShouldInitaliseCommandTimeout()
        {
            //Given
            var dataQuery = new DataQuery().WithCommandTimeout(TimeSpan.FromHours(1));

            //When
            _databaseCommandFactory.CreateCommandFor(dataQuery);

            //Then
            _dbCommand.VerifySet(x => x.CommandTimeout = 3600);
        }
        public void ShouldInitaliseCommandProperties()
        {
            //Given
            var dataQuery = new DataQuery().WithStoredProc("Get_Shizzle");

            //When
            _databaseCommandFactory.CreateCommandFor(dataQuery);

            //Then
            _dbCommand.VerifySet(x => x.CommandText = "Get_Shizzle");
            _dbCommand.VerifySet(x => x.CommandType = CommandType.StoredProcedure);
        }
Exemplo n.º 4
0
        public void ShouldGetContactUsingRunQueryMethodWithDataQuery()
        {
            //Given
            var dataQuery = new DataQuery() {CommandText = "select * from Contact where FirstName = @FirstName",}.WithParam("@FirstName", "David");

            //When - This could be a generic repository
            var contact = UnitOfWork.Repository<ContactRepository>().RunQuery(dataQuery);

            //Then
            Assert.That(contact.FirstName, Is.EqualTo("David"));
            Assert.That(contact.Surname, Is.EqualTo("Miranda"));
            Assert.That(contact.Telephone, Is.EqualTo("999"));
        }
Exemplo n.º 5
0
        public void BeforeEachTest()
        {
            _sqlDataQuery = new DataQuery();
            _command = new Mock<IDbCommand>();
            _databaseCommandFactory = new Mock<IDatabaseCommandFactory>();
            _transactionWrapperMock = new Mock<ITransactionWrapper>();
            _databaseReaderFactory = new Mock<IDatabaseReaderFactory>();
            _connectionHandler = new Mock<IConnectionHandler>();

            _databaseSession = new DatabaseSession(_databaseCommandFactory.Object, _transactionWrapperMock.Object, _databaseReaderFactory.Object, _connectionHandler.Object);

            _connectionHandler.Setup(x => x.GetHandler(It.IsAny<IDbCommand>(), It.IsAny<ITransactionWrapper>())).Returns(_connectionHandler.Object);
            _databaseCommandFactory.Setup(x => x.CreateCommandFor(It.IsAny<DataQuery>())).Returns(_command.Object);
        }
        public void ShouldInitialiseCommandDataParameters()
        {
            //Given
            var dataQuery = new DataQuery()
                .WithParam("Title", "Mr")
                .WithParam("FirstName", "David")
                .WithParam("Surname", "Miranda");

            //When
            _databaseCommandFactory.CreateCommandFor(dataQuery);

            //Then
            _dataParameter.VerifySet(x => x.ParameterName = "Title", Times.Once());
            _dataParameter.VerifySet(x => x.Value =  "Mr", Times.Once());
            _dataParameter.VerifySet(x => x.ParameterName = "FirstName", Times.Once());
            _dataParameter.VerifySet(x => x.Value =  "David", Times.Once());
            _dataParameter.VerifySet(x => x.ParameterName = "Surname", Times.Once());
            _dataParameter.VerifySet(x => x.Value = "Miranda", Times.Once());
        }
        public void ShouldNotSetDbTypeForNullValue()
        {
            var dataQuery = new DataQuery()
                .WithParam("Title", null);

            _databaseCommandFactory.CreateCommandFor(dataQuery);

            _dataParameter.VerifySet(x => x.DbType = It.IsAny<DbType>(), Times.Never());
        }
        public void ShouldNotSetDbTypeForDbNullValue()
        {
            var dataQuery = new DataQuery()
                .WithCommandType(CommandType.StoredProcedure)
                .WithParam("Title", DBNull.Value);

            _databaseCommandFactory.CreateCommandFor(dataQuery);

            _dataParameter.VerifySet(x => x.DbType = It.IsAny<DbType>(), Times.Never());
        }
        public void ShouldMapDbTypeForValue()
        {
            var dataQuery = new DataQuery()
                .WithCommandType(CommandType.StoredProcedure)
                .WithParam("Title", "Dr");

            _databaseCommandFactory.CreateCommandFor(dataQuery);

            _dataParameter.VerifySet(x => x.DbType = DbType.String, Times.Once());
        }