CanInstantiateWithInvalidAdapterParam()
    {
        $adapter = new ZendDb('string monkey');
    }

    /**
     * Check getDataSource returns an \Zend\Db\Adapter\Adapter
     * object when it has been correctly instantiated.
     */
    public function testGetDataSource()
    {
        $dataSource = $this->adapter->getDataSource();
        $this->assertInstanceOf('\Zend\Db\Adapter\Adapter', $dataSource);
    }

    /**
     * Check setDataSource sets correctly.
     */
    public function testSetDataSourceWithValidDataSourceParam()
    {
        $dataSource = $this->adapter->getDataSource();
        $this->adapter->setDataSource($dataSource);
    }

    /**
     * Check setDataSource throws an \ErrorException
     * when supplied with a string of garbage.
     *
     * @expectedException \ErrorException
     */
    public function testSetDataSourceWithInvalidDataSourceParam()
    {
        $this->adapter->setDataSource('string monkey');
    }

    /**
     * Check supplying valid param to getMetaData returns instances
     * of \ZucchiModel\Metadata\Adapter\ZendDb.
     */
    public function testGetMetaDataWithValidTableParam()
    {
        $metadata = $this->adapter->getMetaData(array('test_zucchimodel_user'));
        $this->assertInstanceOf('\ZucchiModel\Metadata\Adapter\ZendDb', $metadata);
    }

    /**
     * Check getMetaData throws an \Exception when supplied with
     * an unknown target.
     *
     * @expectedException \Exception
     */
    public function testGetMetaDataWithUnknownTableParam()
    {
        $metadata = $this->adapter->getMetaData(array('doesnot exist'));
    }

    /**
     * Check getMetaData throws an \Exception
     * when supplied with a string of garbage.
     *
     * @expectedException \ErrorException
     */
    public function testGetMetaDataWithInvalidArrayParam()
    {
        $metadata = $this->adapter->getMetaData('string monkey');
    }

    /**
     * Check getMetaData throws an \InvalidArgumentException
     * when supplied with an empty array of targets.
     *
     * @expectedException \InvalidArgumentException
     */
    public function testGetMetaDataWithEmptyArrayParam()
    {
        $metadata = $this->adapter->getMetaData(array());
    }

    /**
     * Check buildQuery returns an instance of \Zend\Db\Sql\Select
     * when supplied with correct params.
     */
    public function testBuildQueryWithValidCriteriaAndMetaDataContainerParams()
    {
        $metaDataContainer = $this->modelManager->getMetaData(__NAMESPACE__. '\TestAsset\Customer');
        $this->assertInstanceOf('\ZucchiModel\MetaData\MetaDataContainer', $metaDataContainer);

        $criteria = new Criteria(array('model' => __NAMESPACE__. '\TestAsset\Customer'));
        $select = $this->adapter->buildQuery($criteria, $metaDataContainer);
        $this->assertInstanceOf('\Zend\Db\Sql\Select', $select);
    }

    /**
     * Check buildQuery returns an instance of \Zend\Db\Sql\Select
     * when supplied with correct params and a valid \Zend\Db\Sql\Where.
     */
    public function testBuildQueryWithValidWhere()
    {
        $metaDataContainer = $this->modelManager->getMetaData(__NAMESPACE__. '\TestAsset\Customer');
        $this->assertInstanceOf('\ZucchiModel\MetaData\MetaDataContainer', $metaDataContainer);

        $where = new Where();
        $where->like('email', '%rick%');
        $criteria = new Criteria(
            array(
               'model' => __NAMESPACE__. '\TestAsset\Customer',
                'where' => $where
            )
        );
        $select = $this->adapter->buildQuery($criteria, $metaDataContainer);
        $this->assertInstanceOf('\Zend\Db\Sql\Select', $select);
    }

    /**
     * Check buildQuery returns an instance of \Zend\Db\Sql\Select
     * when supplied with correct params and a valid \Zend\Db\Sql\Where
     * with a valid offset and limit.
     */
    public function testBuildQueryWithValidOffsetAndLimit()
    {
        $metaDataContainer = $this->modelManager->getMetaData(__NAMESPACE__. '\TestAsset\Customer');
        $this->assertInstanceOf('\ZucchiModel\MetaData\MetaDataContainer', $metaDataContainer);

        $criteria = new Criteria(
            array(
               'model' => __NAMESPACE__. '\TestAsset\Customer',
                'offset' => 1,
                'limit' => 1
            )
        );
        $select = $this->adapter->buildQuery($criteria, $metaDataContainer);
        $this->assertInstanceOf('\Zend\Db\Sql\Select', $select);
    }

    /**
     * Check buildQuery throws \ErrorException when supplied with
     * string params of garbage.
     *
     * @expectedException \ErrorException
     */
    public function testBuildQueryWithInvalidCriteriaAndMetaDataContainerParams()
    {
        $metaDataContainer = $this->modelManager->getMetaData(__NAMESPACE__. '\TestAsset\Customer');
        $this->assertInstanceOf('\ZucchiModel\MetaData\MetaDataContainer', $metaDataContainer);

        $select = $this->adapter->buildQuery('string monkey','string monkey');
    }

    /**
     * Check buildCountQuery returns an instance of \Zend\Db\Sql\Select
     * when supplied with correct params and a valid \Zend\Db\Sql\Where
     * with a valid offset and limit.
     */
    public function testBuildCountQueryWithValidCriteriaAndMetaDataContainerParams()
    {
        $metaDataContainer = $this->modelManager->getMetaData(__NAMESPACE__. '\TestAsset\Customer');
        $this->assertInstanceOf('\ZucchiModel\MetaData\MetaDataContainer', $metaDataContainer);

        $criteria = new Criteria(array('model' => __NAMESPACE__. '\TestAsset\Customer'));
        $select = $this->adapter->buildCountQuery($criteria, $metaDataContainer);
        $this->assertInstanceOf('\Zend\Db\Sql\Select', $select);
    }

    /**
     * Check buildCountQuery throws \ErrorException when supplied with
     * string params of garbage.
     *
     * @expectedException \ErrorException
     */
    public function testBuildCountQueryWithInvalidCriteriaAndMetaDataContainerParams()
    {
        $metaDataContainer = $this->modelManager->getMetaData(__NAMESPACE__. '\TestAsset\Customer');
        $this->assertInstanceOf('\ZucchiModel\MetaData\MetaDataContainer', $metaDataContainer);

        $select = $this->adapter->buildCountQuery('string monkey','string monkey');
    }

    /**
     * Check execute returns instance of \Zend\Db\Adapter\Driver\ResultInterface
     * when supplied with valid \Zend\Db\Sql\Select on \ZucchiModelTest\Adapter\TestAsset\Customer.
     */
    public function testExecuteWithValidCustomerSelect()
    {
        $metaDataContainer = $this->modelManager->getMetaData(__NAMESPACE__. '\TestAsset\Customer');
        $this->assertInstanceOf('\ZucchiModel\MetaData\MetaDataContainer', $metaDataContainer);

        $criteria = new Criteria(array('model' => __NAMESPACE__. '\TestAsset\Customer'));
        $select = $this->adapter->buildQuery($criteria, $metaDataContainer);
        $this->assertInstanceOf('\Zend\Db\Sql\Select', $select);

        $results = $this->adapter->execute($select);
        $this->assertInstanceOf('\Zend\Db\Adapter\Driver\ResultInterface', $results);
    }

    /**
     * Check execute throws \ErrorException when supplied with
     * string param of garbage.
     *
     * @expectedException \ErrorException
     */
    public function testExecuteWithInvalidQueryParam()
    {
        $adapter = new ZendDb($this->zendAdapter);
        $results = $adapter->execute('string monkey');
    }

    /**
     * Check execute throws \Zend\Db\Adapter\Exception\InvalidQueryException
     * when supplied with unknown column in \Zend\Db\