Beispiel #1
0
        public void RenameActiveDatabaseSameName()
        {
            // Create an index with a particular name. Then change the name of the index.
            String sourceDatabaseName = "MoveIndexTestDatabase1";
            String destDatabaseName   = "MoveIndexTestDatabase1";

            m_SqlSettings.InitialCatalog = sourceDatabaseName;
            m_ErrorIndex = new SqlErrorIndex(m_SqlSettings, sourceDatabaseName, m_TestFolder);
            try { m_ErrorIndex.DeleteIndex(); }
            catch {; }

            // This call will create the database.
            m_ErrorIndex.Activate();

            // Can't move an active database.
            m_ErrorIndex.Deactivate();

            m_SqlSettings.InitialCatalog = destDatabaseName;
            m_ErrorIndex.MoveIndex(m_TestFolder, destDatabaseName, m_SqlSettings, true);

            Assert.AreEqual(destDatabaseName, m_ErrorIndex.ErrorIndexName);
            Assert.AreEqual(m_TestFolder, m_ErrorIndex.ErrorIndexPath);

            m_ErrorIndex.Deactivate();
            m_ErrorIndex.Dispose();

            // Now reload and make sure it is present.
            m_ErrorIndex = new SqlErrorIndex(m_SqlSettings, destDatabaseName, m_TestFolder);
            Assert.AreEqual(ErrorIndexStatus.Created, m_ErrorIndex.Status);

            Assert.AreEqual(true, Directory.Exists(Path.Combine(m_TestFolder, destDatabaseName)));

            m_ErrorIndex.Activate();
            m_ErrorIndex.Deactivate();
        }
Beispiel #2
0
        public void MoveDatabaseToNewFolderDifferentDrive()
        {
            // Only run this test on machine with a Z drive mapped.
            if (!Directory.Exists(m_TestFolderZ))
            {
                return;
            }

            // Create an index with a particular name. Then change the name of the index.
            String sourceDatabaseName = "MoveIndexTestDatabase1";
            String destDatabaseName   = "MoveIndexTestDatabase1";

            m_SqlSettings.InitialCatalog = sourceDatabaseName;
            m_ErrorIndex = new SqlErrorIndex(m_SqlSettings, sourceDatabaseName, m_TestFolder);
            try { m_ErrorIndex.DeleteIndex(); }
            catch {; }

            // This call will create the database.
            m_ErrorIndex.Activate();

            // Can't move an active database.
            m_ErrorIndex.Deactivate();

            // Must create the destination folder.
            if (!Directory.Exists(m_TestFolder3))
            {
                Directory.CreateDirectory(m_TestFolder3);
            }

            m_SqlSettings.InitialCatalog = destDatabaseName;

            m_ErrorIndex.IndexMoveProgress += new EventHandler <ErrorIndexMoveEventArgs>(this.errorIndexMoveCallback);

            try
            {
                m_ErrorIndex.MoveIndex(m_TestFolder3, destDatabaseName, m_SqlSettings, true);

                Assert.AreEqual(destDatabaseName, m_ErrorIndex.ErrorIndexName);
                Assert.AreEqual(m_TestFolder3, m_ErrorIndex.ErrorIndexPath);

                m_ErrorIndex.Deactivate();
                m_ErrorIndex.Dispose();

                // Now reload and make sure it is present.
                m_ErrorIndex = new SqlErrorIndex(m_SqlSettings, destDatabaseName, m_TestFolder3);
                Assert.AreEqual(ErrorIndexStatus.Created, m_ErrorIndex.Status);

                Assert.AreEqual(true, Directory.Exists(Path.Combine(m_TestFolder3, destDatabaseName)));
                Assert.AreEqual(false, Directory.Exists(Path.Combine(m_TestFolder, sourceDatabaseName)));

                Assert.AreEqual(true, m_MoveFileCount > 0);

                m_ErrorIndex.Activate();
                m_ErrorIndex.Deactivate();
            }
            finally
            {
                m_ErrorIndex.IndexMoveProgress -= new EventHandler <ErrorIndexMoveEventArgs>(this.errorIndexMoveCallback);
            }
        }
Beispiel #3
0
        public void RenameIndexBeforeActive()
        {
            // Create an index with a particular name. Then change the name of the index.
            String sourceDatabaseName = "MoveIndexTestDatabase1";
            String destDatabaseName   = "MoveIndexTestDatabase2";

            m_SqlSettings.InitialCatalog = sourceDatabaseName;
            m_ErrorIndex = new SqlErrorIndex(m_SqlSettings, sourceDatabaseName, m_TestFolder);

            m_SqlSettings.InitialCatalog = destDatabaseName;
            m_ErrorIndex.MoveIndex(m_TestFolder, destDatabaseName, m_SqlSettings, true);

            Assert.AreEqual(destDatabaseName, m_ErrorIndex.ErrorIndexName);
            Assert.AreEqual(m_TestFolder, m_ErrorIndex.ErrorIndexPath);
        }
Beispiel #4
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 moveIndex(IErrorIndex errorIndex, int numProducts, String newIndexPath, String newIndexName, bool activate)
        {
            String originalIndexPath = errorIndex.ErrorIndexPath;
            String originalIndexName = errorIndex.ErrorIndexName;

            if (activate)
            {
                errorIndex.Activate();

                for (int i = 0; i < numProducts; i++)
                {
                    StackHashProduct product = new StackHashProduct(DateTime.Now, DateTime.Now, "www.link.com", i, "p" + i.ToString(),
                                                                    i, i, "version");
                    errorIndex.AddProduct(product);
                }

                // Now move the index.
                errorIndex.Deactivate();
            }

            errorIndex.MoveIndex(newIndexPath, newIndexName, null, true);
            if (activate)
            {
                errorIndex.Activate();
            }

            // Check the results.
            if (activate)
            {
                Assert.AreEqual(false, Directory.Exists(originalIndexPath + "\\" + originalIndexName));
                Assert.AreEqual(true, Directory.Exists(newIndexPath + "\\" + newIndexName));
            }
            else
            {
                // Shouldn't have done anything - if never activated then even the source should not exist.
                Assert.AreEqual(false, Directory.Exists(originalIndexPath + "\\" + originalIndexName));
                Assert.AreEqual(false, Directory.Exists(newIndexPath + "\\" + newIndexName));
            }
        }