Part 1 on testing the subscriptions here.
Now that we’ve tested that our event aggregator is subscribed correctly, all that remains is to test that the code behaves as expected when a LoginSuccessful event is published. In order to check whether it was successfully listened to, I’ve changed our demo code to set a boolean to true once a LoginSuccessful event is published.
Now to test this all we have to do is simulate a LoginSuccessful event and publish it to an event aggregator and then assert that our boolean value is set to true. In our test we create a REAL event, a REAL demo class (the one we’re testing) and a fake event aggregator.
We tell the aggregator to return our real event when asked for one. Then we force our event to publish a success case and assert against the results.
For completeness we need to test the opposite: a login that is not a success results in a false boolean.
And that’s our event aggregator logic in the EventAggregatorDemo class tested. Obviously this example was simple, but the concepts follow through to real-world scenarios as well.
No comments have been posted yet