private void testAddNEventInfoReloadCache(IErrorIndex realIndex, int numEventInfos) { ErrorIndexCache index = new ErrorIndexCache(realIndex); index.Activate(); StackHashProduct product = new StackHashProduct(DateTime.Now, DateTime.Now, "http://www.cucku.com", 1, "TestProduct1", 20, 30, "2.10.02123.1293"); StackHashFile file = new StackHashFile(new DateTime(100), new DateTime(101), 39, new DateTime(102), "filename.dll", "1.2.3.4"); StackHashParameterCollection parameters = new StackHashParameterCollection(); parameters.Add(new StackHashParameter("param1", "param1value")); parameters.Add(new StackHashParameter("param2", "param2value")); StackHashEventSignature signature = new StackHashEventSignature(parameters); StackHashEvent theEvent = new StackHashEvent(new DateTime(102), new DateTime(103), "EventType1", 20000, signature, 99, 2); index.AddProduct(product); index.AddFile(product, file); index.AddEvent(product, file, theEvent); StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection(); for (int i = 0; i < numEventInfos; i++) { StackHashEventInfo eventInfo = new StackHashEventInfo(DateTime.Now.AddDays(i), DateTime.Now.AddDays(i + 1), DateTime.Now.AddDays(i + 2), "English" + i.ToString(), i, "locale" + i.ToString(), "OS" + i.ToString(), "OSVersion" + i.ToString(), i * 10); eventInfoCollection.Add(eventInfo); } index.AddEventInfoCollection(product, file, theEvent, eventInfoCollection); // Now reconnect a cache to make sure that the data has been stored ok. index = new ErrorIndexCache(realIndex); index.Activate(); // Now get all the event info and make sure it all matches. StackHashEventInfoCollection eventInfoCollection2 = index.LoadEventInfoList(product, file, theEvent); Assert.AreEqual(0, eventInfoCollection.CompareTo(eventInfoCollection2)); }
private void testCacheInitialiseNProductsAddAnotherProduct(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)); } // Now add one more product. StackHashProduct finalProduct = new StackHashProduct(DateTime.Now.AddDays(99), DateTime.Now.AddDays(99), null, 99, "TestProduct99", 99, 98, "2.10.02123.1293"); indexCache.AddProduct(finalProduct); // Now reload and check it is still there. indexCache = new ErrorIndexCache(realIndex); indexCache.Activate(); products = indexCache.LoadProductList(); Assert.AreNotEqual(null, products); Assert.AreEqual(numProducts + 1, products.Count); StackHashProduct latestProduct = indexCache.GetProduct(finalProduct.Id); Assert.AreNotEqual(null, latestProduct); Assert.AreEqual(0, finalProduct.CompareTo(latestProduct)); }