public void WaitAny_chekcs_only_entries_created_afer_last_check() { var source = new SpeechJournalSource(); var journal = new SpeechJournal(source, null); bool firstCheckExecuted = false; bool secondCheckExecuted = false; source.AddMessage("name", "message1", new ObjectId(0), 0); journal.When("message1", () => { firstCheckExecuted = true; }).WhenTimeout(() => { }).WaitAny(TimeSpan.FromMilliseconds(1)); journal.When("message1", () => { secondCheckExecuted = true; }).WhenTimeout(() => { }).WaitAny(TimeSpan.FromMilliseconds(1)); firstCheckExecuted.Should().BeTrue(); secondCheckExecuted.Should().BeFalse(); }
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 ContainsAnyWord_is_not_affected_by_previous_call_to_WaitAny() { var source = new SpeechJournalSource(); var journal = new SpeechJournal(source, null); source.AddMessage("name", "message1", new ObjectId(0), 0); journal.When("message1", () => { }).WaitAny(TimeSpan.FromMilliseconds(1)); journal.ContainsAnyWord("message1").Any().Should().BeTrue(); }
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 When_is_case_insensitive_by_default_when_waiting_and_already_in_journal() { var source = new SpeechJournalSource(); var journal = new SpeechJournal(source); source.AddMessage("name", "cas InSeNsItIvE", new ObjectId(0), 0); bool executed = false; journal.When("insensitive", () => executed = true) .WaitAny(TimeSpan.FromMilliseconds(100)); executed.Should().BeTrue(); }
public void WaitAny_cannot_see_entry_received_before_journal_deletion() { var source = new SpeechJournalSource(); var journal = new SpeechJournal(source, null); source.AddMessage("name", "message before delete", new ObjectId(0), 0); journal.Delete(); bool canSeeMessageBeforeDelete = false; journal.When("message before delete", e => canSeeMessageBeforeDelete = true) .WhenTimeout(() => { }) .WaitAny(TimeSpan.FromMilliseconds(1)); canSeeMessageBeforeDelete.Should().BeFalse(); }
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(); }
public void When_is_case_insensitive_by_default_when_waiting() { var source = new SpeechJournalSource(); var journal = new SpeechJournal(source, null); bool executed = false; var task = Task.Run(() => { journal.When("insensitive", () => executed = true) .WaitAny(TimeSpan.FromMilliseconds(250)); }); Thread.Sleep(25); source.AddMessage("name", "InSeNsItIvE", new ObjectId(0), 0); task.Wait(); executed.Should().BeTrue(); }