public void Lastaction_is_not_affected_by_actions_on_another_thread() { var source = new SpeechJournalSource(); var scriptJournal = new SpeechJournal(source); var nextScriptStep = new AutoResetEvent(false); var nextOtherThreadStep = new AutoResetEvent(false); bool message1Received = false; bool message2Received = false; var scriptTask = Task.Run(() => { source.NotifyAction(); nextOtherThreadStep.Set(); nextScriptStep.WaitOne(); scriptJournal .When("message 1", () => message1Received = true) .When("message 2", () => message2Received = true) .WaitAny(); }); nextOtherThreadStep.WaitOne(); source.AddMessage("name", "message 1", 0, 0); source.NotifyAction(); source.AddMessage("name", "message 2", 0, 0); nextScriptStep.Set(); scriptTask.Wait(100).Should().BeTrue(); message1Received.Should().BeTrue(); message2Received.Should().BeFalse(); }
public void Can_await_entries_received_between_lastaction_and_WaitAny() { bool executed = false; var source = new SpeechJournalSource(); var journal = new SpeechJournal(source, null); source.AddMessage("name", "before last action", new ObjectId(0), 0); source.NotifyAction(); source.AddMessage("name", "after last action", new ObjectId(0), 0); journal.When("after last action", () => executed = true).WaitAny(TimeSpan.FromMilliseconds(100)); executed.Should().BeTrue(); }
public void Doesnt_await_entries_received_before_lastaction() { bool executed = false; bool timeoutExecuted = false; var source = new SpeechJournalSource(); var journal = new SpeechJournal(source, null); source.AddMessage("name", "before last action", new ObjectId(0), 0, (Color)0); source.NotifyAction(); source.AddMessage("name", "after last action", new ObjectId(0), 0, (Color)0); journal.When("before last action", () => executed = true).WhenTimeout(() => timeoutExecuted = true).WaitAny(TimeSpan.FromMilliseconds(10)); timeoutExecuted.Should().BeTrue(); executed.Should().BeFalse(); }