public void MoveErrorIndexBeforeCreation() { m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); CreateNewStackHashContextResponse newContextResp = m_Utils.CreateNewContext(); Assert.AreEqual(ErrorIndexStatus.NotCreated, newContextResp.Settings.ErrorIndexSettings.Status); String originalIndexPath = newContextResp.Settings.ErrorIndexSettings.Folder; Assert.AreEqual(false, Directory.Exists(originalIndexPath)); String testPath = "c:\\stackhashunittests\\testindex\\"; String indexName = "ShouldNeverExist"; m_Utils.MoveIndex(0, testPath, indexName, 10000, newContextResp.Settings.SqlSettings); // Read them back and make sure they have changed. GetStackHashPropertiesResponse resp = m_Utils.GetContextSettings(); Assert.AreEqual(1, resp.Settings.ContextCollection.Count); Assert.AreEqual(false, resp.Settings.ContextCollection[0].IsActive); Assert.AreEqual(testPath.ToUpperInvariant(), resp.Settings.ContextCollection[0].ErrorIndexSettings.Folder.ToUpperInvariant()); Assert.AreEqual(indexName.ToUpperInvariant(), resp.Settings.ContextCollection[0].ErrorIndexSettings.Name.ToUpperInvariant()); Assert.AreEqual(ErrorIndexStatus.NotCreated, newContextResp.Settings.ErrorIndexSettings.Status); Assert.AreEqual(false, Directory.Exists(Path.Combine(testPath, indexName))); }
// // 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 public GetWindowedEventPackageResponse windowSearch(ErrorIndexType errorIndexType, StackHashTestIndexData testIndexData, StackHashSearchCriteriaCollection allSearchCriteria, long startRow, long numRows, StackHashSortOrderCollection sortOrder, StackHashSearchDirection direction, bool countAllMatches) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(errorIndexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; resp.Settings.ErrorIndexSettings.Type = errorIndexType; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); m_Utils.ActivateContext(0); m_Utils.CreateTestIndex(0, testIndexData); try { // Enable all products so that they appear in searchs. StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; foreach (StackHashProductInfo product in products) { m_Utils.SetProductSynchronizationState(0, product.Product.Id, true); } GetWindowedEventPackageResponse eventPackages = m_Utils.GetWindowedEvents(0, allSearchCriteria, startRow, numRows, sortOrder, direction, countAllMatches); return(eventPackages); } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(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 public void getProductSummary(ErrorIndexType indexType, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs, int productId) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = numFiles; testIndexData.NumberOfEvents = numEvents; testIndexData.NumberOfEventInfos = numEventInfos; testIndexData.NumberOfCabs = numCabs; m_Utils.CreateTestIndex(0, testIndexData); GetProductRollupResponse resp2 = m_Utils.GetProductSummary(0, productId); Assert.AreEqual(numFiles * numEvents * numEventInfos, resp2.RollupData.HitDateSummary.Count); Assert.AreEqual(numFiles * numEvents * numEventInfos, resp2.RollupData.LocaleSummaryCollection.Count); Assert.AreEqual(numFiles * numEvents * numEventInfos, resp2.RollupData.OperatingSystemSummary.Count); m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); }
// Set the workflow status. public void setWorkFlowStatus(ErrorIndexType indexType, bool resetService) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = 1; testIndexData.NumberOfFiles = 1; testIndexData.NumberOfEvents = 1; testIndexData.NumberOfEventInfos = 0; testIndexData.NumberOfCabs = 0; m_Utils.CreateTestIndex(0, testIndexData); GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(1, getProductsResp.Products.Count()); GetFilesResponse allFiles = m_Utils.GetFiles(0, getProductsResp.Products[0].Product); Assert.AreEqual(1, allFiles.Files.Count()); GetProductEventPackageResponse allEvents = m_Utils.GetProductEventPackages(0, getProductsResp.Products[0].Product); Assert.AreEqual(1, allEvents.EventPackages.Count()); // Set the workflow status int workFlowStatus = 10; m_Utils.SetWorkFlowStatus(0, getProductsResp.Products[0].Product, allFiles.Files[0], allEvents.EventPackages[0].EventData, workFlowStatus); if (resetService) { m_Utils.RestartService(); } allEvents = m_Utils.GetProductEventPackages(0, getProductsResp.Products[0].Product); Assert.AreEqual(1, allEvents.EventPackages.Count()); Assert.AreEqual(workFlowStatus, allEvents.EventPackages[0].EventData.WorkFlowStatus); Assert.AreEqual("Resolved - Responded", allEvents.EventPackages[0].EventData.WorkFlowStatusName); m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); }
// Set the workflow status. public void getDefaultWorkFlowStatus(ErrorIndexType indexType, bool resetService) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); Assert.AreEqual(null, resp.Settings.WorkFlowMappings); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. // Workflow should still be null. GetStackHashPropertiesResponse getSettingsResp = m_Utils.GetContextSettings(); Assert.AreEqual(null, resp.Settings.WorkFlowMappings); m_Utils.ActivateContext(0); // Workflow should now be set. getSettingsResp = m_Utils.GetContextSettings(); Assert.AreNotEqual(null, getSettingsResp.Settings.ContextCollection[0].WorkFlowMappings); Assert.AreEqual(16, getSettingsResp.Settings.ContextCollection[0].WorkFlowMappings.Count); if (resetService) { m_Utils.RestartService(); } // Workflow should now be set. getSettingsResp = m_Utils.GetContextSettings(); Assert.AreNotEqual(null, getSettingsResp.Settings.ContextCollection[0].WorkFlowMappings); Assert.AreEqual(16, getSettingsResp.Settings.ContextCollection[0].WorkFlowMappings.Count); m_Utils.DeactivateContext(0); // Workflow should still be set when deactivated. getSettingsResp = m_Utils.GetContextSettings(); Assert.AreNotEqual(null, getSettingsResp.Settings.ContextCollection[0].WorkFlowMappings); Assert.AreEqual(16, getSettingsResp.Settings.ContextCollection[0].WorkFlowMappings.Count); m_Utils.DeleteIndex(0); }
// Get the public void getCabPackage(ErrorIndexType indexType) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = 1; testIndexData.NumberOfFiles = 1; testIndexData.NumberOfEvents = 1; testIndexData.NumberOfEventInfos = 0; testIndexData.NumberOfCabs = 1; m_Utils.CreateTestIndex(0, testIndexData); GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(1, getProductsResp.Products.Count()); GetFilesResponse allFiles = m_Utils.GetFiles(0, getProductsResp.Products[0].Product); Assert.AreEqual(1, allFiles.Files.Count()); GetProductEventPackageResponse allEvents = m_Utils.GetProductEventPackages(0, getProductsResp.Products[0].Product); Assert.AreEqual(1, allEvents.EventPackages.Count()); Assert.AreEqual(1, allEvents.EventPackages[0].Cabs.Count); // Get the Cab package. GetCabPackageResponse cabPackageResp = m_Utils.GetCabPackage(0, getProductsResp.Products[0].Product, allFiles.Files[0], allEvents.EventPackages[0].EventData, allEvents.EventPackages[0].Cabs[0].Cab); Assert.AreEqual("c:\\stackhashunittests\\testindex\\TestIndex\\00\\00\\00\\00\\CAB_0000000001\\1-Crash 32bit-0.cab", cabPackageResp.CabPackage.FullPath); }
public void SetIndexSettingsBeforeCreation() { CreateNewStackHashContextResponse newContextResp = m_Utils.CreateNewContext(); Assert.AreEqual(ErrorIndexStatus.NotCreated, newContextResp.Settings.ErrorIndexSettings.Status); String originalIndexPath = newContextResp.Settings.ErrorIndexSettings.Folder; Assert.AreEqual(false, Directory.Exists(originalIndexPath)); String indexName = "ShouldNeverExist"; String testPath = "c:\\stackhashunittests\\testindex\\"; m_Utils.DeleteIndex(0); // Make sure the destination folder does not exist. String fullDestPath = Path.Combine(testPath, indexName); if (Directory.Exists(fullDestPath)) { PathUtils.DeleteDirectory(fullDestPath, true); } newContextResp.Settings.ErrorIndexSettings.Folder = testPath; newContextResp.Settings.ErrorIndexSettings.Name = indexName; m_Utils.SetContextSettings(newContextResp.Settings); // Read them back and make sure they have changed. GetStackHashPropertiesResponse resp = m_Utils.GetContextSettings(); Assert.AreEqual(1, resp.Settings.ContextCollection.Count); Assert.AreEqual(false, resp.Settings.ContextCollection[0].IsActive); Assert.AreEqual(newContextResp.Settings.ErrorIndexSettings.Folder, resp.Settings.ContextCollection[0].ErrorIndexSettings.Folder); Assert.AreEqual(newContextResp.Settings.ErrorIndexSettings.Name, resp.Settings.ContextCollection[0].ErrorIndexSettings.Name); Assert.AreEqual(ErrorIndexStatus.NotCreated, newContextResp.Settings.ErrorIndexSettings.Status); Assert.AreEqual(false, Directory.Exists(Path.Combine(testPath, indexName))); }
// // 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 public void getWindowedEventsByOrder(ErrorIndexType indexType, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs, int windowSize, bool restrictSearchToParticularProduct, bool addLotsOfSearchOptions, List <int> enabledProducts, StackHashSearchDirection direction) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = numFiles; testIndexData.NumberOfEvents = numEvents; testIndexData.NumberOfEventInfos = numEventInfos; testIndexData.NumberOfCabs = numCabs; testIndexData.NumberOfScriptResults = numCabs; m_Utils.CreateTestIndex(0, testIndexData); GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection(); // Just get events for even numbered product ids. for (int productCount = 0; productCount < numProducts; productCount++) { if ((enabledProducts == null) || enabledProducts.Contains(productCount + 1)) { m_Utils.SetProductSynchronizationState(0, productCount + 1, true); } // This doesn't really do anything - just in here so there is at least 1 search option. StackHashSearchCriteria newCriteria = new StackHashSearchCriteria { SearchFieldOptions = new StackHashSearchOptionCollection() { new IntSearchOption { ObjectType = StackHashObjectType.Product, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.Equal, Start = productCount + 1, End = productCount + 1 }, } }; if (addLotsOfSearchOptions) { // Add some "always true" options just to complicate things. newCriteria.SearchFieldOptions.Add(new IntSearchOption { ObjectType = StackHashObjectType.Event, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.RangeExclusive, Start = 0, End = Int32.MaxValue }); newCriteria.SearchFieldOptions.Add(new IntSearchOption { ObjectType = StackHashObjectType.Event, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.RangeInclusive, Start = 0, End = Int32.MaxValue }); newCriteria.SearchFieldOptions.Add(new IntSearchOption { ObjectType = StackHashObjectType.Event, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.GreaterThan, Start = 0, End = 0 }); newCriteria.SearchFieldOptions.Add(new DateTimeSearchOption { ObjectType = StackHashObjectType.EventInfo, FieldName = "DateCreatedLocal", SearchOptionType = StackHashSearchOptionType.RangeExclusive, Start = DateTime.Now.AddYears(-20), End = DateTime.Now.AddYears(20) }); newCriteria.SearchFieldOptions.Add(new DateTimeSearchOption { ObjectType = StackHashObjectType.CabInfo, FieldName = "DateCreatedLocal", SearchOptionType = StackHashSearchOptionType.RangeExclusive, Start = DateTime.Now.AddYears(-20), End = DateTime.Now.AddYears(20) }); } if (restrictSearchToParticularProduct) { if (((productCount + 1) % 2) == 0) { allCriteria.Add(newCriteria); } } else { allCriteria.Add(newCriteria); } } // The events will be returned possibly in event id order from the search. // Set the sort order based on the Offset - ascending - this should return the events // in reverse event ID order as the offsets descend. StackHashSortOrderCollection allSortOrders = new StackHashSortOrderCollection() { new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "Offset", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "DateCreatedLocal", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "DateModifiedLocal", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "EventTypeName", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "Id", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "TotalHits", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "BugId", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ApplicationName", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ApplicationVersion", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ApplicationTimeStamp", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ModuleName", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ModuleVersion", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ModuleTimeStamp", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ExceptionCode", Ascending = true }, }; int totalEventsExpected = numProducts * numFiles * numEvents; List <int> expectedEventIds = new List <int>(); int expectedEventId = 1; for (int productCount = 0; productCount < numProducts; productCount++) { for (int fileCount = 0; fileCount < numFiles; fileCount++) { for (int eventCount = 0; eventCount < numEvents; eventCount++) { // Only add product events for even numbered products. if (restrictSearchToParticularProduct) { if (((productCount + 1) % 2) == 0) { expectedEventIds.Add(expectedEventId++); } else { expectedEventId++; } } else if ((enabledProducts != null) && !enabledProducts.Contains(productCount + 1)) { expectedEventId++; } else { expectedEventIds.Add(expectedEventId++); } } } } expectedEventIds.Reverse(); for (int startRow = 1; startRow <= expectedEventIds.Count; startRow++) { DateTime startTime = DateTime.Now; // Get the next window. GetWindowedEventPackageResponse allPackages = m_Utils.GetWindowedEvents(0, allCriteria, startRow, windowSize, allSortOrders, direction, startRow == 1); TimeSpan totalTime = DateTime.Now - startTime; Console.WriteLine("Window: {0}, startRow: {1}, numRows: {2}, duration: {3}", windowSize, startRow, allPackages.EventPackages.Count, totalTime); Assert.AreNotEqual(null, allPackages.EventPackages); int expectedRowsReturned = startRow + windowSize - 1 > expectedEventIds.Count ? expectedEventIds.Count - startRow + 1 : windowSize; if (expectedRowsReturned < 0) { expectedRowsReturned = 0; } Assert.AreEqual(expectedRowsReturned, allPackages.EventPackages.Count); for (int eventIndex = 0; eventIndex < expectedRowsReturned; eventIndex++) { int nextExpectedEventId = expectedEventIds[startRow + eventIndex - 1]; StackHashEventPackage eventRetrieved = allPackages.EventPackages[eventIndex]; Assert.AreEqual(nextExpectedEventId, eventRetrieved.EventData.Id); Assert.AreEqual(numCabs, eventRetrieved.Cabs.Count); Assert.AreEqual(numEventInfos, eventRetrieved.EventInfoList.Count); foreach (StackHashCabPackage cabPackage in eventRetrieved.Cabs) { Assert.AreNotEqual(null, cabPackage.Cab); Assert.AreNotEqual(null, cabPackage.CabFileContents); Assert.AreNotEqual(null, cabPackage.CabFileContents.Files); Assert.AreEqual(2, cabPackage.CabFileContents.Files.Count); Assert.AreEqual("cuckusrv.exe.mdmp", cabPackage.CabFileContents.Files[0].FileName); Assert.AreEqual(0x1a5cb, cabPackage.CabFileContents.Files[0].Length); Assert.AreEqual("version.txt", cabPackage.CabFileContents.Files[1].FileName); Assert.AreEqual(0x24, cabPackage.CabFileContents.Files[1].Length); } // Get the event package through the other interface. StackHashProduct product = new StackHashProduct() { Id = eventRetrieved.ProductId }; StackHashFile file = new StackHashFile() { Id = eventRetrieved.EventData.FileId }; StackHashEventPackage matchedPackage = m_Utils.GetEventPackage(0, product, file, eventRetrieved.EventData).EventPackage; Assert.AreEqual(eventRetrieved.Cabs.Count, matchedPackage.Cabs.Count); foreach (StackHashCabPackage cabPackage in matchedPackage.Cabs) { Assert.AreNotEqual(null, cabPackage.CabFileContents); Assert.AreNotEqual(null, cabPackage.CabFileContents.Files); Assert.AreEqual(2, cabPackage.CabFileContents.Files.Count); Assert.AreEqual("cuckusrv.exe.mdmp", cabPackage.CabFileContents.Files[0].FileName); Assert.AreEqual(0x1a5cb, cabPackage.CabFileContents.Files[0].Length); Assert.AreEqual("version.txt", cabPackage.CabFileContents.Files[1].FileName); Assert.AreEqual(0x24, cabPackage.CabFileContents.Files[1].Length); } } } m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(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 public void addRemoveEventNotes(int numberOfNotes) { StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = 1; testIndexData.NumberOfFiles = 1; testIndexData.NumberOfEvents = 1; testIndexData.NumberOfEventInfos = 0; testIndexData.NumberOfCabs = 0; // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(ErrorIndexType.SqlExpress); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; resp.Settings.ErrorIndexSettings.Type = ErrorIndexType.SqlExpress; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); m_Utils.ActivateContext(0); m_Utils.CreateTestIndex(0, testIndexData); try { // Enable all products so that they appear in searchs. StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; StackHashProduct product = products[0].Product; StackHashFileCollection files = m_Utils.GetFiles(0, product).Files; StackHashEventCollection events = m_Utils.GetEvents(0, product, files[0]).Events; // Add the specified number of event notes. for (int eventCount = 0; eventCount < numberOfNotes; eventCount++) { StackHashNoteEntry note = new StackHashNoteEntry(); note.Note = "Note" + (eventCount + 1).ToString(); note.Source = "USER"; note.User = "******"; note.TimeOfEntry = DateTime.Now.AddDays(-1); m_Utils.AddEventNote(0, product, files[0], events[0], note); StackHashNotes notes = m_Utils.GetEventNotes(0, product, files[0], events[0]).Notes; Assert.AreEqual(eventCount + 1, notes.Count); bool found = false; foreach (StackHashNoteEntry noteEntry in notes) { if (noteEntry.NoteId == eventCount + 1) { Assert.AreEqual(note.Note, noteEntry.Note); Assert.AreEqual(note.Source, noteEntry.Source); Assert.AreEqual(note.User, noteEntry.User); Assert.AreEqual(DateTime.UtcNow.Date, noteEntry.TimeOfEntry.Date); found = true; break; } } Assert.AreEqual(true, found); } // Now delete the event notes. int expectedEventNotes = numberOfNotes; for (int eventCount = 0; eventCount < numberOfNotes; eventCount++) { m_Utils.DeleteEventNote(0, product, files[0], events[0], eventCount + 1); expectedEventNotes--; StackHashNotes notes = m_Utils.GetEventNotes(0, product, files[0], events[0]).Notes; Assert.AreEqual(expectedEventNotes, notes.Count); bool found = false; foreach (StackHashNoteEntry noteEntry in notes) { if (noteEntry.NoteId == eventCount + 1) { found = true; break; } } Assert.AreEqual(false, found); } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
public void SetIndexSettingsBeforeCreationSql() { CreateNewStackHashContextResponse newContextResp = m_Utils.CreateNewContext(ErrorIndexType.SqlExpress); Assert.AreEqual(ErrorIndexStatus.NotCreated, newContextResp.Settings.ErrorIndexSettings.Status); String originalIndexPath = newContextResp.Settings.ErrorIndexSettings.Folder; Assert.AreEqual(false, Directory.Exists(originalIndexPath)); String indexName = "ShouldNeverExist"; String testPath = "c:\\stackhashunittests\\testindex\\"; m_Utils.DeleteIndex(0); // Make sure the destination folder does not exist. String fullDestPath = Path.Combine(testPath, indexName); if (Directory.Exists(fullDestPath)) { PathUtils.DeleteDirectory(fullDestPath, true); } newContextResp.Settings.ErrorIndexSettings.Folder = testPath; newContextResp.Settings.ErrorIndexSettings.Name = indexName; newContextResp.Settings.ErrorIndexSettings.Type = ErrorIndexType.SqlExpress; newContextResp.Settings.SqlSettings.ConnectionString = TestSettings.DefaultConnectionString; newContextResp.Settings.SqlSettings.InitialCatalog = indexName; newContextResp.Settings.SqlSettings.EventsPerBlock = 20; newContextResp.Settings.SqlSettings.ConnectionTimeout = 10; newContextResp.Settings.SqlSettings.MaxPoolSize = 8; newContextResp.Settings.SqlSettings.MinPoolSize = 3; m_Utils.SetContextSettings(newContextResp.Settings); m_Utils.RestartService(); // Read them back and make sure they have changed. GetStackHashPropertiesResponse resp = m_Utils.GetContextSettings(); Assert.AreEqual(1, resp.Settings.ContextCollection.Count); Assert.AreEqual(false, resp.Settings.ContextCollection[0].IsActive); Assert.AreEqual(newContextResp.Settings.ErrorIndexSettings.Folder, resp.Settings.ContextCollection[0].ErrorIndexSettings.Folder); Assert.AreEqual(newContextResp.Settings.ErrorIndexSettings.Name, resp.Settings.ContextCollection[0].ErrorIndexSettings.Name); Assert.AreEqual(newContextResp.Settings.ErrorIndexSettings.Type, resp.Settings.ContextCollection[0].ErrorIndexSettings.Type); Assert.AreEqual(newContextResp.Settings.SqlSettings.ConnectionString, resp.Settings.ContextCollection[0].SqlSettings.ConnectionString); Assert.AreEqual(newContextResp.Settings.SqlSettings.ConnectionTimeout, resp.Settings.ContextCollection[0].SqlSettings.ConnectionTimeout); Assert.AreEqual(newContextResp.Settings.SqlSettings.EventsPerBlock, resp.Settings.ContextCollection[0].SqlSettings.EventsPerBlock); Assert.AreEqual(newContextResp.Settings.SqlSettings.InitialCatalog, resp.Settings.ContextCollection[0].SqlSettings.InitialCatalog); Assert.AreEqual(newContextResp.Settings.SqlSettings.MaxPoolSize, resp.Settings.ContextCollection[0].SqlSettings.MaxPoolSize); Assert.AreEqual(newContextResp.Settings.SqlSettings.MinPoolSize, resp.Settings.ContextCollection[0].SqlSettings.MinPoolSize); Assert.AreEqual(ErrorIndexStatus.NotCreated, newContextResp.Settings.ErrorIndexSettings.Status); Assert.AreEqual(false, Directory.Exists(Path.Combine(testPath, indexName))); }
public void getProductsNProductsNFilesNEvents(ErrorIndexType indexType, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = numFiles; testIndexData.NumberOfEvents = numEvents; testIndexData.NumberOfEventInfos = numEventInfos; testIndexData.NumberOfCabs = numCabs; m_Utils.CreateTestIndex(0, testIndexData); // Service is now started with the specified index. // Make sure we can get at least the list of products. GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreNotEqual(new DateTime(0), getProductsResp.LastSiteUpdateTime); Assert.AreEqual(true, Math.Abs((DateTime.Now - getProductsResp.LastSiteUpdateTime).TotalDays) <= 15); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); int productId = 1; int fileId = 1; int eventId = 1; foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(productId++, product.Id); GetFilesResponse getFilesResp = m_Utils.GetFiles(0, product); Assert.AreEqual(numFiles, getFilesResp.Files.Count()); foreach (StackHashFile file in getFilesResp.Files) { Assert.AreEqual(fileId++, file.Id); GetEventsResponse getEventsResp = m_Utils.GetEvents(0, product, file); Assert.AreEqual(numEvents, getEventsResp.Events.Count()); foreach (StackHashEvent theEvent in getEventsResp.Events) { Assert.AreEqual(eventId++, theEvent.Id); GetEventPackageResponse getEventPackageResp = m_Utils.GetEventPackage(0, product, file, theEvent); Assert.AreEqual(numCabs, getEventPackageResp.EventPackage.Cabs.Count); Assert.AreEqual(numEventInfos, getEventPackageResp.EventPackage.EventInfoList.Count); } } } m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); }
// Get the public void productInfoGet(ErrorIndexType indexType, int numProducts, bool resetService) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = 0; testIndexData.NumberOfEvents = 0; testIndexData.NumberOfEventInfos = 0; testIndexData.NumberOfCabs = 0; m_Utils.CreateTestIndex(0, testIndexData); // Service is now started with the specified index. // Make sure we can get at least the list of products. GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(false, productInfo.SynchronizeEnabled); Assert.AreEqual(null, productInfo.ProductSyncData); } // Now enable the products for sync. foreach (StackHashProductInfo productInfo in getProductsResp.Products) { m_Utils.SetProductSynchronizationState(0, productInfo.Product.Id, true); } // Get the list of product data again. getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(true, productInfo.SynchronizeEnabled); Assert.AreNotEqual(null, productInfo.ProductSyncData); Assert.AreEqual(productInfo.Product.Id, productInfo.ProductSyncData.ProductId); } foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProductSyncData syncData = new StackHashProductSyncData(); syncData.ProductId = productInfo.Product.Id; m_Utils.SetProductSynchronizationData(0, syncData); } // Get the list of product data again. getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); if (resetService) { m_Utils.RestartService(); } // Get the list of product data again. getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(true, productInfo.SynchronizeEnabled); Assert.AreNotEqual(null, productInfo.ProductSyncData); Assert.AreEqual(productInfo.Product.Id, productInfo.ProductSyncData.ProductId); } // Disable all products for sync. foreach (StackHashProductInfo productInfo in getProductsResp.Products) { m_Utils.SetProductSynchronizationState(0, productInfo.Product.Id, false); } getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(false, productInfo.SynchronizeEnabled); Assert.AreEqual(null, productInfo.ProductSyncData); } m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); }
public void getProductEventPackages(ErrorIndexType indexType, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashsoaktest\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = numFiles; testIndexData.NumberOfEvents = numEvents; testIndexData.NumberOfEventInfos = numEventInfos; testIndexData.NumberOfCabs = numCabs; m_Utils.CreateTestIndex(0, testIndexData); // Service is now started with the specified index. // Make sure we can get at least the list of products. GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); try { DateTime startTime = DateTime.Now; foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; GetProductEventPackageResponse response = m_Utils.GetProductEventPackages(0, product); Assert.AreEqual(1 * numFiles * numEvents, response.EventPackages.Count); foreach (StackHashEventPackage package in response.EventPackages) { Assert.AreEqual(numCabs, package.Cabs.Count); Assert.AreEqual(numEventInfos, package.EventInfoList.Count); } } DateTime endTime = DateTime.Now; TimeSpan duration = endTime - startTime; Console.WriteLine("Duration: {0}", duration); m_Utils.RestartService(); startTime = DateTime.Now; foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; GetProductEventPackageResponse response = m_Utils.GetProductEventPackages(0, product); Assert.AreEqual(1 * numFiles * numEvents, response.EventPackages.Count); foreach (StackHashEventPackage package in response.EventPackages) { Assert.AreEqual(numCabs, package.Cabs.Count); Assert.AreEqual(numEventInfos, package.EventInfoList.Count); } } endTime = DateTime.Now; duration = endTime - startTime; Console.WriteLine("Duration: {0}", duration); } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(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 public void streamCabs(ErrorIndexType errorIndexType, bool useBigCabs, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs, String fileName, String cabFileName) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(errorIndexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; resp.Settings.ErrorIndexSettings.Type = errorIndexType; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = numFiles; testIndexData.NumberOfEvents = numEvents; testIndexData.NumberOfEventInfos = numEventInfos; testIndexData.NumberOfCabs = numCabs; testIndexData.UseLargeCab = useBigCabs; testIndexData.CabFileName = cabFileName; m_Utils.CreateTestIndex(0, testIndexData); // Find the cab. GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); int productId = 1; int fileId = 1; int eventId = 1; try { foreach (StackHashProductInfo productInfo in getProductsResp.Products) { StackHashProduct product = productInfo.Product; Assert.AreEqual(productId++, product.Id); GetFilesResponse getFilesResp = m_Utils.GetFiles(0, product); Assert.AreEqual(numFiles, getFilesResp.Files.Count()); foreach (StackHashFile file in getFilesResp.Files) { Assert.AreEqual(fileId++, file.Id); GetEventsResponse getEventsResp = m_Utils.GetEvents(0, product, file); Assert.AreEqual(numEvents, getEventsResp.Events.Count()); foreach (StackHashEvent theEvent in getEventsResp.Events) { Assert.AreEqual(eventId++, theEvent.Id); GetEventPackageResponse getEventPackageResp = m_Utils.GetEventPackage(0, product, file, theEvent); Assert.AreEqual(numCabs, getEventPackageResp.EventPackage.Cabs.Count); Assert.AreEqual(numEventInfos, getEventPackageResp.EventPackage.EventInfoList.Count); // Stream the cabs. foreach (StackHashCabPackage cab in getEventPackageResp.EventPackage.Cabs) { String tempCabFileName = Path.GetTempFileName(); File.Delete(tempCabFileName); m_Utils.GetCab(tempCabFileName, 0, product, file, theEvent, cab.Cab, fileName); try { if (String.IsNullOrEmpty(fileName)) { Assert.AreEqual(true, File.Exists(tempCabFileName)); FileInfo fileInfo = new FileInfo(tempCabFileName); if (useBigCabs) { Assert.AreEqual(true, fileInfo.Length > 64 * 1024); } else if (cabFileName != null) { FileInfo sourceCabFileInfo = new FileInfo(cabFileName); Assert.AreEqual(true, fileInfo.Length == sourceCabFileInfo.Length); Assert.AreEqual(true, fileInfo.Length > 20000000); } else { Assert.AreEqual(true, fileInfo.Length <= 64 * 1024); } } else if (String.Compare("version.txt", fileName, StringComparison.OrdinalIgnoreCase) == 0) { String allText = File.ReadAllText(tempCabFileName); Assert.AreEqual(true, allText.Contains("Architecture:")); } } finally { File.Delete(tempCabFileName); } } } } } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }