// // 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> /// Adds the rollup of hitDates. /// </summary> public void addHitDateSummaries(int numHitDateSummaries) { // Create a clean index. m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); DateTime hitDateBase = DateTime.Now.RoundToNextSecond(); int productId = 1234; // Check a hitDate that doesn't exist. Assert.AreEqual(false, m_Index.HitDateSummaryExists(productId, DateTime.Now)); StackHashProductHitDateSummaryCollection allHitDateSummaries = new StackHashProductHitDateSummaryCollection(); for (int hitDateCount = 0; hitDateCount < numHitDateSummaries; hitDateCount++) { int totalHits = hitDateCount + 1; DateTime hitDate = hitDateBase.AddDays(hitDateCount); m_Index.AddHitDateSummary(productId, hitDate, totalHits, false); // Check the hitDate exists now. Assert.AreEqual(true, m_Index.HitDateSummaryExists(productId, hitDate)); // Get the specific hitDate and make sure it was stored properly. StackHashProductHitDateSummary summary = m_Index.GetHitDateSummaryForProduct(productId, hitDate); Assert.AreEqual(hitDate, summary.HitDate.ToLocalTime()); Assert.AreEqual(totalHits, summary.TotalHits); allHitDateSummaries.Add(summary); } StackHashProductHitDateSummaryCollection hitDateSummaryCollection = m_Index.GetHitDateSummaries(productId); Assert.AreEqual(numHitDateSummaries, hitDateSummaryCollection.Count); foreach (StackHashProductHitDateSummary hitDateData in hitDateSummaryCollection) { // Find the matching hitDate in the expected list. StackHashProductHitDateSummary expectedSummary = allHitDateSummaries.FindHitDate(hitDateData.HitDate); Assert.AreNotEqual(null, expectedSummary); Assert.AreEqual(0, expectedSummary.CompareTo(hitDateData)); } }
public void UpdateHitSummaries(StackHashProductHitDateSummaryCollection hitDateSummary, StackHashProductLocaleSummaryCollection localeSummary, StackHashProductOperatingSystemSummaryCollection osSummary) { if (hitDateSummary != _hitDateSummary) { _hitDateSummary = hitDateSummary; RaisePropertyChanged("HitDateSummary"); } if (localeSummary != _localeSummary) { _localeSummary = localeSummary; RaisePropertyChanged("LocaleSummary"); } if (osSummary != _osSummary) { _osSummary = osSummary; RaisePropertyChanged("OsSummary"); } }
/// <summary> /// Gets the rollup of hit dates. /// </summary> public void getHitDateRollup(int numEventInfos, int hitDateModulo) { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); 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, "TestProduct1", 20, 30, "2.10.02123.1293"); StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, 20, 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(); StackHashEvent event1 = new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName1", 100, eventSignature, 20, file1.Id, "bug"); m_Index.AddProduct(product1); m_Index.AddFile(product1, file1); m_Index.AddEvent(product1, file1, event1); StackHashEventInfoCollection eventInfos = new StackHashEventInfoCollection(); int hitCount = 1; int totalHits = 0; String localeCodeBase = "US"; String languageNameBase = "ENGLISH"; String osBase = "Vista"; DateTime nowTime = DateTime.Now; DateTime date = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0); for (int i = 0; i < numEventInfos; i++) { DateTime hitDate = date.AddDays(i % hitDateModulo); totalHits += hitCount; int localeId = i; int osId = i; int hits = (i % hitDateModulo); StackHashEventInfo eventInfo = new StackHashEventInfo(creationDateTime, modifiedDateTime, hitDate, languageNameBase + localeId.ToString(), localeId, localeCodeBase + localeId.ToString(), osBase + osId.ToString(), osId.ToString(), hits); eventInfos.Add(eventInfo); } m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos); StackHashProductHitDateSummaryCollection hitDateSummary = m_Index.GetHitDateSummary(product1.Id); StackHashProductHitDateSummaryCollection hitDateSummaryFresh = m_Index.GetHitDateSummaryFresh(product1.Id); Assert.AreEqual(0, hitDateSummary.CompareTo(hitDateSummaryFresh)); Dictionary <DateTime, StackHashProductHitDateSummary> hitDateCheckList = new Dictionary <DateTime, StackHashProductHitDateSummary>(); if (hitDateModulo < numEventInfos) { Assert.AreEqual(hitDateModulo, hitDateSummary.Count); } else { Assert.AreEqual(numEventInfos, hitDateSummary.Count); } int dateCount = 0; foreach (StackHashProductHitDateSummary hitData in hitDateSummary) { int expectedDateAdjust = dateCount % hitDateModulo; if (hitDateModulo >= numEventInfos) { Assert.AreEqual(dateCount, hitData.TotalHits); } else { Assert.AreEqual(expectedDateAdjust * ((numEventInfos / hitDateModulo)), hitData.TotalHits); } Assert.AreEqual(false, hitDateCheckList.ContainsKey(hitData.HitDate)); hitDateCheckList.Add(hitData.HitDate, hitData); dateCount++; } // Update the stats fresh. m_Index.UpdateProductStatistics(product1.Id); StackHashProductHitDateSummaryCollection hitDateSummary2 = m_Index.GetHitDateSummary(product1.Id); Assert.AreEqual(0, hitDateSummary.CompareTo(hitDateSummary2)); }