 h = require('../test-helper')
+async = h.async
+
 fs = require('fs')
 
 env = "development"
 database = null
+
+tmpTable = """
+DECLARE @names TABLE(
+    FirstName VARCHAR(50),
+    LastName VARCHAR (50)
+)
+
+INSERT INTO @names VALUES ('Vincent','Vega')
+INSERT INTO @names VALUES  ('Jules','Winnfield')
+INSERT INTO @names VALUES  ('Mia','Wallace')
+INSERT INTO @names VALUES  ('Marsellus','Wallace')
+
+"""
 
 describe('Database', () ->
     it('should have a configuration object', () ->

        )
    )

    it('should get query rows', (done) ->
        stmt = "SELECT 1 AS test"
        database.allRows(stmt, (err, data) ->

            done()
        )
    )

    it('tryOneRow should behave as oneRow with a unitary resultset', (done) ->
        query = "#{tmpTable} SELECT FirstName, LastName FROM @names WHERE LastName = 'Winnfield'"
        database.tryOneRow(query, (err, r) ->
            done(err) if err
            r.should.eql({ FirstName: 'Jules', LastName: 'Winnfield' })
            done()
        )
    )

    it('should allow empty resultsets when using tryOneRow', (done) ->
        query = "#{tmpTable} SELECT FirstName, LastName FROM @names WHERE FirstName = 'Pumpkin'"
        database.tryOneRow(query, (err, r) ->
            done(err) if err
            done("Resultset should be null") if r?
            done()
        )
    )

    it('should raise an error when tryOneRow finds more than 1 row', (done) ->
        query = "#{tmpTable} SELECT FirstName, LastName FROM @names WHERE LastName = 'Wallace'"
        database.tryOneRow(query, (err, r) ->
            err.should.match(/^Too many rows returned/)
            done()
        )
    )
)
