Beispiel #1
0
        public void PostgreServer_CreateCommand_ConnectionNotInitialized_ThrowsConnectFirstException()

        {
            //------------Setup for test--------------------------
            var sqlServer = new PostgreServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.CreateCommand();

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Beispiel #2
0
        public void PostgreServer_CreateCommand_CreateCommand()

        {
            //------------Setup for test--------------------------
            var factory     = new Mock <IDbFactory>();
            var mockCommand = new Mock <IDbCommand>();

            mockCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
            var added = new SqlCommand().Parameters;

            mockCommand.Setup(a => a.Parameters).Returns(added);
            var helpTextCommand = new Mock <IDbCommand>();

            helpTextCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            var dt = new DataTable();

            dt.Columns.Add("database_name");
            dt.Rows.Add(new object[] { "Bob" });
            dt.Rows.Add(new object[] { "Dave" });
            factory.Setup(a => a.GetSchema(It.IsAny <IDbConnection>(), "Databases")).Returns(dt);
            var conn = new Mock <IDbConnection>();

            conn.Setup(a => a.State).Returns(ConnectionState.Open);
            conn.Setup(a => a.ConnectionString).Returns("bob");
            conn.Setup(a => a.CreateCommand()).Returns(mockCommand.Object);
            factory.Setup(a => a.CreateConnection(It.IsAny <string>())).Returns(conn.Object);
            var sqlServer = new PostgreServer(factory.Object);

            try
            {
                var pvt = new PrivateObject(sqlServer);
                pvt.SetField("_connection", conn.Object);
                //------------Execute Test---------------------------
                sqlServer.CreateCommand();
                conn.Verify(a => a.CreateCommand());
            }
            finally
            {
                sqlServer.Dispose();
            }
        }