Udostępnij za pośrednictwem


CCR tips and tricks - part 25

In the very first CCR tips and tricks I gave you a utility to essentially make CCR code synchronous to make unit testing simpler. Well, with the release of RDS4 beta there is a nice addition in the IO.Adapters assembly. The synchronous arbiter essentially does the job of the PortUtility you've previously seen. All you need is this namespace:

  1: using Microsoft.Ccr.Adapters.IO;

And then this code using the PortUtility (assuming PortUtility is created in test constructor):

  1: portUtility.Choice(
 2:     resultPort, 
 3:     s => streamContent = s, 
 4:     e => Assert.Fail("Unexpected failure: " + e.ToString()));

Will look like this:

  1: using (var syncArbiter = new SynchronousArbiter())
 2: {
 3:     Assert.IsTrue(syncArbiter.Choice(
 4:         resultPort, 
 5:         s => streamContent = s, 
 6:         e => Assert.Fail("Unexpected failure: " + e.ToString()),
 7:         TimeSpan.FromSeconds(5)));
 8: }

What I've seen is that in unit tests and also in a few other occasions where you use CCR outside of the Robotics space, a synchronous arbiter makes sense. And now it's part of CCR for you to use. Enjoy!