Npgsql.Tests.ConnectionTests.Notice C# (CSharp) Method

Notice() private method

private Notice ( ) : void
return void
        public void Notice()
        {
            using (var conn = OpenConnection())
            {
                // Make sure messages are in English
                conn.ExecuteNonQuery(@"SET lc_messages='en_US.UTF8'");
                conn.ExecuteNonQuery(@"
                        CREATE OR REPLACE FUNCTION pg_temp.emit_notice() RETURNS VOID AS
                        'BEGIN RAISE NOTICE ''testnotice''; END;'
                        LANGUAGE 'plpgsql';
                ");

                PostgresNotice notice = null;
                NoticeEventHandler action = (sender, args) => notice = args.Notice;
                conn.Notice += action;
                try
                {
                    conn.ExecuteNonQuery("SELECT pg_temp.emit_notice()::TEXT"); // See docs for CreateSleepCommand
                    Assert.That(notice, Is.Not.Null, "No notice was emitted");
                    Assert.That(notice.MessageText, Is.EqualTo("testnotice"));
                    Assert.That(notice.Severity, Is.EqualTo("NOTICE"));
                }
                finally
                {
                    conn.Notice -= action;
                }
            }
        }