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);
        }
예제 #2
0
        public void TestRegionGetById()
        {
            Region r = (Region)regions.GetById(1);

            Assert.AreEqual("Eastern                                           ", r.RegionDescription);
            //Assert.AreEqual("Western                                           ", r.RegionDescription); //id=2
        }
예제 #3
0
        public void TestGenericProductGetById()
        {
            Product p = prods.GetById(10);

            Assert.AreEqual("Ikura", p.ProductName);
            Assert.AreEqual("Seafood", p.Category.CategoryName);
            Assert.AreEqual("Tokyo Traders", p.Supplier.CompanyName);
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
0
 protected override object Load(IDataReader dr)
 {
     return(new Product {
         ProductID = (int)Caster(dr["ProductID"]),
         ProductName = (string)Caster(dr["ProductName"]),
         Supplier = (Supplier)suppliers.GetById(dr["SupplierID"]),
         Category = (Category)categories.GetById(dr["CategoryID"]),
         UnitsInStock = (short)Caster(dr["UnitsInStock"]),
         UnitsOnOrder = (short)Caster(dr["UnitsOnOrder"]),
         ReorderLevel = (short)Caster(dr["ReorderLevel"])
     });
 }
        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);
        }
예제 #8
0
        public void TestRegionGetById()
        {
            Region c             = (Region)regions.GetById(3);
            string trimmedResult = c.RegionDescription.Trim(); ///TODO porque é que tem espaços vazios, a info vinda da query?

            Assert.AreEqual("Northern", trimmedResult);
        }
        public void TestShipperGetById()
        {
            Shipper c = (Shipper)shippers.GetById(3);

            Assert.AreEqual("Federal Shipping", c.CompanyName);
            Assert.AreEqual("(503) 555-9931", c.Phone);
        }
예제 #10
0
        public void TestCategoryGetById()
        {
            Category c = (Category)categories.GetById(3);

            Assert.AreEqual("Confections", c.CategoryName);
            Assert.AreEqual("Desserts, candies, and sweet breads", c.Description);
        }
예제 #11
0
        protected override object Load(SqlDataReader dr)
        {
            Product p = new Product();

            p.ProductID    = (int)dr["ProductID"];
            p.ProductName  = (string)dr["ProductName"];
            p.Supplier     = (Supplier)suppliers.GetById(dr["SupplierID"]);
            p.Category     = (Category)categories.GetById(dr["CategoryID"]);
            p.UnitsInStock = (short)dr["UnitsInStock"];
            p.UnitsOnOrder = (short)dr["UnitsOnOrder"];
            p.ReorderLevel = (short)dr["ReorderLevel"];
            return(p);
        }
예제 #12
0
        public void TestEmployeeGetById()
        {
            Employee e = (Employee)employee.GetById(1);

            Assert.AreEqual("Davolio", e.LastName);
            Assert.AreEqual("Nancy", e.FirstName);
            Assert.AreEqual("Sales Representative", e.Title);
        }
예제 #13
0
        public Product GetById(int id, SqlTransaction trx)
        {
            using (SqlCommand cmdGet = sqlGetById(c))
            {
                if (trx != null)
                {
                    cmdGet.Transaction = trx;
                }

                cmdGet.Parameters["@ProductId"].Value = id;
                using (SqlDataReader dr = cmdGet.ExecuteReader())
                {
                    dr.Read();
                    Product newProd = new Product(
                        (int)dr[0],
                        (string)dr[1],
                        (decimal)dr[2],
                        (short)dr[3],
                        suppMapper.GetById((int)dr[4]));
                    return(newProd);
                }
            }
        }
예제 #14
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);
        }
        public void TestCustomerGetById()
        {
            Customer c = (Customer)customers.GetById("ALFKI");

            Assert.AreEqual("ALFKI", c.CustomerID);
            Assert.AreEqual("Alfreds Futterkiste", c.CompanyName);
            Assert.AreEqual("Maria Anders", c.ContactName);
            Assert.AreEqual("Obere Str. 57", c.Address);
            Assert.AreEqual("Berlin", c.City);
            Assert.AreEqual("12209", c.PostalCode);
            Assert.IsNull(c.Region);
            Assert.AreEqual("Germany", c.Country);
            Assert.AreEqual("030-0074321", c.Phone);
            Assert.AreEqual("030-0076545", c.Fax);
        }
예제 #16
0
        public IEnumerator <object> GetEnumerator()
        {
            if (results == null)
            {
                results = new List <object>();
                Dictionary <string, Type> allEDMembers = columnMapper.MapEDMembersTypes();

                connectionPolicy.DoBeforeCommandExecution();
                using (SqlCommand cmd = connectionPolicy.GetConnection().CreateCommand())
                {
                    cmd.Transaction = connectionPolicy.GetTransaction();
                    cmd.CommandText = "SELECT * FROM " + tableName;
                    if (!string.IsNullOrEmpty(whereClause))
                    {
                        cmd.CommandText = string.Format("{0} WHERE {1}", cmd.CommandText, whereClause);
                    }

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            Dictionary <string, object> members = columnMapper.MapAllMembers(dr);
                            foreach (string name in allEDMembers.Keys)
                            {
                                IDataMapper dataMapper    = foreignMappers[allEDMembers[name]];
                                object      foreignObject = dataMapper.GetById(members[name]);
                                members[name] = foreignObject;
                            }

                            object newObject = columnMapper.MapMembersIntoObject(members);
                            results.Add(newObject);
                        }
                    }
                }
                connectionPolicy.DoAfterCommandExecution();
            }
            foreach (object obj in results)
            {
                yield return(obj);
            }
        }
예제 #17
0
        public static void m1()
        {
            Builder builder = new Builder(
                SqlDataMapperType,
                DataMapperParams,
                //FieldsColumnMapperType,
                PropertyColumnMapperType,
                MultipleConnectionPolicyType);
            IDataMapper productMapper = builder.Build <Product>();

            SqlEnumerable prods = productMapper.GetAll();
            Product       p2    = (Product)productMapper.GetById(1);

            p2.SupplierID.ContactName = "Charlotte";
            productMapper.Update(p2);

            p2.SupplierID.ContactName = "Charlotte Cooper";
            productMapper.Update(p2);

            foreach (Product p in prods)
            {
                Console.WriteLine(p);
            }
        }
예제 #18
0
        public void TestEmployeeGetById()
        {
            EmployeeP3 e = (EmployeeP3)employee.GetById(1);

            Assert.AreEqual("Davolio", e.LastName);
            Assert.AreEqual("Nancy", e.FirstName);
            Assert.AreEqual("Sales Representative", e.Title);
            IEnumerable <Order> a = e.Orders;
            IEnumerable <Order> b = ((AbstractDataMapper <int, Order>)orders).Get("SELECT * FROM Orders WHERE EmployeeID = 1");
            int countA            = 0;
            int countB            = 0;

            foreach (Order o in a)
            {
                countA++;
            }

            foreach (Order o in b)
            {
                countB++;
            }
            Assert.AreEqual(countA, countB);
        }