Inheritance: DataObjectBase
Exemple #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 FluentByNameMapper_Save() {
            INameMapper nameMapper = new CapitalizeNameMapper();

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

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

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

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

            // update
            result = SQLiteRepository.ExecuteEntity("SaveOrUpdateCategory", category, nameMapper);
            Assert.AreNotEqual(0, result.AsInt());
        }
        public void PersistentObjectToDatabase() {
            var category = new Category { CategoryName = "Test", Description = "FluentUtil" };

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

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

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

            // update
            result = SQLiteRepository.ExecuteEntity("SaveOrUpdateCategory", category, CapitalizeMapper);
            Assert.AreNotEqual(0, result.AsInt());
        }
        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 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);
            }
        }