Beispiel #1
0
        public void tidyTest()
        {
            StackHashSqlControl.InstallerInterface installerInterface =
                new StackHashSqlControl.InstallerInterface(TestSettings.DefaultConnectionString,
                                                           "MASTER", "C:\\StackHashDefaultErrorIndex");

            installerInterface.Connect();
            if (installerInterface.DatabaseExists(s_SourceIndexName))
            {
                installerInterface.DeleteDatabase(s_SourceIndexName);
            }
            if (installerInterface.DatabaseExists(s_DestIndexName))
            {
                installerInterface.DeleteDatabase(s_DestIndexName);
            }
            installerInterface.Disconnect();
            SqlConnection.ClearAllPools();

            if (Directory.Exists("C:\\StackHashDefaultErrorIndex"))
            {
                PathUtils.DeleteDirectory("C:\\StackHashDefaultErrorIndex", true);
            }
        }
Beispiel #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

        public void copyIndex(bool createDestinationIndexLocally, bool switchIndex, StackHashTestIndexData testData)
        {
            try
            {
                m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid);
                m_Utils.CreateAndSetNewContext(ErrorIndexType.Xml); // Create a context and give it a non-default name.
                m_Utils.DeleteIndex(0);

                GetStackHashPropertiesResponse getResp = m_Utils.GetContextSettings();
                Assert.AreEqual(ErrorIndexStatus.NotCreated, getResp.Settings.ContextCollection[0].ErrorIndexSettings.Status);

                m_Utils.ActivateContext(0); // Create the index.
                m_Utils.CreateTestIndex(0, testData);


                getResp = m_Utils.GetContextSettings();
                Assert.AreEqual(ErrorIndexStatus.Created, getResp.Settings.ContextCollection[0].ErrorIndexSettings.Status);

                String originalIndexPath = getResp.Settings.ContextCollection[0].ErrorIndexSettings.Folder;
                String originalIndexName = getResp.Settings.ContextCollection[0].ErrorIndexSettings.Name;

                String destIndexName = "UnitTestsCopyIndexName";
                String destIndexPath = "c:\\stackhashunittests\\copyindexpath\\";

                // Make sure the destination folder does not exist.
                String fullDestPath = Path.Combine(destIndexPath, destIndexName);

                if (Directory.Exists(fullDestPath))
                {
                    PathUtils.DeleteDirectory(fullDestPath, true);
                }


                ErrorIndexSettings destSettings = new ErrorIndexSettings()
                {
                    Folder = destIndexPath,
                    Name   = destIndexName,
                    Type   = ErrorIndexType.SqlExpress
                };

                StackHashSqlConfiguration sqlConfig = new StackHashSqlConfiguration()
                {
                    ConnectionString  = String.Format(TestSettings.DefaultConnectionString, destIndexName),
                    InitialCatalog    = destIndexName,
                    MaxPoolSize       = 100,
                    MinPoolSize       = 2,
                    ConnectionTimeout = 20,
                };

                if (createDestinationIndexLocally)
                {
                    StackHashSqlControl.InstallerInterface installerInterface =
                        new StackHashSqlControl.InstallerInterface(TestSettings.DefaultConnectionString + "Initial Catalog=MASTER;",
                                                                   destSettings.Name, destSettings.Folder);

                    installerInterface.Connect();
                    installerInterface.CreateDatabase(true);
                    installerInterface.Disconnect();
                    SqlConnection.ClearAllPools();
                }

                m_Utils.DeactivateContext(0);
                m_Utils.CopyIndex(0, destSettings, sqlConfig, switchIndex, 60000);
                m_Utils.ActivateContext(0);

                Assert.AreEqual(true, Directory.Exists(Path.Combine(originalIndexPath, originalIndexName)));
                Assert.AreEqual(true, Directory.Exists(fullDestPath));

                Assert.AreNotEqual(null, m_Utils.CopyCompleteAdminReport);
                Assert.AreEqual(null, m_Utils.CopyCompleteAdminReport.LastException);
                Assert.AreEqual(StackHashAsyncOperationResult.Success, m_Utils.CopyCompleteAdminReport.ResultData);


                getResp = m_Utils.GetContextSettings();

                if (switchIndex)
                {
                    Assert.AreEqual(ErrorIndexStatus.Created, getResp.Settings.ContextCollection[0].ErrorIndexSettings.Status);
                    Assert.AreEqual(destSettings.Folder.ToUpperInvariant(), getResp.Settings.ContextCollection[0].ErrorIndexSettings.Folder.ToUpperInvariant());
                    Assert.AreEqual(destSettings.Name.ToUpperInvariant(), getResp.Settings.ContextCollection[0].ErrorIndexSettings.Name.ToUpperInvariant());
                }
                else
                {
                    Assert.AreEqual(ErrorIndexStatus.Created, getResp.Settings.ContextCollection[0].ErrorIndexSettings.Status);
                    Assert.AreEqual(originalIndexPath.ToUpperInvariant(), getResp.Settings.ContextCollection[0].ErrorIndexSettings.Folder.ToUpperInvariant());
                    Assert.AreEqual(originalIndexName.ToUpperInvariant(), getResp.Settings.ContextCollection[0].ErrorIndexSettings.Name.ToUpperInvariant());
                }
            }
            finally
            {
                m_Utils.DeactivateContext(0);
                m_Utils.DeleteIndex(0);
            }
        }