예제 #1
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);
            }
        }
예제 #2
0
        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);
        }