question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

reactive async assertions

See original GitHub issue

We have a system where components embedded in a runtime mainly communicate with each other through events. To test these components (or to specifiy its behavior) I’d like to see more assertions that deal with handling a series of events (asynchronously or synchronously).

Here are some examples:

// assert number of events
sut.ShouldRaiseEvent("SomethingHappened").Exacly.Once;
sut.ShouldRaiseEvent("SomethingHappened").AtLeast(5).Times;
sut.ShouldRaiseEvent("SomethingHappened").NotMoreThan(6).Times;

// assert sequence of events
sut.ShouldRaiseEvent("SomethingHappened").FollowedBy("SomethingElseHappened");
sut.ShouldRaiseEvent("SomethingHappened").WithArgs<SomethingEventArgs>(a => a.Foo = "Bar").FollowedBy("SomethingHappened").WithArgs<SomethingEventArgs>(a => a.Foo = "Bar2");
sut.ShouldRaiseEvent("SomethingHappened").AtLeast(5).Times.FollowedBy("SomethingElseHappened");
sut.ShouldRaiseEvent("SomethingHappened").AtLeast(5).Times.FollowedBy("SomethingHappened").WithArgs<SomethingEventArgs>(a => a.Foo = "Bar");

// assert all of the above in an asynchronous fashion (obvoiously you'd often want a timeout here)
await sut.ShouldRaiseEvent("SomethingHappened").Exactly.Once.Within(Timespan.FromSeconds(1));

// but also without a timeout is possible
await sut.ShouldRaiseEvent("SomethingHappened").Exactly.Once.Eventually;

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
bitbonkcommented, Dec 19, 2014

I guess it is important that I still can use whatever version of reactive extension I choose in the same Appdomain that the tests run in, because the SUT itself might depend on it.

0reactions
dennisdoomencommented, Apr 16, 2015

Yeah, but it’s a big feature. I welcome Pull Requests though 😏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reactive Asynchronous Programming in Java using ...
In Reactive Streams and Reactor, errors are terminal events. As soon as an error occurs, it stops the sequence and gets propagated down...
Read more >
Async method deadlocks with TestScheduler in ReactiveUI
The test hangs when the async call is awaited. The root cause seems to be a command that's awaited in the async method....
Read more >
Lazy and async assertions | Better world by better software
I use assertions in my production code for two reasons. Users always find new ways to go beyond what I expect and test...
Read more >
Testing Asynchronous Code • Angular
This async function executes the code inside its body in a special async test zone. This intercepts and keeps track of all promises...
Read more >
CreateCollection + Testing - pasoft-share/ReactiveUI
Rx lets you easily control the ordering of events to happen in arbitrary combinations that happen in a deterministic way. This means that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found