Beispiel #1
0
        public void DeserializeMultiDbConfigurationTest_WithQueryRowDataItems()
        {
            string fileName = Path.GetTempFileName();

            try
            {
                string fileContents = Properties.Resources.MultiDb_WithQueryRowData;
                File.WriteAllText(fileName, fileContents);
                MultiDbData actual;
                actual = MultiDbHelper.DeserializeMultiDbConfiguration(fileName);
                actual.IsTransactional = false;

                Assert.AreEqual(@"Server1\Instance_1", actual[0].ServerName);

                Assert.AreEqual(@"Server2\Instance_1", actual[1].ServerName);
                DbOverrideSequence seq = actual[1].OverrideSequence;
                Assert.AreEqual("Default", seq["1"][0].DefaultDbTarget);
                Assert.AreEqual("Db_0002", seq["1"][0].OverrideDbTarget);

                List <QueryRowItem> queryItems = seq["1"][0].QueryRowData;
                Assert.AreEqual("MyCompany2", queryItems[0].Value);
                Assert.AreEqual("CompanyName", queryItems[0].ColumnName);
                Assert.AreEqual("CompanyID", queryItems[1].ColumnName);
                Assert.AreEqual("000002", queryItems[1].Value);

                Assert.IsFalse(actual.IsTransactional);
            }
            finally
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
            }
        }
Beispiel #2
0
        public void ValidateMultiDatabaseData_EmptyOverrideSequence()
        {
            MultiDbData dbData = new MultiDbData();

            ServerData srv1 = new ServerData();

            srv1.ServerName   = "server1";
            dbData["server1"] = srv1;
            ServerData srv2 = new ServerData();

            srv2.ServerName   = "server2";
            dbData["server2"] = srv2;

            DbOverrideSequence ovr = new DbOverrideSequence();

            ovr.Add("1", new DatabaseOverride("default", "target"));
            ovr.Add("2", new DatabaseOverride("default2", "target2"));
            dbData["server1"].OverrideSequence = ovr;

            DbOverrideSequence ovr2 = new DbOverrideSequence();

            ovr.Add("3", new DatabaseOverride("default", "target"));
            ovr.Add("4", new DatabaseOverride("", ""));
            dbData["server2"].OverrideSequence = ovr2;


            bool expected = false;
            bool actual   = MultiDbHelper.ValidateMultiDatabaseData(dbData);

            Assert.AreEqual(expected, actual);
        }
Beispiel #3
0
        public void ImportMultiDbTextConfigTest_ReadFile()
        {
            string fileName = Path.GetTempFileName();

            try
            {
                string[] fileContents = new string[] { "SERVER:default,target;default2,target2", "SERVER2:default,target;default2,target2" };
                File.WriteAllLines(fileName, fileContents);
                MultiDbData actual;
                actual = MultiDbHelper.ImportMultiDbTextConfig(fileName);

                Assert.AreEqual(actual[0].ServerName, "SERVER");
                Assert.AreEqual(actual[1].ServerName, "SERVER2");

                DbOverrideSequence seq = actual[0].OverrideSequence;
                Assert.AreEqual(seq["0"][0].DefaultDbTarget, "default");
                Assert.AreEqual(seq["0"][1].OverrideDbTarget, "target2");
                seq = actual[1].OverrideSequence;
                Assert.AreEqual(seq["1"][1].DefaultDbTarget, "default2");
                Assert.AreEqual(seq["1"][0].OverrideDbTarget, "target");
            }
            finally
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
            }
        }
Beispiel #4
0
        public void ImportMultiDbTextConfigTest_BadConfuguration_MissingColon()
        {
            string[]    fileContents = new string[] { "SERVER:default,target;default2,target2", "SERVER2 default,target;default2,target2" };
            MultiDbData actual;

            actual = MultiDbHelper.ImportMultiDbTextConfig(fileContents);
        }
Beispiel #5
0
        public void ValidateMultiDatabaseData_BadConfuguration()
        {
            string[]    fileContents = new string[] { "SERVER:default,target;default2,target2", "SERVER2:,;default2,target2" };
            MultiDbData dbData       = MultiDbHelper.ImportMultiDbTextConfig(fileContents);
            bool        expected     = false;
            bool        actual       = MultiDbHelper.ValidateMultiDatabaseData(dbData);

            Assert.AreEqual(expected, actual);
        }
Beispiel #6
0
        public void DeserializeMultiDbConfigurationTest_EmptyFileName()
        {
            string      fileName = string.Empty;
            MultiDbData expected = null;
            MultiDbData actual;

            actual = MultiDbHelper.DeserializeMultiDbConfiguration(fileName);
            Assert.AreEqual(expected, actual);
        }
Beispiel #7
0
        public void ImportMultiDbTextConfigTest_EmptyFileName()
        {
            string      fileName = string.Empty;
            MultiDbData expected = null;
            MultiDbData actual;

            actual = MultiDbHelper.ImportMultiDbTextConfig(fileName);
            Assert.AreEqual(expected, actual);
        }
Beispiel #8
0
        /// <summary>
        /// Uploads the specified file to the specified Blob container.
        /// </summary>
        /// <param name="storageSvcClient">A <see cref="CloudBlobClient"/>.</param>
        /// <param name="containerName">The name of the blob storage container to which the file should be uploaded.</param>
        /// <param name="filePath">The full path to the file to upload to Storage.</param>
        /// <returns>A ResourceFile instance representing the file within blob storage.</returns>



        /// <summary>
        /// Gets a string array for all of the target DB override settings
        /// </summary>
        /// <param name="multiDBFileName"></param>
        /// <returns></returns>
        private static string[] GetTargetConfigValues(string multiDBFileName)
        {
            MultiDbData multiDb;

            string[] errorMessages;
            int      valRet = Validation.ValidateAndLoadMultiDbData(multiDBFileName, null, out multiDb, out errorMessages);
            string   cfg    = MultiDbHelper.ConvertMultiDbDataToTextConfig(multiDb);

            return(cfg.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
        }
Beispiel #9
0
        public void ImportMultiDbTextConfigTest_MultipleOfSameServer()
        {
            string[]    fileContents = new string[] { "SERVER:default,target;default2,target2", "SERVER:default,target;default2,target2", "SERVER1:default,target;default3,target3" };
            MultiDbData actual;

            actual = MultiDbHelper.ImportMultiDbTextConfig(fileContents);
            Assert.AreEqual("SERVER", actual[0].ServerName); //Make sure the items with the same server only get on server entry.
            Assert.AreEqual("SERVER1", actual[1].ServerName);
            Assert.AreEqual(2, actual[0].OverrideSequence.Count);
            Assert.AreEqual(1, actual[1].OverrideSequence.Count);
        }
Beispiel #10
0
        public void ConvertMultiDbDataToTextConfigTest()
        {
            DbOverrideSequence sequenceA = new DbOverrideSequence();

            sequenceA.Add("1", new DatabaseOverride("default1", "override1"));
            sequenceA.Add("2", new DatabaseOverride("default2", "override2"));
            sequenceA.Add("0", new DatabaseOverride("default0", "override0"));

            DatabaseOverride        ovrX   = new DatabaseOverride("defaultX", "overrideX");
            DatabaseOverride        ovrY   = new DatabaseOverride("defaultY", "overrideY");
            List <DatabaseOverride> lstOvr = new List <DatabaseOverride>();

            lstOvr.Add(ovrX);
            lstOvr.Add(ovrY);
            sequenceA.Add("M", lstOvr);

            ServerData serverA = new ServerData();

            serverA.OverrideSequence = sequenceA;
            serverA.ServerName       = "ServerA";

            DbOverrideSequence sequenceB = new DbOverrideSequence();

            sequenceB.Add("6", new DatabaseOverride("default6", "override6"));
            sequenceB.Add("7", new DatabaseOverride("default7", "override7"));
            sequenceB.Add("5", new DatabaseOverride("default5", "override5"));

            ServerData serverB = new ServerData();

            serverB.OverrideSequence = sequenceB;
            serverB.ServerName       = "ServerB";

            MultiDbData cfg = new MultiDbData();

            cfg.Add(serverA);
            cfg.Add(serverB);

            string expected =
                @"ServerA:default1,override1
ServerA:default2,override2
ServerA:default0,override0
ServerA:defaultX,overrideX;defaultY,overrideY
ServerB:default6,override6
ServerB:default7,override7
ServerB:default5,override5
";
            string actual;

            actual = MultiDbHelper.ConvertMultiDbDataToTextConfig(cfg);
            Assert.AreEqual(expected, actual);
        }
Beispiel #11
0
        public void DeserializeMultiDbConfigurationTest_ReadFile()
        {
            string fileName = Path.GetTempFileName();

            try
            {
                string fileContents = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
                fileContents += "<ArrayOfServerData xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
                fileContents += @"
  <ServerData>
    <ServerName>(local)</ServerName>
    <OverrideSequence>
      <item>
        <key>
          <string>1</string>
        </key>
        <value>
          <ArrayOfDatabaseOverride>
            <DatabaseOverride>
              <DefaultDbTarget>SqlBuildTest</DefaultDbTarget>
              <OverrideDbTarget>master</OverrideDbTarget>
            </DatabaseOverride>
          </ArrayOfDatabaseOverride>
        </value>
      </item>
    </OverrideSequence>
  </ServerData>
</ArrayOfServerData>";
                File.WriteAllText(fileName, fileContents);
                MultiDbData actual;
                actual = MultiDbHelper.DeserializeMultiDbConfiguration(fileName);
                actual.IsTransactional = false;

                Assert.AreEqual(actual[0].ServerName, "(local)");
                DbOverrideSequence seq = actual[0].OverrideSequence;
                Assert.AreEqual(seq["1"][0].DefaultDbTarget, "SqlBuildTest");
                Assert.AreEqual(seq["1"][0].OverrideDbTarget, "master");
                Assert.IsFalse(actual.IsTransactional);
            }
            finally
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
            }
        }
Beispiel #12
0
        public void ImportMultiDbTextConfigTest_GoodConfuguration_HandleEmptyLine()
        {
            string[]    fileContents = new string[] { "SERVER:default,target;default2,target2", "", "SERVER2:default,target;default2,target2" };
            MultiDbData actual;

            actual = MultiDbHelper.ImportMultiDbTextConfig(fileContents);
            Assert.AreEqual(actual[0].ServerName, "SERVER");
            Assert.AreEqual(actual[1].ServerName, "SERVER2");

            DbOverrideSequence seq = actual[0].OverrideSequence;

            Assert.AreEqual(seq["0"][0].DefaultDbTarget, "default");
            Assert.AreEqual(seq["0"][1].OverrideDbTarget, "target2");
            seq = actual[1].OverrideSequence;
            Assert.AreEqual(seq["1"][1].DefaultDbTarget, "default2");
            Assert.AreEqual(seq["1"][0].OverrideDbTarget, "target");
        }
Beispiel #13
0
        /// <summary>
        /// Accepts a Multi-Database configuration file, processes it and outputs a populated MultiDbData object
        /// </summary>
        /// <param name="multiDbOverrideSettingFileName">Valid Multi-database file (.multiDb, .multiDbQ, .cfg)</param>
        /// <param name="multiData">Out parameter of populated MultiDbData object</param>
        /// <param name="errorMessages">Out parameter or error messages (if any)</param>
        /// <returns>Zero (0) if no errors, otherwise an error code</returns>
        public static int ValidateAndLoadMultiDbData(string multiDbOverrideSettingFileName, CommandLineArgs cmdLine, out MultiDbData multiData, out string[] errorMessages)
        {
            log.LogInformation("Validating target database settings");
            string message = string.Empty;
            string error;

            errorMessages = new string[0];
            multiData     = null;
            string extension = Path.GetExtension(multiDbOverrideSettingFileName).ToLowerInvariant();

            switch (extension)
            {
            case ".multidb":
                multiData = MultiDbHelper.DeserializeMultiDbConfiguration(multiDbOverrideSettingFileName);
                break;

            case ".multidbq":
                multiData = MultiDbHelper.CreateMultiDbConfigFromQueryFile(multiDbOverrideSettingFileName, out message);
                break;

            case ".sql":
                if (cmdLine != null)
                {
                    ConnectionData connData = new ConnectionData()
                    {
                        DatabaseName       = cmdLine.Database,
                        SQLServerName      = cmdLine.Server,
                        UserId             = cmdLine.AuthenticationArgs.UserName,
                        Password           = cmdLine.AuthenticationArgs.Password,
                        AuthenticationType = cmdLine.AuthenticationArgs.AuthenticationType
                    };
                    multiData = MultiDbHelper.CreateMultiDbConfigFromQuery(connData, File.ReadAllText(cmdLine.MultiDbRunConfigFileName), out message);
                }
                break;

            case ".cfg":
            default:
                multiData = MultiDbHelper.ImportMultiDbTextConfig(multiDbOverrideSettingFileName);
                break;
            }
            //if (multiDbOverrideSettingFileName.EndsWith(".multidb", StringComparison.InvariantCultureIgnoreCase))
            //    multiData = MultiDbHelper.DeserializeMultiDbConfiguration(multiDbOverrideSettingFileName);
            //else if (multiDbOverrideSettingFileName.EndsWith(".multidbq", StringComparison.InvariantCultureIgnoreCase))
            //    multiData = MultiDbHelper.CreateMultiDbConfigFromQueryFile(multiDbOverrideSettingFileName, out message);
            //else if (multiDbOverrideSettingFileName.EndsWith(".cfg", StringComparison.InvariantCultureIgnoreCase))
            //    multiData = MultiDbHelper.ImportMultiDbTextConfig(multiDbOverrideSettingFileName);


            if (multiData == null || multiData.Count() == 0)
            {
                error         = "Unable to read in configuration file " + multiDbOverrideSettingFileName + ((message.Length > 0) ? " :: " + message : "");
                errorMessages = new string[] { error, "Returning error code: " + (int)ExecutionReturn.NullMultiDbConfig };
                log.LogError(error);
                return((int)ExecutionReturn.NullMultiDbConfig);
            }

            if (!MultiDbHelper.ValidateMultiDatabaseData(multiData))
            {
                error         = "One or more scripts is missing a default or target override database setting. Run has been halted. Please correct the error and try again";
                errorMessages = new string[] { error, "Returning error code: " + (int)ExecutionReturn.MissingTargetDbOverrideSetting };
                log.LogError(error);
                return((int)ExecutionReturn.MissingTargetDbOverrideSetting);
            }
            return(0);
        }