// // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion /// <summary> /// Add n event notes /// </summary> public void getPackages(int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs, bool useSameLocale, bool incrementingEventId, bool randomEventIds) { int cabId = 1000; int eventId = 1320080390; int fileId = 0x12345678; int productId = 122; Random rand = new Random(100); m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); Dictionary <int, StackHashEventPackageCollection> expectedProductEvents = new Dictionary <int, StackHashEventPackageCollection>(); StackHashProductCollection allProducts = new StackHashProductCollection(); for (int productCount = 0; productCount < numProducts; productCount++) { 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, productId++, "TestProduct1", 20, 30, "2.10.02123.1293"); m_Index.AddProduct(product1); allProducts.Add(product1); StackHashEventPackageCollection allAddedEvents = new StackHashEventPackageCollection(); for (int fileCount = 0; fileCount < numFiles; fileCount++) { StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, fileId++, creationDateTime, "File1.dll", "2.3.4.5"); StackHashEventSignature eventSignature = new StackHashEventSignature(); eventSignature.Parameters = new StackHashParameterCollection(); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamApplicationName, "AppName")); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamApplicationVersion, "1.2.3.4")); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamApplicationTimeStamp, creationDateTime.ToString())); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamModuleName, "ModuleName")); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamModuleVersion, "2.3.4.5")); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamModuleTimeStamp, creationDateTime.ToString())); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamExceptionCode, "1234")); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamOffset, "0x1234")); eventSignature.InterpretParameters(); m_Index.AddFile(product1, file1); for (int eventCount = 0; eventCount < numEvents; eventCount++) { StackHashEvent event1 = new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName1", eventId, eventSignature, eventCount, file1.Id, "bug" + eventCount.ToString()); if (randomEventIds) { eventId = rand.Next(100, 1320080390); } else { if (incrementingEventId) { eventId++; } else { eventId--; } } m_Index.AddEvent(product1, file1, event1); StackHashEventInfoCollection eventInfos = new StackHashEventInfoCollection(); int hitCount = 1; int totalHits = 0; for (int i = 0; i < numEventInfos; i++) { DateTime nowTime = DateTime.Now; DateTime date = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0); int localeId = 10; if (!useSameLocale) { localeId += i; } totalHits += hitCount; StackHashEventInfo eventInfo = new StackHashEventInfo(date.AddDays(i * 1), date.AddDays(i * 2), date.AddDays(i * 3), "US", localeId, "English", "Windows Vista" + i.ToString(), "1.2.3.4 build 7", hitCount++); eventInfos.Add(eventInfo); } event1.TotalHits = totalHits; m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos); StackHashCabCollection cabs = new StackHashCabCollection(); for (int i = 0; i < numCabs; i++) { DateTime nowTime = DateTime.Now; DateTime date = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0); StackHashCab cab = new StackHashCab(date.AddDays(i * 1), date.AddDays(i * 2), event1.Id, event1.EventTypeName, "cab12345_23232.cab", cabId++, i * 2000); cab.DumpAnalysis = new StackHashDumpAnalysis("2 days, 5 hours, 2 mins", "1 hour, 2 mins", "2.120.222.1121212", "Microsoft Windows Vista X64 6.0.212121212 (Build 2500)", "64 bit windows"); cab.CabDownloaded = false; cabs.Add(cab); m_Index.AddCab(product1, file1, event1, cab, true); } allAddedEvents.Add(new StackHashEventPackage(eventInfos, new StackHashCabPackageCollection(cabs), event1, product1.Id)); } } expectedProductEvents[product1.Id] = allAddedEvents; } foreach (StackHashProduct product in allProducts) { StackHashEventPackageCollection allEvents = m_Index.GetProductEvents(product); StackHashEventPackageCollection expectedEvents = expectedProductEvents[product.Id]; Assert.AreNotEqual(null, allEvents); Assert.AreEqual(expectedEvents.Count, allEvents.Count); foreach (StackHashEventPackage package in allEvents) { StackHashEventPackage matchedEvent = expectedEvents.FindEventPackage(package.EventData.Id, package.EventData.EventTypeName); Assert.AreNotEqual(null, matchedEvent); Assert.AreEqual(0, package.EventInfoList.CompareTo(matchedEvent.EventInfoList)); Assert.AreEqual(0, package.Cabs.CompareTo(matchedEvent.Cabs)); } } }