I found the answer to this in some posts in the net. But i always forgot it and find my self looking for it again, so i will post the solution Im using here for future reference.
[Test]
public void during_single_load_getting_two_barcode_raises_event_with_them()
{
var eventRaised = false;
dispenserProcessManager = CreateStubbedDispenserManager();
var barcodes = new[] { "4444455555", "4444455556" };
busterManager.Stub(bm => bm.GetSingleLoadBarcodes(Context.TelephoneType)).Return(barcodes);
dispenserProcessManager.BarcodesRead += (sender, collection) =>
{
collection.Elements.Count().Should().Be.EqualTo(2);
collection.Elements.Should().Contain(barcodes[0]);
collection.Elements.Should().Contain(barcodes[1]);
eventRaised = true;
};
dispenserProcessManager.SingleLoad();
eventRaised.Should().Be.True();
}
Inside the event i’m checking that the event was raised with the right data, and i set the eventraised variable to true. At the end i check that i really hit that line.
The Should() syntax is a handy way of asserting (at least for me) using NunitEx
1 comments:
Only a little short-cut
collection.Elements
.Should().Contain(barcodes[0])
.And.Contain(barcodes[1]);
Post a Comment