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