Exemple #1
0
        public static Connection GetConnection()
        {
            Connection connection = Org.Mockito.Mockito.Mock <DriverForTest.FakeConnection>();

            try
            {
                Statement statement = Org.Mockito.Mockito.Mock <Statement>();
                ResultSet results   = Org.Mockito.Mockito.Mock <ResultSet>();
                Org.Mockito.Mockito.When(results.GetLong(1)).ThenReturn(15L);
                Org.Mockito.Mockito.When(statement.ExecuteQuery(Matchers.Any <string>())).ThenReturn
                    (results);
                Org.Mockito.Mockito.When(connection.CreateStatement()).ThenReturn(statement);
                DatabaseMetaData metadata = Org.Mockito.Mockito.Mock <DatabaseMetaData>();
                Org.Mockito.Mockito.When(metadata.GetDatabaseProductName()).ThenReturn("Test");
                Org.Mockito.Mockito.When(connection.GetMetaData()).ThenReturn(metadata);
                PreparedStatement reparedStatement0 = Org.Mockito.Mockito.Mock <PreparedStatement>
                                                          ();
                Org.Mockito.Mockito.When(connection.PrepareStatement(AnyString())).ThenReturn(reparedStatement0
                                                                                              );
                PreparedStatement preparedStatement = Org.Mockito.Mockito.Mock <PreparedStatement>
                                                          ();
                ResultSet resultSet = Org.Mockito.Mockito.Mock <ResultSet>();
                Org.Mockito.Mockito.When(resultSet.Next()).ThenReturn(false);
                Org.Mockito.Mockito.When(preparedStatement.ExecuteQuery()).ThenReturn(resultSet);
                Org.Mockito.Mockito.When(connection.PrepareStatement(AnyString(), AnyInt(), AnyInt
                                                                         ())).ThenReturn(preparedStatement);
            }
            catch (SQLException)
            {
            }
            return(connection);
        }
Exemple #2
0
 /// <exception cref="Java.Sql.SQLException"/>
 protected internal virtual ResultSet ExecuteQuery(string query)
 {
     this.statement = connection.PrepareStatement(query, ResultSet.TypeForwardOnly, ResultSet
                                                  .ConcurReadOnly);
     return(statement.ExecuteQuery());
 }