public void TestRepeatedPrefix(string prefix, string firstBody, string secondBody) { //TODO: add a slightly misaligned test var responseDispatcher = new ResponseDispatcher(); var tasks = new List <Task> { Task.Run(() => { // simulate a task calling for the first time var firstResult = responseDispatcher.WaitForResult("r", -1); Assert.AreEqual(firstBody, firstResult); }), Task.Run(() => { // another task calling successively Task.Delay(1).Wait(); var secondResult = responseDispatcher.WaitForResult("r", -1); Assert.AreEqual(secondBody, secondResult); }) }; Task.Delay(100).Wait(); responseDispatcher.FeedMessage(prefix + " " + firstBody); Task.Delay(100).Wait(); responseDispatcher.FeedMessage(prefix + " " + secondBody); Task.WaitAll(tasks.ToArray()); }
public void TestSyncVersion(string prefix, string message) { var feedLine = prefix + " " + message; var responseDispatcher = new ResponseDispatcher(); string waitForResult = null; var taskRegister = Task.Run(() => { waitForResult = responseDispatcher.WaitForResult(prefix); }); var taskDispatcher = Task.Run(() => { Task.Delay(100).Wait(); responseDispatcher.FeedMessage(feedLine); }); Task.WaitAll(taskRegister); Assert.AreEqual(message, waitForResult); }
public void TestFeedAfterTimeout() { var responseDispatcher = new ResponseDispatcher(); Assert.Throws <AggregateException>(() => responseDispatcher.WaitForResult("r")); }