Exemplo n.º 1
0
        /// <summary>
        /// Returns copy of cached object
        /// </summary>
        public void TestReturnCopyOfCachedOject()
        {
            CacheModel cacheModel = new CacheModel("test", typeof(LruCache).FullName, 60, 1, true);

            Order order = new Order(); 
            order.CardNumber = "CardNumber";
            order.Date = DateTime.Now;
            order.LineItemsCollection = new LineItemCollection();

            LineItem item = new LineItem();
            item.Code = "Code1";
            order.LineItemsCollection.Add(item);

            item = new LineItem();
            item.Code = "Code2";
            order.LineItemsCollection.Add(item);

            CacheKey key = new CacheKey();
            key.Update(order);

            int firstId = HashCodeProvider.GetIdentityHashCode(order);
            cacheModel[ key ] = order;

            Order order2 = cacheModel[ key ] as Order;
            int secondId = HashCodeProvider.GetIdentityHashCode(order2);
            Assert.AreNotEqual(firstId, secondId, "hasCode equal");

        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns reference to same instance of cached object
        /// </summary>
        public void TestReturnInstanceOfCachedOject()
        {
            CacheModel cacheModel = new CacheModel("test", typeof(LruCache).FullName, 60, 1, false);

            //cacheModel.FlushInterval = interval;
            //cacheModel.IsReadOnly = true;
            //cacheModel.IsSerializable = false;

            Order order = new Order(); 
            order.CardNumber = "CardNumber";
            order.Date = DateTime.Now;
            order.LineItemsCollection = new LineItemCollection();
            LineItem item = new LineItem();
            item.Code = "Code1";
            order.LineItemsCollection.Add(item);
            item = new LineItem();
            item.Code = "Code2";
            order.LineItemsCollection.Add(item);

            CacheKey key = new CacheKey();
            key.Update(order);

            int firstId = HashCodeProvider.GetIdentityHashCode(order);
            cacheModel[ key ] = order;

            Order order2 = cacheModel[ key ] as Order;
            int secondId = HashCodeProvider.GetIdentityHashCode(order2);
            Assert.AreEqual(firstId, secondId, "hasCode different");
        }
Exemplo n.º 3
0
        public void TestNullValueReplacementOnDateTime()
        {
            Account account = NewAccount6();

            dataMapper.Insert("InsertAccountViaParameterMap", account);

            Order order = new Order();
            order.Id = 99;
            order.CardExpiry = "09/11";
            order.Account = account;
            order.CardNumber = "154564656";
            order.CardType = "Visa";
            order.City = "Lyon";
            order.Date = System.DateTime.MinValue; //<-- null replacement
            order.PostalCode = "69004";
            order.Province = "Rhone";
            order.Street = "rue Durand";

            dataMapper.Insert("InsertOrderViaParameterMap", order);

            Order orderTest = (Order)dataMapper.QueryForObject("GetOrderLiteByColumnName", 99);

            Assert.AreEqual(System.DateTime.MinValue, orderTest.Date);
        }
Exemplo n.º 4
0
        public void TestNullValueReplacementOnDecimal()
        {
            Account account = NewAccount6();

            dataMapper.Insert("InsertAccountViaParameterMap", account);

            Order order = new Order();
            order.Id = 99;
            order.CardExpiry = "09/11";
            order.Account = account;
            order.CardNumber = "154564656";
            order.CardType = "Visa";
            order.City = "Lyon";
            order.Date = System.DateTime.MinValue; //<-- null replacement for parameterMAp 
            order.PostalCode = "69004";
            order.Province = "Rhone";
            order.Street = "rue Durand";

            dataMapper.Insert("InsertOrderViaParameterMap", order);

            LineItem item = new LineItem();
            item.Id = 99;
            item.Code = "test";
            item.Price = -99.99m;//<-- null replacement for parameterMAp 
            item.Quantity = 99;
            item.Order = order;

            dataMapper.Insert("InsertLineItem", item);

            // Retrieve LineItem & test null replacement for resultMap 

            LineItem testItem = (LineItem)dataMapper.QueryForObject("GetSpecificLineItemWithNullReplacement", 99);

            Assert.IsNotNull(testItem);
            Assert.AreEqual(-77.77m, testItem.Price);
            Assert.AreEqual("test", testItem.Code);
        }
Exemplo n.º 5
0
        public void TestByteArrayMapping()
        {
            Account account = NewAccount6();

            dataMapper.Insert("InsertAccountViaParameterMap", account);

            Order order = new Order();
            order.Id = 99;
            order.CardExpiry = "09/11";
            order.Account = account;
            order.CardNumber = "154564656";
            order.CardType = "Visa";
            order.City = "Lyon";
            order.Date = System.DateTime.MinValue;
            order.PostalCode = "69004";
            order.Province = "Rhone";
            order.Street = "rue Durand";

            dataMapper.Insert("InsertOrderViaParameterMap", order);

            LineItem item = new LineItem();
            item.Id = 99;
            item.Code = "test";
            item.Price = -99.99m;
            item.Quantity = 99;
            item.Order = order;
            item.PictureData = new byte[] { 1, 2, 3 };

            // Check insert
            dataMapper.Insert("InsertLineItemWithPicture", item);

            // select
            LineItem loadItem = null;

            Hashtable param = new Hashtable();
            param.Add("LineItem_ID", 99);
            param.Add("Order_ID", 99);

            loadItem = dataMapper.QueryForObject("GetSpecificLineItemWithPicture", param) as LineItem;

            Assert.IsNotNull(loadItem.Id);
            Assert.IsNotNull(loadItem.PictureData);
            Assert.AreEqual(item.PictureData, loadItem.PictureData);
        }
Exemplo n.º 6
0
        public void TestInsertOrderViaProperties()
        {
            Account account = NewAccount6();

            dataMapper.Insert("InsertAccountViaParameterMap", account);

            Order order = new Order();
            order.Id = 99;
            order.CardExpiry = "09/11";
            order.Account = account;
            order.CardNumber = "154564656";
            order.CardType = "Visa";
            order.City = "Lyon";
            order.Date = DateTime.Now;
            order.PostalCode = "69004";
            order.Province = "Rhone";
            order.Street = "rue Durand";

            dataMapper.Insert("InsertOrderViaPublicFields", order);
        }
Exemplo n.º 7
0
        public void TestOrderLineItemGroupBy()
        {
            InitScript(sessionFactory.DataSource, scriptDirectory + "petstore-drop.sql");
            InitScript(sessionFactory.DataSource, scriptDirectory + "account-init.sql");
            InitScript(sessionFactory.DataSource, scriptDirectory + "order-init.sql");
            InitScript(sessionFactory.DataSource, scriptDirectory + "line-item-init.sql");

            Order order = new Order();
            order.Id = 11;
            LineItem item = new LineItem();
            item.Id = 10;
            item.Code = "blah";
            item.Price = 44.00m;
            item.Quantity = 1;
            item.Order = order;

            dataMapper.Insert("InsertLineItemPostKey", item);

            
            IList list = dataMapper.QueryForList("GetOrderLineItem", null);

            Assert.AreEqual(11, list.Count);
            
            order = (Order)list[0];
            Assert.AreEqual(3, order.LineItemsIList.Count);
            Assert.IsNotNull(order.Account);
            AssertAccount1(order.Account);

            order = (Order)list[10];
            Assert.AreEqual(1, order.LineItemsIList.Count);
            Assert.IsNull(order.Account);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Verify that the input order is equal to the order(id=1).
        /// </summary>
        /// <param name="order">An order object.</param>
        protected void AssertOrder1(Order order)
        {
            DateTime date = new DateTime(2003, 2, 15, 8, 15, 00);

            Assert.AreEqual(1, order.Id, "order.Id");
            Assert.AreEqual(date.ToString(), order.Date.ToString(), "order.Date");
            Assert.AreEqual("VISA", order.CardType, "order.CardType");
            Assert.AreEqual("999999999999", order.CardNumber, "order.CardNumber");
            Assert.AreEqual("05/03", order.CardExpiry, "order.CardExpiry");
            Assert.AreEqual("11 This Street", order.Street, "order.Street");
            Assert.AreEqual("Victoria", order.City, "order.City");
            Assert.AreEqual("BC", order.Province, "order.Id");
            Assert.AreEqual("C4B 4F4", order.PostalCode, "order.PostalCode");
        }
Exemplo n.º 9
0
        public void TestComplexMappingViaHasTable()
        {
            Hashtable param = new Hashtable();

            Account a = new Account();
            a.FirstName = "Joe";
            param.Add("Account",a);

            Order o = new Order();
            o.City = "Dalton";
            param.Add("Order", o);

            Account accountTest = (Account) dataMapper.QueryForObject("GetAccountComplexMapping", param);

            AssertAccount1(accountTest);
        }
Exemplo n.º 10
0
        public void TestNullValueReplacementForDateTimeWithHashtable()
        {
            Account account = NewAccount6();

            dataMapper.Insert("InsertAccountViaParameterMap", account);

            Order order = new Order();
            order.Id = 99;
            order.CardExpiry = "09/11";
            order.Account = account;
            order.CardNumber = "154564656";
            order.CardType = "Visa";
            order.City = "Lyon";
            order.Date = DateTime.MinValue; //<-- null replacement
            order.PostalCode = "69004";
            order.Province = "Rhone";
            order.Street = "rue Durand";
 
            dataMapper.Insert("InsertOrderViaParameterMap", order);

            Hashtable orderTest = (Hashtable) dataMapper.QueryForObject("GetOrderByHashTable", 99);

            Assert.AreEqual(orderTest["Date"], DateTime.MinValue);
        }