コード例 #1
0
        public void TestDefaultConnectionString()
        {
            string fixture = new DirectoryInfo("./Fixtures/MSSQL/ConfigWithIntegratedSecurity.xml").FullName;
            XPathDocument doc = new XPathDocument(fixture);
            var nav = doc.CreateNavigator();
            ConnectionStringExtractor cse = new ConnectionStringExtractor(nav, new XmlNamespaceManager(nav.NameTable));
            _executor.Username = "******";
            _executor.Password = "******";
            _executor.Database = "blip";

            cse.LoadConnectionStringInto(@"/configuration/connectionStrings/add[1]/@connectionString",  _executor);
            Assert.AreEqual("fixture1Host", _executor.Host);
            Assert.AreEqual("fixture1Db", _executor.Database);
            // SSPI
            Assert.AreEqual("", _executor.Username);
            Assert.AreEqual("", _executor.Password);
        }
コード例 #2
0
        public void FindConnectionStringByNameInConfigurationWithComments()
        {
            string fixture = new DirectoryInfo("./Fixtures/MSSQL/ConfigWithComments.xml").FullName;

            XPathDocument doc = new XPathDocument(fixture);
            var nav = doc.CreateNavigator();
            ConnectionStringExtractor cse = new ConnectionStringExtractor(nav, new XmlNamespaceManager(nav.NameTable));
            _executor.Username = "******";
            _executor.Password = "******";
            _executor.Database = "blip";
            _executor.Host = "blop";

            cse.LoadConnectionStringInto(@"/configuration/connectionStrings/add[@name='DatabaseConnection']/@connectionString", _executor);
            Assert.AreEqual("fixture6Host", _executor.Host);
            Assert.AreEqual("fixture6Db", _executor.Database);
            Assert.AreEqual("fixture6User", _executor.Username);
            Assert.AreEqual("fixture6Password", _executor.Password);
        }
コード例 #3
0
ファイル: Parser.cs プロジェクト: prunkster/db-migrator-net
        public override Migrator SetCustomOptionsForMigrator(Migrator migrator)
        {
            if (((Options.MSSQL.Options) CurrentOptions).WinAuth)
            {
                migrator.DbInterface.Executor.Username = string.Empty;
                migrator.DbInterface.Executor.Password = string.Empty;
            }

            // Load configuration
            if (!string.IsNullOrEmpty(((Options.MSSQL.Options)CurrentOptions).XmlConfiguration))
            {
                String configurationPath = ((Options.MSSQL.Options)CurrentOptions).XmlConfiguration;
                String xpathExpression = ((Options.MSSQL.Options)CurrentOptions).XpathExpression.Trim('"').Trim('\'');

                var doc = new XPathDocument(configurationPath.Trim('"').Trim('\''));
                var nav = doc.CreateNavigator();
                var ns = new XmlNamespaceManager(nav.NameTable);

                // add namespaces if needed
                if (!string.IsNullOrEmpty(((Options.MSSQL.Options)CurrentOptions).XmlNamespaces))
                {
                    var namespaceOption = ((Options.MSSQL.Options)CurrentOptions).XmlNamespaces.Trim('"').Trim('\'');
                    string[] namespaces = namespaceOption.Split(';');

                    foreach (string userDefinedNamespace in namespaces) {
                        string[] parts = userDefinedNamespace.Split('=');
                        ns.AddNamespace(parts[0], parts[1]);
                    }
                }

                ConnectionStringExtractor cse = new ConnectionStringExtractor(nav, ns);
                cse.LoadConnectionStringInto(xpathExpression, migrator.DbInterface.Executor);
            }

            if (!string.IsNullOrEmpty(migrator.DbInterface.Executor.Username) &&
                string.IsNullOrEmpty(migrator.DbInterface.Executor.Password))
            {
                throw new Exception("You must apply a password for your database username!");
            }

            migrator.Applier.FileEncoding = System.Text.Encoding.GetEncoding(string.IsNullOrEmpty(CurrentOptions.Encoding) ? "ucs-2" : CurrentOptions.Encoding);

            return migrator;
        }