コード例 #1
0
        public void REFUpdate()
        {
            // start listening for changes
            PostgreSQLListener <FDATask> listener = new PostgreSQLListener <FDATask>("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDASystem; Keepalive = 1;", "fdatasks");

            listener.Notification += Listener_NotificationTasks;
            listener.StartListening();

            currentTest = "UPDATE";
            expectedREF = new RocEventFormats()
            {
                POINTTYPE = 1,
                FORMAT    = 2,
                DescShort = "FAKE-updated",
                DescLong  = "FAKE FORMAT-updated"
            };

            using (NpgsqlConnection conn = new NpgsqlConnection("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDASystem;Keepalive=1"))
            {
                conn.Open();
                string query = "update roceventformats set descshort = 'FAKE-updated',desclong='FAKE FORMAT-updated' where pointtype = 1 and FORMAT = 2";
                using (NpgsqlCommand command = new NpgsqlCommand(query, conn))
                {
                    waiting = true;
                    command.ExecuteNonQuery();
                }

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                while (waiting && stopwatch.ElapsedMilliseconds < waitlimitms)
                {
                    Thread.Sleep(100);
                }
                stopwatch.Stop();

                if (stopwatch.ElapsedMilliseconds >= waitlimitms)
                {
                    Assert.Fail("Notification not received");
                }
                else
                {
                    if (currentTest != resultOperation)
                    {
                        Assert.Fail("Unexpected operation '" + resultOperation + "', expected '" + currentTest + "'");
                    }

                    CompareREFs(expectedREF, resultingREF);
                }
            }
        }
コード例 #2
0
        private void CompareREFs(RocEventFormats expected, RocEventFormats received)
        {
            if (expected.POINTTYPE != received.POINTTYPE)
            {
                Assert.Fail("Unexpected POINTTYPE. expected " + expected.POINTTYPE + ", received " + received.POINTTYPE);
            }

            if (expected.FORMAT != received.FORMAT)
            {
                Assert.Fail("Unexpected FORMAT. expected " + expected.FORMAT + ", received " + received.FORMAT);
            }
            if (expected.DescLong != received.DescLong)
            {
                Assert.Fail("Unexpected DescLong. expected " + expected.DescLong + ", received " + received.DescLong);
            }

            if (expected.DescShort != received.DescShort)
            {
                Assert.Fail("Unexpected DescShort. expected " + expected.DescShort + ", received " + received.DescShort);
            }
        }
コード例 #3
0
 private void Listener_NotificationREF(object sender, PostgreSQLListener <RocEventFormats> .PostgreSQLNotification notifyEvent)
 {
     resultOperation = notifyEvent.Notification.operation;
     resultingREF    = notifyEvent.Notification.row;
     waiting         = false;
 }
コード例 #4
0
        public void REFInsert()
        {
            // create an REF
            RocEventFormats original = new RocEventFormats()
            {
                POINTTYPE = 1,
                FORMAT    = 2,
                DescShort = "FAKE",
                DescLong  = "FAKE FORMAT"
            };


            // start listening for changes
            PostgreSQLListener <RocEventFormats> listener = new PostgreSQLListener <RocEventFormats>("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDASystem; Keepalive = 1;", "roceventformats");

            listener.Notification += Listener_NotificationREF;
            listener.StartListening();

            currentTest = "INSERT";

            expectedREF = new RocEventFormats()
            {
                POINTTYPE = 1,
                FORMAT    = 2,
                DescShort = "FAKE",
                DescLong  = "FAKE FORMAT"
            };

            using (NpgsqlConnection conn = new NpgsqlConnection("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDASystem;Keepalive=1"))
            {
                conn.Open();
                string query = "insert into RocEventFormats (pointtype,format,descshort,desclong) values (1,2,'FAKE','FAKE FORMAT');";
                using (NpgsqlCommand command = new NpgsqlCommand(query, conn))
                {
                    waiting = true;
                    command.ExecuteNonQuery();
                }

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                while (waiting && stopwatch.ElapsedMilliseconds < waitlimitms)
                {
                    Thread.Sleep(100);
                }
                stopwatch.Stop();

                if (stopwatch.ElapsedMilliseconds >= waitlimitms)
                {
                    Assert.Fail("Notification not received");
                }
                else
                {
                    if (currentTest != resultOperation)
                    {
                        Assert.Fail("Unexpected operation '" + resultOperation + "', expected '" + currentTest + "'");
                    }

                    CompareREFs(expectedREF, resultingREF);
                }
            }
        }