/// <summary> /// Try a download using default context username and password - should fail with a feed error. /// </summary> public void downloadCabInvalidLogin(ErrorIndexType indexType) { m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.CreateAndSetNewContext(indexType); m_Utils.ActivateContext(0); StackHashTestIndexData indexData = new StackHashTestIndexData(); indexData.NumberOfProducts = 1; indexData.NumberOfFiles = 1; indexData.NumberOfEvents = 1; indexData.NumberOfCabs = 1; indexData.NumberOfEventInfos = 1; m_Utils.CreateTestIndex(0, indexData); try { StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; StackHashFileCollection files = m_Utils.GetFiles(0, products[0].Product).Files; StackHashEventPackageCollection events = m_Utils.GetProductEventPackages(0, products[0].Product).EventPackages; StackHashCabPackageCollection cabs = events[0].Cabs; DownloadCabResponse resp = m_Utils.DownloadCab(0, products[0].Product, files[0], events[0].EventData, events[0].Cabs[0].Cab, 30000); StackHashAdminReport adminReport = m_Utils.DownloadCabAdminReport; Assert.AreNotEqual(null, adminReport); Assert.AreEqual(m_Utils.LastClientData.ApplicationGuid, adminReport.ClientData.ApplicationGuid); Assert.AreEqual(m_Utils.LastClientData.ClientId, adminReport.ClientData.ClientId); Assert.AreEqual(m_Utils.LastClientData.ClientName, adminReport.ClientData.ClientName); Assert.AreEqual(m_Utils.LastClientData.ClientRequestId, adminReport.ClientData.ClientRequestId); Assert.AreEqual(0, adminReport.ContextId); Assert.AreNotEqual(null, adminReport.LastException); Assert.AreEqual(true, adminReport.LastException.Contains("username and password")); Assert.AreEqual(StackHashAdminOperation.DownloadCabCompleted, adminReport.Operation); Assert.AreEqual(StackHashAsyncOperationResult.Failed, adminReport.ResultData); } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
/// <summary> /// Product = null. /// </summary> public void downloadCabProductNull(ErrorIndexType indexType) { m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.CreateAndSetNewContext(indexType); m_Utils.ActivateContext(0); try { DownloadCabResponse resp = m_Utils.DownloadCab(0, null, null, null, null, 30000); } catch (FaultException <ReceiverFaultDetail> ex) { Assert.AreEqual(true, ex.Message.Contains("Value cannot be null")); Assert.AreEqual(true, ex.Message.Contains("product")); Assert.AreEqual(StackHashServiceErrorCode.UnexpectedError, ex.Detail.ServiceErrorCode); } m_Utils.DeactivateContext(0); }
/// <summary> /// Product doesn't exist. /// </summary> public void downloadCabProductDoesntExist(ErrorIndexType indexType) { m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.CreateAndSetNewContext(indexType); m_Utils.ActivateContext(0); StackHashTestIndexData indexData = new StackHashTestIndexData(); indexData.NumberOfProducts = 1; indexData.NumberOfFiles = 1; indexData.NumberOfEvents = 1; indexData.NumberOfCabs = 1; indexData.NumberOfEventInfos = 1; m_Utils.CreateTestIndex(0, indexData); try { try { StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; StackHashFileCollection files = m_Utils.GetFiles(0, products[0].Product).Files; StackHashEventPackageCollection events = m_Utils.GetProductEventPackages(0, products[0].Product).EventPackages; StackHashCabPackageCollection cabs = events[0].Cabs; products[0].Product.Id++; // Wrong ID. DownloadCabResponse resp = m_Utils.DownloadCab(0, products[0].Product, files[0], events[0].EventData, events[0].Cabs[0].Cab, 30000); } catch (FaultException <ReceiverFaultDetail> ex) { Assert.AreEqual(true, ex.Message.Contains("Product does not exist")); } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
public void runAnalyzeJustAutoScripts(ErrorIndexType indexType, int numberOfProducts, int numberOfFiles, int numberOfEvents, int numberOfCabs, int numberOfAutoUnmanagedAndManagedScripts, int numberOfManualUnmanagedAndManagedScripts, bool useUnmanagedCabs, int numberOfAutoManagedScripts, int numberOfManualManagedScripts, int numberOfAutoUnmanagedScripts, int numberOfManualUnmanagedScripts) { int numberOfEventInfos = 1; // Use the dummy winqual. StackHashTestData testData = new StackHashTestData(); testData.DummyWinQualSettings = new StackHashTestDummyWinQualSettings(); testData.DummyWinQualSettings.UseDummyWinQual = true; testData.DummyWinQualSettings.ObjectsToCreate = new StackHashTestIndexData(); testData.DummyWinQualSettings.ObjectsToCreate.UseLargeCab = false; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfProducts = numberOfProducts; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfFiles = numberOfFiles; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfEvents = numberOfEvents; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfEventInfos = numberOfEventInfos; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfCabs = numberOfCabs; testData.DummyWinQualSettings.ObjectsToCreate.UseUnmanagedCab = useUnmanagedCabs; m_Utils.SetTestData(testData); m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.CreateNewContext(indexType); // Set the username and password to something valid. GetStackHashPropertiesResponse settings = m_Utils.GetContextSettings(); String testPath = "c:\\stackhashunittest\\testindex\\"; settings.Settings.ContextCollection[0].ErrorIndexSettings.Folder = testPath; settings.Settings.ContextCollection[0].ErrorIndexSettings.Name = "TestIndex"; settings.Settings.ContextCollection[0].WinQualSettings.UserName = m_UserName; settings.Settings.ContextCollection[0].WinQualSettings.Password = m_Password; m_Utils.SetContextSettings(settings.Settings.ContextCollection[0]); // Make sure the index starts off empty. m_Utils.DeleteIndex(0); m_Utils.ActivateContext(0); for (int i = 0; i < numberOfAutoUnmanagedAndManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i, true, StackHashScriptDumpType.UnmanagedAndManaged, true); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfManualUnmanagedAndManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 100, true, StackHashScriptDumpType.UnmanagedAndManaged, false); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfAutoManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 200, true, StackHashScriptDumpType.ManagedOnly, true); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfManualManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 300, true, StackHashScriptDumpType.ManagedOnly, false); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfAutoUnmanagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 400, true, StackHashScriptDumpType.UnmanagedOnly, true); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfManualUnmanagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 500, true, StackHashScriptDumpType.UnmanagedOnly, false); m_Utils.AddDebuggerScript(scriptSettings, false); } try { // Synchronize so we have a copy of just the product list. StartSynchronizationResponse resp = m_Utils.StartSynchronization(0, 60000); StackHashClientData clientData = m_Utils.LastClientData; StackHashWinQualSyncCompleteAdminReport adminReport = m_Utils.WinQualSyncAdminReport as StackHashWinQualSyncCompleteAdminReport; Assert.AreNotEqual(null, adminReport); Assert.AreEqual(clientData.ApplicationGuid, adminReport.ClientData.ApplicationGuid); Assert.AreEqual(clientData.ClientId, adminReport.ClientData.ClientId); Assert.AreEqual(clientData.ClientName, adminReport.ClientData.ClientName); Assert.AreEqual(clientData.ClientRequestId, adminReport.ClientData.ClientRequestId); Assert.AreEqual(0, adminReport.ContextId); Assert.AreEqual(null, adminReport.LastException); Assert.AreEqual(StackHashAdminOperation.WinQualSyncCompleted, adminReport.Operation); Assert.AreEqual(StackHashAsyncOperationResult.Success, adminReport.ResultData); Assert.AreEqual(numberOfProducts, adminReport.ErrorIndexStatistics.Products); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Files); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Events); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Cabs); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.EventInfos); // Enable sync for all the products. GetProductsResponse getProducts = m_Utils.GetProducts(0); foreach (StackHashProductInfo productInfo in getProducts.Products) { Assert.AreEqual(false, productInfo.SynchronizeEnabled); m_Utils.SetProductSynchronizationState(0, productInfo.Product.Id, true); // Make sure there are no files for this product yet. GetFilesResponse getFiles = m_Utils.GetFiles(0, productInfo.Product); Assert.AreEqual(0, getFiles.Files.Count); } // Start the sync and wait for the sync and analyze to complete. resp = m_Utils.StartSynchronization(0, 120000, false, false, null); clientData = m_Utils.LastClientData; adminReport = m_Utils.WinQualSyncAdminReport as StackHashWinQualSyncCompleteAdminReport; Assert.AreNotEqual(null, adminReport); Assert.AreEqual(clientData.ApplicationGuid, adminReport.ClientData.ApplicationGuid); Assert.AreEqual(clientData.ClientId, adminReport.ClientData.ClientId); Assert.AreEqual(clientData.ClientName, adminReport.ClientData.ClientName); Assert.AreEqual(clientData.ClientRequestId, adminReport.ClientData.ClientRequestId); Assert.AreEqual(0, adminReport.ContextId); Assert.AreEqual(null, adminReport.LastException); Assert.AreEqual(StackHashAdminOperation.WinQualSyncCompleted, adminReport.Operation); Assert.AreEqual(StackHashAsyncOperationResult.Success, adminReport.ResultData); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Products); // Should have already added the product. Assert.AreEqual(numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Files); Assert.AreEqual(numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Events); Assert.AreEqual(numberOfCabs * numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Cabs); Assert.AreEqual(numberOfEventInfos * numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.EventInfos); // Make sure the task is no longer running. GetStackHashServiceStatusResponse statusResp = m_Utils.GetServiceStatus(); Assert.AreEqual(false, m_Utils.IsTaskRunning(statusResp.Status.ContextStatusCollection[0].TaskStatusCollection, StackHashTaskType.WinQualSynchronizeTask)); Assert.AreEqual(false, m_Utils.IsTaskRunning(statusResp.Status.ContextStatusCollection[0].TaskStatusCollection, StackHashTaskType.AnalyzeTask)); // Check that the scripts have been run ok. Both auto scripts should be run. StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; foreach (StackHashProductInfo product in products) { StackHashFileCollection files = m_Utils.GetFiles(0, product.Product).Files; foreach (StackHashFile file in files) { StackHashEventCollection events = m_Utils.GetEvents(0, product.Product, file).Events; foreach (StackHashEvent currentEvent in events) { StackHashEventPackage eventPackage = m_Utils.GetEventPackage(0, product.Product, file, currentEvent).EventPackage; foreach (StackHashCabPackage cab in eventPackage.Cabs) { StackHashScriptResultFiles scriptResults = m_Utils.GetDebugResultFiles(0, product.Product, file, currentEvent, cab.Cab).ResultFiles; int numberOfAutoScripts = 2; int expectedResults = numberOfAutoScripts + numberOfAutoUnmanagedAndManagedScripts; if (!useUnmanagedCabs) { expectedResults += numberOfAutoManagedScripts; } else { expectedResults += numberOfAutoUnmanagedScripts; } Assert.AreEqual(expectedResults, scriptResults.Count); } } } } } 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 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); }
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); } }