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); }
public void InitResponse(string data) { mResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<GetEventsResponse>(data); eventDelegate.Execute (); }
// // 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); } }