I have always got around this problem by - unfortunately - using events less. However this time I came up with a nifty trick, however I don't think the following would be considered a proper approach. Is there a recommended method to achieve the same results?
NB Without the while you get a null reference exception on the _args.Fixture unless you breakpoint on it - race condition.
private Parser _parser;
private ParsedArgs _args;
[TestFixtureSetUp]
public void Setup()
{
_parser = new Parser();
_parser.DataParsed += DataParsed;
}
void DataParsed(object sender, ParsedArgs e)
{
_args = e;
}
[Test]
public void TestDocParse()
{
_parser.ParseFixture(File.ReadAllText(EventDataPath));
while (_args == null || _args.Fixture == null) { }
Assert.IsNotNull(_args.Fixture);
var fixture = _args.Fixture;
Assert.AreEqual("2F7PY1662477", fixture.Id);
}
I found that the following led to having to think up a potentially inaccurate timescale for the parsing to have completed...
I am aiming to test that the fixture.Id is equal to "2F7PY1662477".
Thanks