Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
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>
        /// 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));
            }
        }