Beispiel #1
0
        private void testCacheInitialiseNProducts(IErrorIndex realIndex, int numProducts)
        {
            realIndex.Activate();
            StackHashProductCollection allProducts = new StackHashProductCollection();

            for (int i = 0; i < numProducts; i++)
            {
                DateTime         creationDateTime = new DateTime(2010, 04, 04, 22, 9, 0, DateTimeKind.Utc).AddDays(i);
                DateTime         modifiedDateTime = new DateTime(2010, 05, 05, 23, 10, 0, DateTimeKind.Utc).AddDays(i);
                int              productId        = 200 + i;
                StackHashProduct product1         =
                    new StackHashProduct(creationDateTime, modifiedDateTime, null, productId, "TestProduct1", 20 + i, 30 + i, "2.10.02123.1293");

                realIndex.AddProduct(product1);
            }

            // Hook up the cache and call LoadProductList.
            ErrorIndexCache indexCache = new ErrorIndexCache(realIndex);

            indexCache.Activate();

            // Get the product list.
            StackHashProductCollection products = indexCache.LoadProductList();

            Assert.AreNotEqual(null, products);
            Assert.AreEqual(numProducts, products.Count);

            for (int i = 0; i < allProducts.Count; i++)
            {
                Assert.AreEqual(0, allProducts[0].CompareTo(products.FindProduct(allProducts[0].Id)));
            }

            // Hook up the cache afresh and call GetProduct.
            indexCache = new ErrorIndexCache(realIndex);
            indexCache.Activate();
            for (int i = 0; i < allProducts.Count; i++)
            {
                StackHashProduct thisProduct = indexCache.GetProduct(allProducts[i].Id);
                Assert.AreNotEqual(null, thisProduct);
                Assert.AreEqual(0, allProducts[i].CompareTo(thisProduct));
            }
        }
Beispiel #2
0
        private void testSaveNProducts(IErrorIndex index, int numProducts)
        {
            index.Activate();
            StackHashProductCollection allProducts = new StackHashProductCollection();

            for (int i = 0; i < numProducts; i++)
            {
                DateTime         creationDateTime = new DateTime(2010, 04, 04, 22, 9, 0, DateTimeKind.Utc);
                DateTime         modifiedDateTime = new DateTime(2010, 05, 05, 23, 10, 0, DateTimeKind.Utc);
                StackHashProduct product1         =
                    new StackHashProduct(creationDateTime, modifiedDateTime, null, 1 + i, "TestProduct1" + i.ToString(), 20 + i, 30 + i, "2.10.02123.1293" + i.ToString());

                index.AddProduct(product1);
                allProducts.Add(product1);
            }

            // Get the product list.
            StackHashProductCollection products = index.LoadProductList();

            Assert.AreNotEqual(null, products);
            Assert.AreEqual(numProducts, products.Count);

            for (int i = 0; i < allProducts.Count; i++)
            {
                StackHashProduct thisProduct = products.FindProduct(allProducts[i].Id);
                Assert.AreNotEqual(null, thisProduct);

                Assert.AreEqual(0, allProducts[i].CompareTo(thisProduct));

                thisProduct = index.GetProduct(allProducts[i].Id);
                Assert.AreNotEqual(null, thisProduct);
                Assert.AreEqual(0, allProducts[i].CompareTo(thisProduct));


                // Check that the dates are stored in UTC.
                Assert.AreEqual(true, thisProduct.DateCreatedLocal.Kind == DateTimeKind.Utc);
                Assert.AreEqual(true, thisProduct.DateModifiedLocal.Kind == DateTimeKind.Utc);
            }

            Assert.AreEqual(numProducts, index.TotalProducts);
        }