Esempio n. 1
0
        public void PreInsertEventListener_must_be_fired()
        {
            IMappedStatement statement = statement = ((IModelStoreAccessor)dataMapper).ModelStore.GetMappedStatement("InsertAccount");

            Assert.That(statement, Is.Not.Null);
            statement.PreInsert += PreInsertEventHandler;

            Account account = new Account();

            account.Id           = 6;
            account.FirstName    = "Calamity";
            account.LastName     = "Jane";
            account.EmailAddress = "*****@*****.**";

            dataMapper.Insert("InsertAccount", account);

            account = dataMapper.QueryForObject <Account>("SelectAccount", 6);

            Assert.That(account, Is.Not.Null);
            Assert.That(account.Id, Is.EqualTo(6));
            Assert.That(account.FirstName, Is.EqualTo("Calamity"));
            Assert.That(account.LastName, Is.EqualTo("Jane"));
            Assert.That(account.EmailAddress, Is.EqualTo("*****@*****.**"));

            statement.PreInsert -= PreInsertEventHandler;
        }
Esempio n. 2
0
        public void TestCategoryInsertAndDelete()
        {
            //
            // Create and Insert new Category
            //
            Category c = new Category()
            {
                CategoryName = "Fish",
                Description  = "Live under water!"
            };
            object id = categories.Insert(c);
            //
            // Get the new category object from database
            //
            Category actual = (Category)categories.GetById(id);

            Assert.AreEqual(c.CategoryName, actual.CategoryName);
            Assert.AreEqual(c.Description, actual.Description);
            //
            // Delete the created category from database
            //
            categories.Delete(actual);
            object res = categories.GetById(id);

            actual = res != null ? (Category)res : default(Category);
            Assert.IsNull(actual.CategoryName);
            Assert.IsNull(actual.Description);
        }
Esempio n. 3
0
        public void TestRegionInsertAndDelete()
        {
            //
            // Create and Insert new Region
            //
            Region c = new Region()
            {
                RegionID          = 17,
                RegionDescription = "Central",
            };
            object id = regions.Insert(c);
            //
            // Get the new Region object from database
            //
            Region actual            = (Region)regions.GetById(id);
            string regionDescription = actual.RegionDescription;
            string trimmedResult     = regionDescription.Trim();

            trimmedResult = Regex.Replace(trimmedResult, @"\t|\n|\r", "");
            Assert.AreEqual(c.RegionDescription, trimmedResult);
            //
            // Delete the created Region from database
            //
            regions.Delete(actual);
            object res = regions.GetById(id);

            actual = res != null ? (Region)res : default(Region);

            Assert.IsNull(res);
        }
        internal void TestRegionInsertAndDelete()
        {
            //
            // Create and Insert new Region

            Region r = new Region()
            {
                RegionID          = 12,
                RegionDescription = "Western                                           ",
            };
            object id = regions.Insert(r);
            //
            // Get the new region object from database
            //
            Region actual = (Region)regions.GetById(12);

            Assert.AreEqual(r.RegionID, actual.RegionID);
            Assert.AreEqual(r.RegionDescription, actual.RegionDescription);

            // Delete the created region from database
            //
            regions.Delete(actual);
            object res = regions.GetById(12);

            actual = res != null ? (Region)res : default(Region);
            Assert.IsNull(actual);
        }
Esempio n. 5
0
        public static void m1()
        {
            Builder builder = new Builder(
                typeof(SqlDataMapper <>),
                new Object[] { SqlMapperUnitTest.getMySqlConnectionString() },
                typeof(PropertyColumnMapper),
                typeof(SingleConnectionPolicy));

            IDataMapper <ProductSimple> productMapper = builder.Build <ProductSimple>();
            IConnectionPolicy           policy        = productMapper.GetConnectionPolicy();

            ProductSimple p = productMapper.GetAll().First();

            p.ProductName = "Potatoes";
            productMapper.Update(p);

            ProductSimple p2 = productMapper.GetAll().First();

            p2.ProductName = "Chai";
            productMapper.Update(p2);

            ProductSimple novoP = new ProductSimple();

            novoP.ProductName     = "batatas";
            novoP.QuantityPerUnit = "setenta mil";
            productMapper.Insert(novoP);
        }
        public void TestProductInsertAndDelete()
        {
            //
            // Create and insert a new product
            //
            Category c = (Category)categories.GetById(4);
            Supplier s = (Supplier)suppliers.GetById(17);
            Product  p = new Product()
            {
                Category     = c,
                Supplier     = s,
                ProductName  = "Bacalhau",
                ReorderLevel = 23,
                UnitsInStock = 100,
                UnitsOnOrder = 40
            };
            object id = prods.Insert(p);
            //
            // Get the new product object from database
            //
            Product actual = (Product)prods.GetById(id);

            Assert.AreEqual(p.ProductName, actual.ProductName);
            Assert.AreEqual(p.UnitsInStock, actual.UnitsInStock);
            //
            // Delete the created product from database
            //
            prods.Delete(actual);
            actual = (Product)prods.GetById(id);
            Assert.IsNull(actual);
        }
Esempio n. 7
0
        public void TestEmployeeInsertAndDelete()
        {
            Employee e = new Employee()
            {
                LastName        = "Silva",
                FirstName       = "Manuel",
                Title           = "Sales Representative",
                TitleOfCourtesy = "Mr.",
                Address         = "There",
                City            = "This one",
                Region          = "That one",
                PostalCode      = "IDK",
                Country         = "Portugal",
                HomePhone       = "(206) 555-9857",
                Extension       = "100"
            };
            object id = employee.Insert(e);
            //
            // Get the new employee object from database
            //
            Employee actual = (Employee)employee.GetById(id);

            Assert.AreEqual(e.LastName, actual.LastName);
            Assert.AreEqual(e.FirstName, actual.FirstName);
            //
            // Delete the created employee from database
            //
            employee.Delete(actual);
            object res = employee.GetById(id);

            actual = res != null ? (Employee)res : default(Employee);
            Assert.IsNull(actual.LastName);
            Assert.IsNull(actual.FirstName);
        }
        public void TestShipperInsertAndDelete()
        {
            //
            // Create and Insert new Shipper
            //
            Shipper c = new Shipper()
            {
                CompanyName = "New Company",
                Phone       = "(555) 123-4567"
            };
            object id = shippers.Insert(c);
            //
            // Get the new category object from database
            //
            Shipper actual = (Shipper)shippers.GetById(id);

            Assert.AreEqual(c.CompanyName, actual.CompanyName);
            Assert.AreEqual(c.Phone, actual.Phone);
            //
            // Delete the created category from database
            //
            shippers.Delete(actual);
            object res = shippers.GetById(id);

            actual = res != null ? (Shipper)res : default(Shipper);
            Assert.IsNull(actual.CompanyName);
            Assert.IsNull(actual.Phone);
        }
Esempio n. 9
0
        public void TestRegionInsertAndDelete()
        {
            //
            // Create and Insert new Region
            //
            Region r = new Region()
            {
                RegionID          = 5,
                RegionDescription = "Northwest                                         "
            };
            object id = regions.Insert(r);
            //
            // Get the new Region object from database
            //
            Region actual = (Region)regions.GetById(id);

            Assert.AreEqual(r.RegionDescription, actual.RegionDescription);
            //
            // Delete the created Region from database
            //
            regions.Delete(actual);
            object res = regions.GetById(id);

            actual = res != null ? (Region)res : default(Region);
            Assert.IsNull(actual.RegionDescription);
        }
Esempio n. 10
0
        private void SeedDB()
        {
            var order1 = new Entities.FluentMappedOrder
            {
                OrderName = "Order 1"
            };

            _db.Insert <Entities.FluentMappedOrder>(order1);
        }
        public void NullValue_should_be_replaced()
        {
            Account account = NewAccount6();

            dataMapper.Insert("InsertAccountViaParameterMap", account);

            account = (Account)dataMapper.QueryForObject("GetAccountNullableEmail", 6);

            AssertAccount6(account);
        }
Esempio n. 12
0
        public void Nvelocity_procedure_with_dynamic_parameter_should_work()
        {
            Account account = new Account();

            account.Id               = 99;
            account.FirstName        = "Achille";
            account.LastName         = "Talon";
            account.NullBannerOption = false;

            IDictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("account", account);

            dataMapper.Insert("NVelocity.Procedure", parameters);

            Account testAccount = dataMapper.QueryForObject <Account>("NVelocity.Simple", parameters);

            Assert.IsNotNull(testAccount);
            Assert.That(testAccount.Id, Is.EqualTo(99));
            Assert.That(testAccount.EmailAddress, Is.EqualTo("*****@*****.**"));
            Assert.That(testAccount.BannerOption, Is.False);
            Assert.That(testAccount.CartOption, Is.False);

            account.Id               = 100;
            account.FirstName        = "Achille";
            account.LastName         = "Talon";
            account.NullBannerOption = true;
            account.CartOption       = true;

            parameters = new Dictionary <string, object>();
            parameters.Add("account", account);

            dataMapper.Insert("NVelocity.Procedure", parameters);

            testAccount = dataMapper.QueryForObject <Account>("NVelocity.Simple", parameters);

            Assert.IsNotNull(testAccount);
            Assert.That(testAccount.Id, Is.EqualTo(100));
            Assert.That(testAccount.EmailAddress, Is.EqualTo("*****@*****.**"));
            Assert.That(testAccount.BannerOption, Is.True);
            Assert.That(testAccount.CartOption, Is.True);
        }
Esempio n. 13
0
        public void CustomersInsert()
        {
            Customer cust1 = new Customer();

            cust1.CustomerID  = "SERRA";
            cust1.CompanyName = "Insert test kjd";
            custMapper.Insert(cust1);
            int res = connMan.GetAffectedRows();

            Assert.IsTrue(res == 1);
        }
        private void SeedDB()
        {
            var order1 = new FluentMappedOrder
            {
                OrderName = "Order 1"
            };

            var order2 = new FluentMappedOrder
            {
                OrderName = "Order 2"
            };

            _db.Insert <FluentMappedOrder>(order1);

            _db.Insert <FluentMappedOrder>(order2);

            foreach (var order in (new[] { order1, order2 }))
            {
                for (var i = 1; i < 3; i++)
                {
                    var oi = new FluentMappedOrderItem
                    {
                        ItemDescription = order.OrderName + " - Item " + i.ToString(),
                        OrderID         = order.ID,
                        Price           = 5.5m
                    };

                    _db.Insert <FluentMappedOrderItem>(oi);

                    var receipt = new FluentMappedReceipt
                    {
                        OrderItemID = oi.ID,
                        AmountPaid  = 5.5m
                    };

                    _db.Insert(receipt);
                }
            }
        }
Esempio n. 15
0
        public static void EmployeeEmit()
        {
            IDataMapper test   = EmitDataMapper.Build(typeof(Employee), connStr, true);
            object      id     = test.Insert(tester);
            IEnumerable res    = test.GetAll();
            Employee    actual = (Employee)test.GetById(id);

            test.Delete(actual);
            Employee original = (Employee)test.GetById(1);

            test.Update(tester);
            test.Update(original);
        }
Esempio n. 16
0
        public static void CustomerEmit()
        {
            IDataMapper test   = EmitDataMapper.Build(typeof(Customer), connStr, true);
            object      id     = test.Insert(insertTestC);
            IEnumerable res    = test.GetAll();
            Customer    actual = (Customer)test.GetById(id);

            test.Delete(actual);
            Customer original = (Customer)test.GetById("ALFKI");

            test.Update(updateTestC);
            test.Update(original);
        }
        public void TestCustomerInsertAndDelete()
        {
            //
            // Create and Insert new Customer
            //
            Customer c = new Customer()
            {
                CustomerID  = "TESTE",
                CompanyName = "Testing code",
                ContactName = "Programmer",
                Address     = "IP",
                City        = "Lisbon",
                PostalCode  = "IDK",
                Region      = "Potato",
                Country     = "Test",
                Phone       = "None",
                Fax         = "see above"
            };
            object id = customers.Insert(c);
            //
            // Get the new Customer object from database
            //
            Customer actual = (Customer)customers.GetById(id);

            Assert.AreEqual(actual.CustomerID, c.CustomerID);
            Assert.AreEqual(actual.CompanyName, c.CompanyName);
            Assert.AreEqual(actual.ContactName, c.ContactName);
            Assert.AreEqual(actual.Address, c.Address);
            Assert.AreEqual(actual.City, c.City);
            Assert.AreEqual(actual.PostalCode, c.PostalCode);
            Assert.AreEqual(actual.Region, c.Region);
            Assert.AreEqual(actual.Country, c.Country);
            Assert.AreEqual(actual.Phone, c.Phone);
            Assert.AreEqual(actual.Fax, c.Fax);
            //
            // Delete the created Customer from database
            //
            customers.Delete(actual);
            object res = customers.GetById(id);

            actual = res != null ? (Customer)res : default(Customer);
            Assert.IsNull(actual);
        }
Esempio n. 18
0
        public static void ProductEmit()
        {
            IDataMapper test       = EmitDataMapper.Build(typeof(Product), connStr, true);
            IDataMapper categories = EmitDataMapper.Build(typeof(Category), connStr, true);
            IDataMapper suppliers  = EmitDataMapper.Build(typeof(Supplier), connStr, true);

            Category c = (Category)categories.GetById(4);
            Supplier s = (Supplier)suppliers.GetById(17);

            object      id     = test.Insert(ProductBuilder(c, s));
            IEnumerable res    = test.GetAll();
            Product     actual = (Product)test.GetById(id);

            test.Delete(actual);

            Product original = (Product)test.GetById(10);

            c = (Category)categories.GetById(4);
            s = (Supplier)suppliers.GetById(17);


            test.Update(ProductBuilder(c, s));
            test.Update(original);
        }
Esempio n. 19
0
 public void AddEntity(T entity)
 {
     DataMapper.Insert(typeof(T).Name + ConfigurationManager.AppSettings["InsertSuffix"], entity);
 }
 public void Add(T entity)
 {
     // throw new NotImplementedException();
     // _dataSet.Add(entity);
     _dataMapper.Insert(entity);
 }
Esempio n. 21
0
 public void Insert(Module module)
 {
     _moduleDataMapper.Insert(module);
 }
Esempio n. 22
0
 public void Insert(CourseProfile profile)
 {
     _profileDataMapper.Insert(profile);
 }
 public void Add(T entity)
 {
     // throw new NotImplementedException();
     // I have no choice but to cheat and write directly in the DB
     _dataMapper.Insert(entity);
 }
Esempio n. 24
0
 internal object Insert(string statementName, object parameterObject)
 {
     return(dataMapper.Insert(statementName, parameterObject));
 }