Esempio n. 1
0
        protected virtual IEnumerable <UoeDatabaseConnection> GetDatabaseConnections(bool addDatabasesInCurrentDirectory, bool throwWhenNoDatabaseFound)
        {
            var nbYield = 0;

            foreach (var connection in DatabaseConnections.ToNonNullEnumerable().Where(c => !string.IsNullOrEmpty(c)))
            {
                foreach (var databaseConnection in UoeDatabaseConnection.GetConnectionStrings(connection))
                {
                    nbYield++;
                    yield return(databaseConnection);
                }
            }
            var ope = GetOperator();

            foreach (var path in DatabasePaths.ToNonNullEnumerable().Where(d => !string.IsNullOrEmpty(d)))
            {
                nbYield++;
                var loc = new UoeDatabaseLocation(path);
                loc.ThrowIfNotExist();
                yield return(ope.GetDatabaseConnection(loc));
            }
            if (!addDatabasesInCurrentDirectory && throwWhenNoDatabaseFound)
            {
                throw new CommandException($"You must specify a database connection string using the option {OptionDatabaseConnectionShortName.PrettyQuote()} or a database path by using the option {OptionDatabaseFileShortName.PrettyQuote()}.");
            }
            if (nbYield > 0 || !addDatabasesInCurrentDirectory)
            {
                yield break;
            }
            foreach (var databaseLocation in GetDatabaseLocationsFromCd(throwWhenNoDatabaseFound))
            {
                databaseLocation.ThrowIfNotExist();
                yield return(ope.GetDatabaseConnection(databaseLocation));
            }
        }
        public void GetConnectionStrings_Except(string input)
        {
            Exception e = null;

            try {
                var list = UoeDatabaseConnection.GetConnectionStrings(input);
                Assert.AreEqual(1, list.Count());
            } catch (UoeDatabaseConnectionParseException ex) {
                e = ex;
            }
            Assert.IsNotNull(e);
        }
 public void GetConnectionString(string input, string output)
 {
     output = output.Replace(@"""data""", Path.Combine(Directory.GetCurrentDirectory(), "data.db").ToQuotedArg());
     Assert.AreEqual(output, new UoeProcessArgs().Append(UoeDatabaseConnection.GetConnectionStrings(input)).ToQuotedArgs());
 }
        public void GetConnectionStrings_NumberOfCsReturned(string input, int nb)
        {
            var list = UoeDatabaseConnection.GetConnectionStrings(input);

            Assert.AreEqual(nb, list.Count());
        }