Пример #1
0
        public async Task ProperCountsSingleTest()
        {
            var exception = (Exception)null;
            var triggered = false;

            await using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventError += (sender, e) =>
                {
                    exception = e.Error;
                };
                @event.RemoteEventCounts += (sender, e) =>
                {
                    triggered = e.Name == "test" && e.Counts == 5;
                };
                await @event.OpenAsync();

                await @event.QueueEventsAsync(new[] { "test" });

                await using (var cmd = Connection.CreateCommand())
                {
                    cmd.CommandText = "execute block as begin post_event 'test'; post_event 'test'; post_event 'test'; post_event 'test'; post_event 'test'; end";
                    await cmd.ExecuteNonQueryAsync();

                    Thread.Sleep(2000);
                }
                Assert.IsNull(exception);
                Assert.IsTrue(triggered);
            }
        }
Пример #2
0
        public async Task NoEventsAfterDispose()
        {
            var triggered = 0;

            await using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventCounts += (sender, e) =>
                {
                    triggered++;
                };
                await @event.OpenAsync();

                await @event.QueueEventsAsync(new[] { "test" });

                Thread.Sleep(2000);
            }
            Thread.Sleep(2000);
            await using (var cmd = Connection.CreateCommand())
            {
                cmd.CommandText = "execute block as begin post_event 'test'; end";
                await cmd.ExecuteNonQueryAsync();

                Thread.Sleep(2000);
            }
            Assert.AreEqual(0, triggered);
        }
Пример #3
0
        public async Task DoubleQueueingTest()
        {
            await using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                await @event.OpenAsync();

                Assert.DoesNotThrowAsync(() => @event.QueueEventsAsync(new[] { "test" }));
                Assert.ThrowsAsync <InvalidOperationException>(() => @event.QueueEventsAsync(new[] { "test" }));
            }
        }
Пример #4
0
        public async Task EventNameSeparateSelectionTest()
        {
            var exception  = (Exception)null;
            var triggeredA = false;
            var triggeredB = false;

            await using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventError += (sender, e) =>
                {
                    exception = e.Error;
                };
                @event.RemoteEventCounts += (sender, e) =>
                {
                    switch (e.Name)
                    {
                    case "a":
                        triggeredA = e.Counts == 1;
                        break;

                    case "b":
                        triggeredB = e.Counts == 1;
                        break;
                    }
                };
                await @event.OpenAsync();

                await @event.QueueEventsAsync(new[] { "a", "b" });

                await using (var cmd = Connection.CreateCommand())
                {
                    cmd.CommandText = "execute block as begin post_event 'b'; end";
                    await cmd.ExecuteNonQueryAsync();

                    cmd.CommandText = "execute block as begin post_event 'a'; end";
                    await cmd.ExecuteNonQueryAsync();

                    Thread.Sleep(2000);
                }
                Assert.IsNull(exception);
                Assert.IsTrue(triggeredA);
                Assert.IsTrue(triggeredB);
            }
        }
Пример #5
0
        public async Task NoExceptionWithDispose()
        {
            var exception = (Exception)null;

            await using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventError += (sender, e) =>
                {
                    exception = e.Error;
                };
                await @event.OpenAsync();

                await @event.QueueEventsAsync(new[] { "test" });

                Thread.Sleep(2000);
            }
            Thread.Sleep(2000);
            Assert.IsNull(exception);
        }
Пример #6
0
        public async Task CancelTest()
        {
            var exception = (Exception)null;
            var triggered = 0;

            await using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventError += (sender, e) =>
                {
                    exception = e.Error;
                };
                @event.RemoteEventCounts += (sender, e) =>
                {
                    triggered++;
                };
                await @event.OpenAsync();

                await @event.QueueEventsAsync(new[] { "test" });

                await using (var cmd = Connection.CreateCommand())
                {
                    cmd.CommandText = "execute block as begin post_event 'test'; end";
                    await cmd.ExecuteNonQueryAsync();

                    Thread.Sleep(2000);
                }
                await @event.CancelEventsAsync();

                await using (var cmd = Connection.CreateCommand())
                {
                    cmd.CommandText = "execute block as begin post_event 'test'; end";
                    await cmd.ExecuteNonQueryAsync();

                    Thread.Sleep(2000);
                }
                Assert.IsNull(exception);
                Assert.AreEqual(1, triggered);
            }
        }