Ejemplo n.º 1
0
        public void ShouldNotAutomaticallyOpenConnection()
        {
            var mock = A.Fake <DbConnection>();

            A.CallTo(() => connectionManager.GetConnection(A <string> .Ignored)).Returns(mock);

            jobStore.ExecuteGetNonManagedConnection();

            A.CallTo(() => mock.Open()).MustNotHaveHappened();
        }
        public WordProbability GetWordProbability(string category, string word)
        {
            WordProbability wp               = null;
            var             matchingCount    = 0;
            var             nonMatchingCount = 0;

            OdbcConnection connection = null;

            try
            {
                connection = (OdbcConnection)connectionManager.GetConnection();
                IDbCommand command = new OdbcCommand("SELECT " + matchCountColumn + ", " + nonMatchCountColumn + " FROM " + tableName + " WHERE " + wordColumn + " = ? AND " + categoryColumn + " = ?", connection);
                command.Parameters.Add(new OdbcParameter("@Word", OdbcType.VarChar, 255, ParameterDirection.Input, true, 0, 0, string.Empty, DataRowVersion.Proposed, word));
                command.Parameters.Add(new OdbcParameter("@Category", OdbcType.VarChar, 20, ParameterDirection.Input, true, 0, 0, string.Empty, DataRowVersion.Proposed, category));
                var reader = command.ExecuteReader();
                if (reader.Read())
                {
                    matchingCount    = (int)reader[matchCountColumn];
                    nonMatchingCount = (int)reader[nonMatchCountColumn];
                }
                reader.Close();
                wp          = new WordProbability(word, matchingCount, nonMatchingCount);
                wp.Category = category;
            }
            catch (Exception ex)
            {
                throw new WordsDataSourceException("Problem obtaining WordProbability from database.", ex);
            }
            finally
            {
                if (connection != null)
                {
                    try
                    {
                        connectionManager.ReturnConnection(connection);
                    }
                    catch {}
                }
            }

            Debug.WriteLine("GetWordProbability() WordProbability loaded [" + wp + "]");

            return(wp);
        }
Ejemplo n.º 3
0
 public ChannelRepository(IDbConnectionManager connectionFactory)
     : base(connectionFactory)
 {
     var f = connectionFactory.GetConnection();
 }