public void ResultsAreReturnedWhenExecutingAsyncStoredProcAccessorMapByNameWithPropInfo()
        {
            Database            db       = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync");
            DataAccessor <Test> accessor = db.CreateSprocAccessor <Test>("GetTestData", MapBuilder <Test> .MapNoProperties()
                                                                         .MapByName(typeof(Test).GetProperty("TestID"))
                                                                         .MapByName(typeof(Test).GetProperty("TestName"))
                                                                         .Build());
            AsyncCallback cb     = new AsyncCallback(EndExecuteAccessor <Test>);
            DbAsyncState  state  = new DbAsyncState(db, accessor);
            IAsyncResult  result = accessor.BeginExecute(cb, state);

            state.AutoResetEvent.WaitOne(new TimeSpan(0, 0, 15));
            IEnumerable <Test> resultSet = (IEnumerable <Test>)state.State;

            if (state.Exception != null)
            {
                Console.WriteLine(state.Exception);
            }
            Assert.IsNull(state.Exception);

            var first = resultSet.First();

            Assert.AreEqual(1, first.TestID);
            Assert.AreEqual("Test1", first.TestName);
            Assert.AreEqual(default(string), first.TestDescription);
            Assert.AreEqual(null, first.BugsCreated);
            Assert.AreEqual(default(DateTime), first.CreatedDate);
            Assert.AreEqual(null, first.UpdatedDate);
        }
        [Ignore] // until raised bug is fixed
        public void ResultsAreReturnedWhenExecutingAsyncStoredProcAccessorWithNullableProperties()
        {
            Database            db       = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync");
            DataAccessor <Test> accessor = db.CreateSprocAccessor <Test>("GetTestData", MapBuilder <Test> .MapAllProperties()
                                                                         .DoNotMap(s => s.CreatedDate)
                                                                         .Build());

            AsyncCallback cb     = new AsyncCallback(EndExecuteAccessor <Test>);
            DbAsyncState  state  = new DbAsyncState(db, accessor);
            IAsyncResult  result = accessor.BeginExecute(cb, state);

            state.AutoResetEvent.WaitOne(new TimeSpan(0, 0, 15));
            IEnumerable <Test> resultSet = (IEnumerable <Test>)state.State;

            if (state.Exception != null)
            {
                Console.WriteLine(state.Exception);
            }
            Assert.IsNull(state.Exception);

            var first = resultSet.First();
            var last  = resultSet.Last();

            Assert.AreEqual("Test10", last.TestName);
            Assert.AreEqual(null, last.BugsCreated);
            Assert.AreEqual("Test1", first.TestName);
            Assert.AreEqual(1, first.BugsCreated);
        }
        public void ResultsAreReturnedWhenExecutingAsyncStoredProcAccessorMapNoPropertiesWithFunc()
        {
            Database db = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync");
            DataAccessor <TopTenProduct> accessor = db.CreateSprocAccessor <TopTenProduct>("Ten Most Expensive Products", MapBuilder <TopTenProduct> .MapNoProperties()
                                                                                           .Map(s => s.UnitPrice)
                                                                                           .WithFunc(r => r.GetDecimal(1))
                                                                                           .Build());
            AsyncCallback cb     = new AsyncCallback(EndExecuteAccessor <TopTenProduct>);
            DbAsyncState  state  = new DbAsyncState(db, accessor);
            IAsyncResult  result = accessor.BeginExecute(cb, state);

            state.AutoResetEvent.WaitOne(new TimeSpan(0, 0, 15));
            IEnumerable <TopTenProduct> resultSet = (IEnumerable <TopTenProduct>)state.State;
            var first = resultSet.First();

            if (state.Exception != null)
            {
                Console.WriteLine(state.Exception);
            }
            Assert.IsNull(state.Exception);


            Assert.AreEqual(default(string), first.TenMostExpensiveProducts);
            Assert.AreEqual(263, (int)first.UnitPrice);
        }
        public void ArgumentNullExceptionIsThrownWhenExecutingAsyncStoredProcAccessorWithRowMapperWithNullFunction()
        {
            Database            db       = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync");
            DataAccessor <Test> accessor = db.CreateSprocAccessor <Test>("GetTestData", MapBuilder <Test> .MapAllProperties()
                                                                         .Map(p => p.TestDescription)
                                                                         .WithFunc(null)
                                                                         .Build());
            AsyncCallback cb     = new AsyncCallback(EndExecuteAccessor <Test>);
            DbAsyncState  state  = new DbAsyncState(db, accessor);
            IAsyncResult  result = accessor.BeginExecute(cb, state);

            state.AutoResetEvent.WaitOne(new TimeSpan(0, 0, 15));
            IEnumerable <Test> resultSet = (IEnumerable <Test>)state.State;

            resultSet.First();
        }
        public void ResultsAreReturnedWhenExecutingAsyncStoredProcAccessorInValidStoredProc()
        {
            Database            db       = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync");
            DataAccessor <Test> accessor = db.CreateSprocAccessor <Test>("GetTestData1");
            AsyncCallback       cb       = new AsyncCallback(EndExecuteAccessor <Test>);
            DbAsyncState        state    = new DbAsyncState(db, accessor);
            IAsyncResult        result   = accessor.BeginExecute(cb, state);

            state.AutoResetEvent.WaitOne(new TimeSpan(0, 0, 15));
            IEnumerable <Test> resultSet = (IEnumerable <Test>)state.State;

            if (state.Exception != null)
            {
                Console.WriteLine(state.Exception.ToString());
            }
            Assert.IsInstanceOfType(state.Exception, typeof(SqlException));
        }
        public void ResultsAreReturnedWhenExecutingAsyncStoredProcAccessor()
        {
            Database db = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync");
            DataAccessor <TopTenProduct> accessor = db.CreateSprocAccessor <TopTenProduct>("Ten Most Expensive Products");
            AsyncCallback cb     = new AsyncCallback(EndExecuteAccessor <TopTenProduct>);
            DbAsyncState  state  = new DbAsyncState(db, accessor);
            IAsyncResult  result = accessor.BeginExecute(cb, state);

            state.AutoResetEvent.WaitOne(new TimeSpan(0, 0, 15));
            IEnumerable <TopTenProduct> resultSet = (IEnumerable <TopTenProduct>)state.State;

            object[] paramsArray = { };
            DataSet  ds          = db.ExecuteDataSet("Ten Most Expensive Products", paramsArray);

            Assert.IsNull(state.Exception);
            Assert.AreEqual <int>(ds.Tables[0].Rows.Count, resultSet.Count());
        }
        public void EndExecuteAccessor <T>(IAsyncResult result)
        {
            DaabAsyncResult daabResult = (DaabAsyncResult)result;
            DbAsyncState    state      = (DbAsyncState)daabResult.AsyncState;

            try
            {
                DataAccessor <T> accessor = (DataAccessor <T>)state.Accessor;
                state.State = accessor.EndExecute(result);
            }
            catch (Exception e)
            {
                state.Exception = e;
            }
            finally
            {
                state.AutoResetEvent.Set();
            }
        }
        public void InvalidCastExceptionIsThrownWhenExecutingAsyncStoredProcAccessorWithRowMapperToColumnInvalidTypeCast()
        {
            Database            db       = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync");
            DataAccessor <Test> accessor = db.CreateSprocAccessor <Test>("GetTestData", MapBuilder <Test> .MapAllProperties()
                                                                         .Map(a => a.CreatedDate)
                                                                         .ToColumn("TestID")
                                                                         .Build());
            AsyncCallback cb     = new AsyncCallback(EndExecuteAccessor <Test>);
            DbAsyncState  state  = new DbAsyncState(db, accessor);
            IAsyncResult  result = accessor.BeginExecute(cb, state);

            state.AutoResetEvent.WaitOne(new TimeSpan(0, 0, 15));
            IEnumerable <Test> resultSet = (IEnumerable <Test>)state.State;

            if (state.Exception != null)
            {
                Console.WriteLine(state.Exception);
            }
            Assert.IsNull(state.Exception);
            resultSet.ToList();
        }
        public void ResultsAreReturnedWhenExecutingAsyncStoredProcAccessorWithRowMapperToColumn()
        {
            Database db = new DatabaseProviderFactory(base.ConfigurationSource).Create("DefaultSqlAsync");
            DataAccessor <TopTenProductWithSalePrice> accessor = db.CreateSprocAccessor <TopTenProductWithSalePrice>("Ten Most Expensive Products", MapBuilder <TopTenProductWithSalePrice> .MapAllProperties()
                                                                                                                     .Map(p => p.SellingPrice)
                                                                                                                     .ToColumn("UnitPrice").Build());
            AsyncCallback cb     = new AsyncCallback(EndExecuteAccessor <TopTenProductWithSalePrice>);
            DbAsyncState  state  = new DbAsyncState(db, accessor);
            IAsyncResult  result = accessor.BeginExecute(cb, state);

            state.AutoResetEvent.WaitOne(new TimeSpan(0, 0, 15));
            IEnumerable <TopTenProductWithSalePrice> resultSet = (IEnumerable <TopTenProductWithSalePrice>)state.State;

            if (state.Exception != null)
            {
                Console.WriteLine(state.Exception);
            }
            Assert.IsNull(state.Exception);

            var first = resultSet.First();

            Assert.AreEqual(first.SellingPrice, first.UnitPrice);
        }