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); } }
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); }
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" })); } }
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); } }
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); }
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); } }