Exemple #1
0
        protected override void Arrange()
        {
            base.Arrange();

            accessor    = Database.CreateSqlStringAccessor <Product>("Select 'book' as ProductName, 12 as UnitPrice");
            asyncResult = accessor.BeginExecute(null, null);
        }
Exemple #2
0
        protected override void Arrange()
        {
            base.Arrange();

            accessor    = Database.CreateSprocAccessor <Product>("Ten Most Expensive Products");
            asyncResult = accessor.BeginExecute(null, null);
        }
        [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 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);
        }
        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);
        }
Exemple #6
0
        public IEnumerable <TResultTable> Run(StoredProcedure storedProcedure)
        {
            try
            {
                IRowMapper <TResultTable> resultTableMapper = MapBuilder <TResultTable> .MapAllProperties().Build();

                DataAccessor <TResultTable> accessor = database.CreateSprocAccessor(
                    storedProcedure.Name,
                    storedProcedure.ParameterMapper,
                    resultTableMapper);

                // Execute the accessor asynchronously, passing in the callback handler,
                // the existing accessor as the AsyncState, and the parameter values.

                asyncResult = accessor.BeginExecute(MyEndExecuteCallback,
                                                    accessor,
                                                    storedProcedure.ParameterValues);
            }
            catch
            {
                // handle any execution initiation errors here
                throw new Exception("Asyn operation has failed in method  public IEnumerable<TResultTable> Run(StoredProcedure storedProcedure) ");
            }

            return(result);
        }
        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());
        }
Exemple #10
0
        public void RunAsync(Database database, object[] param, IRowMapper <TResultTable> rowMapper)
        {
            try
            {
                IParameterMapper paramMapper = new SimpleParameterMapper();

                DataAccessor <TResultTable> accessor =
                    database.CreateSprocAccessor(StoredProcedureName, paramMapper, rowMapper);

                // Execute the accessor asynchronously, passing in the callback handler,
                // the existing accessor as the AsyncState, and the parameter values.
                IAsyncResult async = accessor.BeginExecute(MyEndExecuteCallback, accessor, param);
            }
            catch
            {
                // handle any execution initiation errors here
            }
        }
        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);
        }