Example #1
0
        public void SetParameterValuesGeneric()
        {
            var category = new Category {
                CategoryName = "Test",
                Description  = "FluentUtil"
            };

            // delete exist category
            NorthwindAdoRepository.ExecuteNonQueryBySqlString(
                @"DELETE FROM Categories where CategoryName = @CategoryName",
                new AdoParameter("CategoryName", category.CategoryName, DbType.String, 255));

            // insert
            using (var command = NorthwindAdoRepository.GetProcedureCommand("SaveOrUpdateCategory", true)) {
                AdoTool.SetParameterValues(NorthwindAdoRepository.Db,
                                           command,
                                           category,
                                           command.Mapping(NameMappingUtil.CapitalizeMappingFunc('_', ' ')));


                category.CategoryId = NorthwindAdoRepository.ExecuteCommand(command).AsInt(-1);
                Assert.AreNotEqual(-1, category.CategoryId);
            }

            // update
            using (var command = NorthwindAdoRepository.GetProcedureCommand("SaveOrUpdateCategory", true)) {
                AdoTool.SetParameterValues(NorthwindAdoRepository.Db,
                                           command,
                                           category,
                                           command.Mapping(NameMappingUtil.CapitalizeMappingFunc('_', ' ')));

                category.CategoryId = NorthwindAdoRepository.ExecuteCommand(command).AsInt(-1);
                Assert.AreNotEqual(-1, category.CategoryId);
            }
        }
        public void TransactionScope_ShouldNotPromoteToDTC2()
        {
            TestTool.RunTasks(10,
                              () => {
                using (var txScope = AdoTool.CreateTransactionScope()) {
                    var count = TotalCount();

                    var ds = NorthwindAdoRepository.ExecuteDataSetBySqlString(SQL_REGION_SELECT, 1, 10);
                    var dt = NorthwindAdoRepository.ExecuteDataTableBySqlString(SQL_REGION_SELECT, 1, 10);

                    Assert.IsFalse(ds.Tables[0].HasErrors);
                    Assert.IsFalse(dt.HasErrors);

                    int rows = NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_INSERT);
                    Assert.AreEqual(1, rows);
                    rows = NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_INSERT2);
                    Assert.AreEqual(1, rows);

                    NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_DELETE);

                    ds = NorthwindAdoRepository.ExecuteDataSetBySqlString(SQL_REGION_SELECT);
                    dt = NorthwindAdoRepository.ExecuteDataTableBySqlString(SQL_REGION_SELECT);

                    txScope.Complete();
                }
            });
        }
        public void PersistentObjectToDatabase()
        {
            try {
                var category = new Category {
                    CategoryName = "Test", Description = "FluentUtil"
                };

                // delete exist category
                NorthwindAdoRepository.ExecuteNonQueryBySqlString("DELETE FROM Categories where CategoryName = @CategoryName",
                                                                  new AdoParameter("CategoryName", category.CategoryName));

                // insert
                var result = NorthwindAdoRepository.ExecuteEntity("SaveOrUpdateCategory", category, CapitalizeMapper);

                category.CategoryId = result.AsInt(-1);
                Assert.AreNotEqual(-1, category.CategoryId);

                // update
                result = NorthwindAdoRepository.ExecuteEntity("SaveOrUpdateCategory", category, CapitalizeMapper);
                Assert.IsTrue(result.AsInt() > 0);
            }
            catch (Exception ex) {
                if (log.IsErrorEnabled)
                {
                    log.Error(ex);
                }

                Assert.Fail(ex.Message);
            }
        }
        public void ExecuteNonQuery()
        {
            var row = NorthwindAdoRepository
                      .ExecuteNonQueryBySqlString("DELETE FROM Employees where LastName=@LastName and FirstName=@FirstName",
                                                  new AdoParameter("LastName", "Bae"),
                                                  new AdoParameter("FirstName", "Sunghyouk"));

            Console.WriteLine("Row affected=[{0}]", row);
        }
Example #5
0
        public static void DeleteStoredProcedures()
        {
            var queryBuilder = new StringBuilder();

            queryBuilder
            .Append("if object_id('RegionSelect') <> 0 drop procedure RegionSelect;")
            .Append("if object_id('RegionInsert') <> 0 drop procedure RegionInsert;")
            .Append("if object_id('RegionUpdate') <> 0 drop procedure RegionUpdate;")
            .Append("if object_id('RegionDelete') <> 0 drop procedure RegionDelete;");

            NorthwindAdoRepository.ExecuteNonQueryBySqlString(queryBuilder.ToString());
        }
        public void TransactionScope_ShouldNotPromoteToDTC()
        {
            int totalRows = TotalRows();
            int dtcCount  = 0;

            TransactionManager.DistributedTransactionStarted += delegate { Interlocked.Increment(ref dtcCount); };

            using (var ts = AdoTool.CreateTransactionScope()) {
                int rows = NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_INSERT);
                Assert.AreEqual(1, rows);
                rows = NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_INSERT2);
                Assert.AreEqual(1, rows);

                ts.Complete();
            }
            Assert.AreEqual(totalRows + 2, TotalRows());
            Assert.AreEqual(0, dtcCount);
        }
Example #7
0
        public static void CreateStoredProcedures()
        {
            var query = @"create procedure RegionSelect as select * from Region Order by RegionId";

            NorthwindAdoRepository.ExecuteNonQueryBySqlString(query);

            query = @"create procedure RegionInsert(@RegionID int, @RegionDescription varchar(100)) as "
                    + @"Insert into Region values(@RegionID, @RegionDescription)";

            NorthwindAdoRepository.ExecuteNonQueryBySqlString(query);

            query = @"create procedure RegionUpdate(@RegionID int, @RegionDescription varchar(100)) as "
                    + @"Update Region set RegionDescription=@RegionDescription where RegionID=@RegionID";

            NorthwindAdoRepository.ExecuteNonQueryBySqlString(query);

            query = @"create procedure RegionDelete(@RegionID int) as "
                    + @"Delete Region where RegionID=@RegionID";

            NorthwindAdoRepository.ExecuteNonQueryBySqlString(query);
        }
 public void TransactionScope_ShouldNotPromoteToDTC3()
 {
     TestTool.RunTasks(10,
                       () => AdoWith.TransactionScope(TransactionScopeOption.Required,
                                                      System.Transactions.IsolationLevel.ReadCommitted,
                                                      delegate { var count = TotalCount(); },
                                                      delegate {
         NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_INSERT);
         NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_INSERT2);
         NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_DELETE);
     },
                                                      delegate {
         var ds =
             NorthwindAdoRepository.ExecuteDataSetBySqlString(
                 SQL_REGION_SELECT, 1, 10);
     },
                                                      delegate {
         var dt =
             NorthwindAdoRepository.ExecuteDataTableBySqlString(
                 SQL_REGION_SELECT, 1, 10);
     }
                                                      ));
 }
        public void FluentByNameMapper_Save()
        {
            INameMapper nameMapper = new CapitalizeNameMapper();

            var category = new Category
            {
                CategoryName = "Test",
                Description  = "FluentUtil"
            };

            // delete exist category
            NorthwindAdoRepository.ExecuteNonQueryBySqlString("DELETE FROM Categories where CategoryName = @CategoryName",
                                                              new AdoParameter("CategoryName", category.CategoryName));

            // insert
            var result = NorthwindAdoRepository.ExecuteEntity("SaveOrUpdateCategory", category, nameMapper);

            category.CategoryId = result.AsInt(-1);
            Assert.AreNotEqual(-1, category.CategoryId);

            // update
            result = NorthwindAdoRepository.ExecuteEntity("SaveOrUpdateCategory", category, nameMapper);
            Assert.IsTrue(result.AsInt() > 0);
        }
 public void CleanUp()
 {
     NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_DELETE);
 }