public void GetFilesForProduct2FilesOnly1ForSelectedProduct() { 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"); StackHashProduct product2 = new StackHashProduct(creationDateTime, modifiedDateTime, null, 2, "TestProduct1", 21, 31, "2.10.02123.1293"); StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, 20, creationDateTime, "File1.dll", "2.3.4.5"); StackHashFile file2 = new StackHashFile(creationDateTime, modifiedDateTime, 21, creationDateTime, "File2.dll", "2.3.4.5"); m_Index.AddProduct(product1); m_Index.AddProduct(product2); m_Index.AddFile(product1, file1); m_Index.AddFile(product2, file2); StackHashFileCollection files = m_Index.LoadFileList(product1); Assert.AreNotEqual(null, files); Assert.AreEqual(1, files.Count); Assert.AreEqual(0, file1.CompareTo(files[0])); files = m_Index.LoadFileList(product2); Assert.AreNotEqual(null, files); Assert.AreEqual(1, files.Count); Assert.AreEqual(0, file2.CompareTo(files[0])); }
public void ProductControlDataSetGet2Products() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); int productId1 = 1000; int productId2 = 2000; DateTime testDate = new DateTime(2010, 08, 10, 10, 30, 40, DateTimeKind.Utc); m_Index.SetLastHitTimeLocal(productId1, testDate); m_Index.SetLastSyncCompletedTimeLocal(productId1, testDate.AddDays(1)); m_Index.SetLastSyncStartedTimeLocal(productId1, testDate.AddDays(2)); m_Index.SetLastSyncTimeLocal(productId1, testDate.AddDays(3)); m_Index.SetLastHitTimeLocal(productId2, testDate.AddDays(4)); m_Index.SetLastSyncCompletedTimeLocal(productId2, testDate.AddDays(5)); m_Index.SetLastSyncStartedTimeLocal(productId2, testDate.AddDays(6)); m_Index.SetLastSyncTimeLocal(productId2, testDate.AddDays(7)); Assert.AreEqual(testDate, m_Index.GetLastHitTimeLocal(productId1)); Assert.AreEqual(testDate.AddDays(1), m_Index.GetLastSyncCompletedTimeLocal(productId1)); Assert.AreEqual(testDate.AddDays(2), m_Index.GetLastSyncStartedTimeLocal(productId1)); Assert.AreEqual(testDate.AddDays(3), m_Index.GetLastSyncTimeLocal(productId1)); Assert.AreEqual(testDate.AddDays(4), m_Index.GetLastHitTimeLocal(productId2)); Assert.AreEqual(testDate.AddDays(5), m_Index.GetLastSyncCompletedTimeLocal(productId2)); Assert.AreEqual(testDate.AddDays(6), m_Index.GetLastSyncStartedTimeLocal(productId2)); Assert.AreEqual(testDate.AddDays(7), m_Index.GetLastSyncTimeLocal(productId2)); }
public void UpdateFile() { 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"); m_Index.AddProduct(product1); m_Index.AddFile(product1, file1); StackHashFile dbFile1 = m_Index.GetFile(product1, file1.Id); Assert.AreEqual(0, file1.CompareTo(dbFile1)); StackHashFile file2 = new StackHashFile(creationDateTime.AddDays(1), modifiedDateTime.AddDays(2), 20, creationDateTime.AddDays(3), "File2.dll", "1.3.4.5"); m_Index.AddFile(product1, file2); StackHashFile dbFile2 = m_Index.GetFile(product1, file2.Id); Assert.AreEqual(0, file2.CompareTo(dbFile2)); Assert.AreNotEqual(0, file1.CompareTo(dbFile2)); }
// // 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 specified number of Mappings to the MappingsTable. /// </summary> public void addMappings(StackHashMappingType mappingType, StackHashMappingCollection mappings, int expectedCount) { // Create a clean index. m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); StackHashMappingCollection currentMappings = m_Index.GetMappings(mappingType); if (mappingType == StackHashMappingType.WorkFlow) { Assert.AreEqual(16, currentMappings.Count); } else { Assert.AreEqual(0, currentMappings.Count); } m_Index.AddMappings(mappings); currentMappings = m_Index.GetMappings(mappingType); Assert.AreEqual(expectedCount, currentMappings.Count); foreach (StackHashMapping mapping in mappings) { StackHashMapping matchingMapping = mappings.FindMapping(mapping.MappingType, mapping.Id); Assert.AreNotEqual(null, matchingMapping); Assert.AreEqual(0, mapping.CompareTo(matchingMapping)); } }
public void filesCount(int numFiles) { 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"); m_Index.AddProduct(product1); for (int i = 0; i < numFiles; i++) { StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, 20 + i, creationDateTime, "File1.dll", "2.3.4.5"); m_Index.AddFile(product1, file1); } long filesCount = m_Index.TotalFiles; Assert.AreEqual(numFiles, filesCount); }
public void AddProductDisconnectReconnectGetProducts() { 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 product = new StackHashProduct(creationDateTime, modifiedDateTime, "www.files.com", 25, @"P""r:o?d:u@(XP_2k)", 0, 0, "1:2:3:4"); m_Index.AddProduct(product); Assert.AreEqual(1, m_Index.TotalProducts); Assert.AreEqual(true, m_Index.ProductExists(product)); m_Index.Deactivate(); m_Index.Dispose(); m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.Activate(); StackHashProductCollection products = m_Index.LoadProductList(); Assert.AreEqual(1, products.Count); Assert.AreEqual(1, m_Index.TotalProducts); Assert.AreEqual(true, m_Index.ProductExists(product)); }
public void GetSetSyncProgressReload() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); StackHashSyncProgress syncProgress = new StackHashSyncProgress(1, 2, 3, "EventTypeName", 4, StackHashSyncPhase.Events); m_Index.SyncProgress = syncProgress; StackHashSyncProgress newProgress = m_Index.SyncProgress; Assert.AreEqual(0, newProgress.CompareTo(syncProgress)); m_Index.Deactivate(); m_Index.Dispose(); // Load again to make sure the data was persisted. m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.Activate(); newProgress = m_Index.SyncProgress; Assert.AreEqual(0, newProgress.CompareTo(syncProgress)); }
public void FileExistsForDifferentProduct() { 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"); StackHashProduct product2 = new StackHashProduct(creationDateTime, modifiedDateTime, null, 2, "TestProduct1", 21, 31, "2.10.02123.1293"); StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, 20, creationDateTime, "File1.dll", "2.3.4.5"); m_Index.AddProduct(product1); m_Index.AddProduct(product2); m_Index.AddFile(product1, file1); StackHashFile dbFile1 = m_Index.GetFile(product1, file1.Id); Assert.AreEqual(0, file1.CompareTo(dbFile1)); Assert.AreEqual(true, m_Index.FileExists(product1, file1)); Assert.AreEqual(false, m_Index.FileExists(product2, file1)); }
public void GetProductEvents20Products5Files3EventsSql() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); getProductEvents(m_Index, 20, 5, 3); }
public void UpdateProductStatsIndex10Files100EventsSql() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); updateProductStatsNoEvents(m_Index, 1, 10, 100); }
public void GetSetSyncCount() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); Assert.AreEqual(0, m_Index.SyncCount); m_Index.SyncCount = 1; Assert.AreEqual(1, m_Index.SyncCount); }
/// <summary> /// Checks for localeCode and localeName accepted ok. /// </summary> public void addMultipleLocales(StackHashProductLocaleSummaryCollection localesToAdd) { // Create a clean index. m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); int productId = 1234; // Check a locale that doesn't exist. Assert.AreEqual(false, m_Index.LocaleSummaryExists(1245, 12121)); StackHashProductLocaleSummaryCollection allLocaleSummaries = new StackHashProductLocaleSummaryCollection(); foreach (StackHashProductLocaleSummary locale in localesToAdd) { m_Index.AddLocale(locale.Lcid, locale.Locale, locale.Language); m_Index.AddLocaleSummary(productId, locale.Lcid, locale.TotalHits, false); // Check the locale exists now. Assert.AreEqual(true, m_Index.LocaleSummaryExists(productId, locale.Lcid)); // Get the specific locale and make sure it was stored properly. StackHashProductLocaleSummary summary = m_Index.GetLocaleSummaryForProduct(productId, locale.Lcid); Assert.AreEqual(locale.Lcid, summary.Lcid); Assert.AreEqual(locale.Locale, summary.Locale); Assert.AreEqual(locale.Language, summary.Language); Assert.AreEqual(locale.TotalHits, summary.TotalHits); } StackHashProductLocaleSummaryCollection localeSummaryCollection = m_Index.GetLocaleSummaries(productId); Assert.AreEqual(localesToAdd.Count, localeSummaryCollection.Count); foreach (StackHashProductLocaleSummary loadedLocale in localeSummaryCollection) { StackHashProductLocaleSummary expectedSummary = localesToAdd.FindLocale(loadedLocale.Lcid); Assert.AreEqual(0, expectedSummary.CompareTo(loadedLocale)); } // Now update the statistics again using the same values. m_Index.UpdateLocaleStatistics(productId, localesToAdd, false); // Values should have doubled. localeSummaryCollection = m_Index.GetLocaleSummaries(productId); Assert.AreEqual(localesToAdd.Count, localeSummaryCollection.Count); foreach (StackHashProductLocaleSummary loadedLocale in localeSummaryCollection) { StackHashProductLocaleSummary expectedSummary = localesToAdd.FindLocale(loadedLocale.Lcid); expectedSummary.TotalHits *= 2; Assert.AreEqual(0, expectedSummary.CompareTo(loadedLocale)); } }
/// <summary> /// Adds the specified number of Updates to the UpdateTable and then CLEARS them. /// </summary> public void addAndClearAllUpdates(int numUpdates, bool incrementIds) { // Create a clean index. m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); m_Index.UpdateTableActive = true; int productId = 11111111; int fileId = 22222222; int eventId = 33333333; String eventTypeName = "EventTypeName"; int componentId = 44444444; // Check that no update exists. StackHashBugTrackerUpdate update = m_Index.GetFirstUpdate(); Assert.AreEqual(null, update); List <StackHashBugTrackerUpdate> allUpdates = new List <StackHashBugTrackerUpdate>(); for (int updateCount = 0; updateCount < numUpdates; updateCount++) { StackHashBugTrackerUpdate newUpdate = new StackHashBugTrackerUpdate() { EntryId = updateCount + 1, // This will be the expected entryid - this is an automatic update field in the database. DateChanged = DateTime.Now.RoundToNextSecond(), // Database dates are not as accurate as .NET dates. DataThatChanged = StackHashDataChanged.Event, TypeOfChange = StackHashChangeType.NewEntry, ProductId = productId, FileId = fileId, EventId = eventId, EventTypeName = eventTypeName, ChangedObjectId = componentId, }; if (incrementIds) { productId++; fileId++; eventId++; componentId++; } m_Index.AddUpdate(newUpdate); allUpdates.Add(newUpdate); } m_Index.ClearAllUpdates(); Assert.AreEqual(null, m_Index.GetFirstUpdate()); }
/// <summary> /// Checks for OS name and version nulls. /// </summary> public void addMultipleOperatingSystems(StackHashProductOperatingSystemSummaryCollection operatingSystemsToAdd) { // Create a clean index. m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); int productId = 1234; StackHashProductOperatingSystemSummaryCollection allOSSummaries = new StackHashProductOperatingSystemSummaryCollection(); foreach (StackHashProductOperatingSystemSummary operatingSystem in operatingSystemsToAdd) { m_Index.AddOperatingSystem(operatingSystem.OperatingSystemName, operatingSystem.OperatingSystemVersion); short osId = m_Index.GetOperatingSystemId(operatingSystem.OperatingSystemName, operatingSystem.OperatingSystemVersion); m_Index.AddOperatingSystemSummary(productId, osId, operatingSystem.TotalHits, false); // Check the OS exists now. Assert.AreEqual(true, m_Index.OperatingSystemSummaryExists(productId, operatingSystem.OperatingSystemName, operatingSystem.OperatingSystemVersion)); // Get the specific OS and make sure it was stored properly. StackHashProductOperatingSystemSummary summary = m_Index.GetOperatingSystemSummaryForProduct(productId, operatingSystem.OperatingSystemName, operatingSystem.OperatingSystemVersion); Assert.AreEqual(operatingSystem.OperatingSystemName, summary.OperatingSystemName); Assert.AreEqual(operatingSystem.OperatingSystemVersion, summary.OperatingSystemVersion); } StackHashProductOperatingSystemSummaryCollection osSummaryCollection = m_Index.GetOperatingSystemSummaries(productId); Assert.AreEqual(operatingSystemsToAdd.Count, osSummaryCollection.Count); foreach (StackHashProductOperatingSystemSummary os in osSummaryCollection) { StackHashProductOperatingSystemSummary expectedSummary = operatingSystemsToAdd.FindOperatingSystem(os.OperatingSystemName, os.OperatingSystemVersion); Assert.AreEqual(0, expectedSummary.CompareTo(os)); } // Now update the statistics again using the same values. m_Index.UpdateOperatingSystemStatistics(productId, operatingSystemsToAdd, false); osSummaryCollection = m_Index.GetOperatingSystemSummaries(productId); Assert.AreEqual(operatingSystemsToAdd.Count, osSummaryCollection.Count); foreach (StackHashProductOperatingSystemSummary os in osSummaryCollection) { StackHashProductOperatingSystemSummary expectedSummary = operatingSystemsToAdd.FindOperatingSystem(os.OperatingSystemName, os.OperatingSystemVersion); expectedSummary.TotalHits *= 2; Assert.AreEqual(0, expectedSummary.CompareTo(os)); } // Now update the statistics again using the same values. m_Index.UpdateOperatingSystemStatistics(productId, operatingSystemsToAdd, false); }
// // 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 OperatingSystems. /// </summary> public void addOperatingSystemSummaries(int numOperatingSystemSummaries) { // Create a clean index. m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); String operatingSystemNameBase = "Microsoft Windows Vista"; String operatingSystemVersionBase = "6.0.0.1212.0"; int productId = 1234; // Check an OperatingSystem that doesn't exist. Assert.AreEqual(false, m_Index.OperatingSystemSummaryExists(productId, operatingSystemNameBase, operatingSystemVersionBase)); StackHashProductOperatingSystemSummaryCollection allOperatingSystemSummaries = new StackHashProductOperatingSystemSummaryCollection(); for (int operatingSystemCount = 0; operatingSystemCount < numOperatingSystemSummaries; operatingSystemCount++) { String operatingSystemName = operatingSystemNameBase + operatingSystemCount.ToString(); String operatingSystemVersion = operatingSystemVersionBase + operatingSystemCount.ToString(); int totalHits = operatingSystemCount + 1; m_Index.AddOperatingSystem(operatingSystemName, operatingSystemVersion); short operatingSystemId = m_Index.GetOperatingSystemId(operatingSystemName, operatingSystemVersion); m_Index.AddOperatingSystemSummary(productId, operatingSystemId, totalHits, false); // Check the OperatingSystem exists now. Assert.AreEqual(true, m_Index.OperatingSystemSummaryExists(productId, operatingSystemName, operatingSystemVersion)); // Get the specific OperatingSystem and make sure it was stored properly. StackHashProductOperatingSystemSummary summary = m_Index.GetOperatingSystemSummaryForProduct(productId, operatingSystemName, operatingSystemVersion); Assert.AreEqual(operatingSystemName, summary.OperatingSystemName); Assert.AreEqual(operatingSystemVersion, summary.OperatingSystemVersion); Assert.AreEqual(totalHits, summary.TotalHits); allOperatingSystemSummaries.Add(summary); } StackHashProductOperatingSystemSummaryCollection operatingSystemSummaryCollection = m_Index.GetOperatingSystemSummaries(productId); Assert.AreEqual(numOperatingSystemSummaries, operatingSystemSummaryCollection.Count); foreach (StackHashProductOperatingSystemSummary operatingSystemData in operatingSystemSummaryCollection) { // Find the matching OperatingSystem in the expected list. StackHashProductOperatingSystemSummary expectedSummary = allOperatingSystemSummaries.FindOperatingSystem(operatingSystemData.OperatingSystemName, operatingSystemData.OperatingSystemVersion); Assert.AreNotEqual(null, expectedSummary); Assert.AreEqual(0, expectedSummary.CompareTo(operatingSystemData)); } }
public void ProductControlDataGetDefault() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); int productId = 1000; Assert.AreEqual(new DateTime(0), m_Index.GetLastHitTimeLocal(productId)); Assert.AreEqual(new DateTime(0), m_Index.GetLastSyncCompletedTimeLocal(productId)); Assert.AreEqual(new DateTime(0), m_Index.GetLastSyncStartedTimeLocal(productId)); Assert.AreEqual(new DateTime(0), m_Index.GetLastSyncTimeLocal(productId)); }
/// <summary> /// Checks for localeCode and localeName accepted ok. /// </summary> public void addSingleLocale(int localeId, String localeCode, String localeName) { // Create a clean index. m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); int productId = 1234; // Check a locale that doesn't exist. Assert.AreEqual(false, m_Index.LocaleSummaryExists(1245, 12121)); StackHashProductLocaleSummaryCollection allLocaleSummaries = new StackHashProductLocaleSummaryCollection(); int totalHits = 100; m_Index.AddLocale(localeId, localeCode, localeName); m_Index.AddLocaleSummary(productId, localeId, totalHits, false); // Check the locale exists now. Assert.AreEqual(true, m_Index.LocaleSummaryExists(productId, localeId)); // Get the specific locale and make sure it was stored properly. StackHashProductLocaleSummary summary = m_Index.GetLocaleSummaryForProduct(productId, localeId); Assert.AreEqual(localeId, summary.Lcid); Assert.AreEqual(localeCode, summary.Locale); Assert.AreEqual(localeName, summary.Language); Assert.AreEqual(totalHits, summary.TotalHits); StackHashProductLocaleSummaryCollection localeSummaryCollection = m_Index.GetLocaleSummaries(productId); Assert.AreEqual(1, localeSummaryCollection.Count); StackHashProductLocaleSummary expectedSummary = new StackHashProductLocaleSummary(localeName, localeId, localeCode, totalHits); Assert.AreEqual(0, expectedSummary.CompareTo(localeSummaryCollection[0])); // Now update the statistics again using the same values. allLocaleSummaries.Add(expectedSummary); m_Index.UpdateLocaleStatistics(productId, allLocaleSummaries, false); // Values should have doubled. localeSummaryCollection = m_Index.GetLocaleSummaries(productId); Assert.AreEqual(1, localeSummaryCollection.Count); expectedSummary = new StackHashProductLocaleSummary(localeName, localeId, localeCode, totalHits * 2); Assert.AreEqual(0, expectedSummary.CompareTo(localeSummaryCollection[0])); }
// // 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> /// Gets the rollup of locales. /// </summary> public void addLocaleSummaries(int numLocaleSummaries) { // Create a clean index. m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); String localeCodeBase = "US-"; String localeNameBase = "ENGLISH"; int productId = 1234; // Check a locale that doesn't exist. Assert.AreEqual(false, m_Index.LocaleSummaryExists(1245, 12121)); StackHashProductLocaleSummaryCollection allLocaleSummaries = new StackHashProductLocaleSummaryCollection(); for (int localeCount = 0; localeCount < numLocaleSummaries; localeCount++) { int localeId = 1000 + localeCount; int totalHits = localeCount + 1; m_Index.AddLocale(localeId, localeCodeBase + localeId.ToString(), localeNameBase + localeId.ToString()); m_Index.AddLocaleSummary(productId, localeId, totalHits, false); // Check the locale exists now. Assert.AreEqual(true, m_Index.LocaleSummaryExists(productId, localeId)); // Get the specific locale and make sure it was stored properly. StackHashProductLocaleSummary summary = m_Index.GetLocaleSummaryForProduct(productId, localeId); Assert.AreEqual(localeId, summary.Lcid); Assert.AreEqual(localeCodeBase + localeId.ToString(), summary.Locale); Assert.AreEqual(localeNameBase + localeId.ToString(), summary.Language); Assert.AreEqual(totalHits, summary.TotalHits); allLocaleSummaries.Add(summary); } StackHashProductLocaleSummaryCollection localeSummaryCollection = m_Index.GetLocaleSummaries(productId); Assert.AreEqual(numLocaleSummaries, localeSummaryCollection.Count); foreach (StackHashProductLocaleSummary localeData in localeSummaryCollection) { // Find the matching locale in the expected list. StackHashProductLocaleSummary expectedSummary = allLocaleSummaries.FindLocale(localeData.Lcid); Assert.AreNotEqual(null, expectedSummary); Assert.AreEqual(0, expectedSummary.CompareTo(localeData)); } }
public void GetSetSyncProgress() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); StackHashSyncProgress syncProgress = new StackHashSyncProgress(1, 2, 3, "EventTypeName", 4, StackHashSyncPhase.Events); m_Index.SyncProgress = syncProgress; StackHashSyncProgress newProgress = m_Index.SyncProgress; Assert.AreEqual(0, newProgress.CompareTo(syncProgress)); }
public void ControlDataGetDefault() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); Assert.AreEqual(0, m_Index.SyncCount); Assert.AreNotEqual(null, m_Index.SyncProgress); Assert.AreEqual(0, m_Index.SyncProgress.ProductId); Assert.AreEqual(0, m_Index.SyncProgress.FileId); Assert.AreEqual(0, m_Index.SyncProgress.EventId); Assert.AreEqual(0, m_Index.SyncProgress.CabId); Assert.AreEqual(null, m_Index.SyncProgress.EventTypeName); }
// // 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 AddFileNullProduct() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); try { m_Index.Activate(); StackHashFile file = new StackHashFile(); m_Index.AddFile(null, file); } catch (ArgumentNullException ex) { Assert.AreEqual("product", ex.ParamName); throw; } }
public void DatabaseExistsOk() { String cabFolder = m_RootCabFolder; String databaseName = "TestIndex"; StackHashSqlConfiguration sqlConfig = StackHashSqlConfiguration.Default; sqlConfig.ConnectionTimeout = 10; m_Index = new SqlErrorIndex(sqlConfig, databaseName, cabFolder); m_Index.Activate(true, false); // Allow database to be created. ErrorIndexConnectionTestResults result = m_Index.GetDatabaseStatus(); Assert.AreNotEqual(null, result); Assert.AreEqual(StackHashErrorIndexDatabaseStatus.Success, result.Result); Assert.AreEqual(null, result.LastException); }
public void GetTaskControlDataDefault() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); StackHashTaskStatus controlData = m_Index.GetTaskStatistics(StackHashTaskType.DummyTask); Assert.AreEqual(0, controlData.FailedCount); Assert.AreEqual(0, controlData.LastDurationInSeconds); Assert.AreEqual(null, controlData.LastException); Assert.AreEqual(new DateTime(0), controlData.LastFailedRunTimeUtc); Assert.AreEqual(new DateTime(0), controlData.LastStartedTimeUtc); Assert.AreEqual(new DateTime(0), controlData.LastSuccessfulRunTimeUtc); Assert.AreEqual(0, controlData.RunCount); Assert.AreEqual(StackHashServiceErrorCode.NoError, controlData.ServiceErrorCode); Assert.AreEqual(0, controlData.SuccessCount); Assert.AreEqual(StackHashTaskState.NotRunning, controlData.TaskState); Assert.AreEqual(StackHashTaskType.DummyTask, controlData.TaskType); }
public void GetSetSyncProgressNTimes() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); int numTimes = 100; Random rand = new Random(1); for (int i = 0; i < numTimes; i++) { StackHashSyncPhase phase = (StackHashSyncPhase)rand.Next(0, 4); StackHashSyncProgress syncProgress = new StackHashSyncProgress(1 + i, 2 + i, 3 + i, "EventTypeName" + i.ToString(), 4 + i, phase); m_Index.SyncProgress = syncProgress; StackHashSyncProgress newProgress = m_Index.SyncProgress; Assert.AreEqual(0, newProgress.CompareTo(syncProgress)); } }
public void SetTaskControlDataNullValues() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); DateTime testDate = new DateTime(0); StackHashTaskStatus setControlData = new StackHashTaskStatus(); setControlData.TaskType = StackHashTaskType.DummyTask; setControlData.FailedCount = 0; setControlData.LastDurationInSeconds = 0; setControlData.LastFailedRunTimeUtc = testDate; setControlData.LastStartedTimeUtc = testDate; setControlData.LastSuccessfulRunTimeUtc = testDate; setControlData.LastException = null; setControlData.RunCount = 0; setControlData.ServiceErrorCode = StackHashServiceErrorCode.NoLicense; setControlData.SuccessCount = 0; setControlData.TaskState = StackHashTaskState.Queued; m_Index.SetTaskStatistics(setControlData); StackHashTaskStatus controlData = m_Index.GetTaskStatistics(StackHashTaskType.DummyTask); Assert.AreEqual(setControlData.FailedCount, controlData.FailedCount); Assert.AreEqual(setControlData.LastDurationInSeconds, controlData.LastDurationInSeconds); Assert.AreEqual(setControlData.LastException, controlData.LastException); Assert.AreEqual(setControlData.LastFailedRunTimeUtc, controlData.LastFailedRunTimeUtc); Assert.AreEqual(setControlData.LastStartedTimeUtc, controlData.LastStartedTimeUtc); Assert.AreEqual(setControlData.LastSuccessfulRunTimeUtc, controlData.LastSuccessfulRunTimeUtc); Assert.AreEqual(setControlData.RunCount, controlData.RunCount); Assert.AreEqual(setControlData.ServiceErrorCode, controlData.ServiceErrorCode); Assert.AreEqual(setControlData.SuccessCount, controlData.SuccessCount); Assert.AreEqual(setControlData.TaskState, controlData.TaskState); Assert.AreEqual(setControlData.TaskType, controlData.TaskType); }
public void AddFileNullFile() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); try { 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"); m_Index.AddProduct(product1); m_Index.AddFile(product1, null); } catch (ArgumentNullException ex) { Assert.AreEqual("file", ex.ParamName); throw; } }
public void Add100Files() { 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"); int numFiles = 100; m_Index.AddProduct(product1); List <StackHashFile> addedFiles = new List <StackHashFile>(); for (int i = 0; i < numFiles; i++) { StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, 20 + i, creationDateTime, "File1.dll", "2.3.4.5"); m_Index.AddFile(product1, file1); addedFiles.Add(file1); StackHashFileCollection files = m_Index.LoadFileList(product1); Assert.AreNotEqual(null, files); Assert.AreEqual(i + 1, files.Count); for (int j = 0; j < i; j++) { Assert.AreEqual(0, addedFiles[j].CompareTo(files[j])); } } }
public void MergeWithDuplicatesInNewList() { 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 eventInfos1 = new StackHashEventInfoCollection(); StackHashEventInfoCollection eventInfos2 = new StackHashEventInfoCollection(); DateTime nowTime = DateTime.Now; DateTime date = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0); int localeId = 123; // These events just different by num hits. StackHashEventInfo eventInfo1 = new StackHashEventInfo(date, date, date, "US", localeId, "English", "Windows Vista", "1.2.3.4 build 7", 100); StackHashEventInfo eventInfo2 = new StackHashEventInfo(date, date, date, "US", localeId, "English", "Windows Vista", "1.2.3.4 build 7", 101); StackHashEventInfo expectedEventInfo = (StackHashEventInfo)eventInfo1.Clone(); expectedEventInfo.TotalHits = eventInfo1.TotalHits + eventInfo2.TotalHits; eventInfos1.Add(eventInfo1); eventInfos1.Add(eventInfo2); m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos1); StackHashEventInfoCollection eventInfosRetrieved = m_Index.LoadEventInfoList(product1, file1, event1); Assert.AreEqual(1, eventInfosRetrieved.Count); Assert.AreEqual(0, expectedEventInfo.CompareTo(eventInfosRetrieved[0])); }
public void GetMostRecentHitDateDuplicateEventIds() { 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"); StackHashEvent event2 = new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName2", 100, eventSignature, 20, file1.Id, "bug"); m_Index.AddProduct(product1); m_Index.AddFile(product1, file1); m_Index.AddEvent(product1, file1, event1); m_Index.AddEvent(product1, file1, event2); StackHashEventInfoCollection eventInfos1 = new StackHashEventInfoCollection(); int numEventInfos = 3; 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 = i; StackHashEventInfo eventInfo = new StackHashEventInfo(date.AddDays(i + 2), date.AddDays(i + 1), date.AddDays(i), "US", localeId, "English", "Windows Vista" + i.ToString(), "1.2.3.4 build 7", event1.Id); eventInfos1.Add(eventInfo); } m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos1); StackHashEventInfoCollection eventInfos2 = new StackHashEventInfoCollection(); // Add some other event infos for a different event. 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 = i; StackHashEventInfo eventInfo = new StackHashEventInfo(date.AddDays(i + 2), date.AddDays(i + 1), date.AddDays(i * 2), "US", localeId, "English", "Windows Vista" + i.ToString(), "1.2.3.4 build 7", event2.Id); eventInfos2.Add(eventInfo); } m_Index.AddEventInfoCollection(product1, file1, event2, eventInfos2); StackHashEventInfoCollection eventInfosRetrieved = m_Index.LoadEventInfoList(product1, file1, event1); Assert.AreEqual(numEventInfos, eventInfosRetrieved.Count); for (int i = 0; i < numEventInfos; i++) { StackHashEventInfo eventInfo = eventInfosRetrieved.FindEventInfo(eventInfos1[i]); Assert.AreEqual(0, eventInfos1[i].CompareTo(eventInfo)); } DateTime mostRecentHitDate = m_Index.GetMostRecentHitDate(product1, file1, event1); Assert.AreEqual(eventInfos1[numEventInfos - 1].HitDateLocal, mostRecentHitDate); Assert.AreNotEqual(eventInfos1[0].HitDateLocal, mostRecentHitDate); Assert.AreNotEqual(eventInfos1[1].HitDateLocal, mostRecentHitDate); DateTime mostRecentHitDate2 = m_Index.GetMostRecentHitDate(product1, file1, event2); Assert.AreEqual(eventInfos2[numEventInfos - 1].HitDateLocal, mostRecentHitDate2); Assert.AreNotEqual(eventInfos2[0].HitDateLocal, mostRecentHitDate2); Assert.AreNotEqual(eventInfos2[1].HitDateLocal, mostRecentHitDate2); }