Пример #1
0
        public void Can_await_two_conditions()
        {
            var firstConditionExecuted  = false;
            var secondConditionExecuted = false;
            var initializedEvent        = new AutoResetEvent(false);
            var awaiter = new SpeechJournalAwaiter(cancellation);

            var task = Task.Run(() =>
            {
                awaiter
                .When("word1", entry => firstConditionExecuted  = true)
                .When("word2", entry => secondConditionExecuted = true);
                initializedEvent.Set();
                awaiter.WaitAny();
            });

            initializedEvent.WaitOne(100);
            awaiter.ReceiveJournalEntry(new JournalEntry(0, "TestName", "somethingsomething word2 somethingsomething", new ObjectId(1234),
                                                         (ModelId)4321));

            task.Wait(100);

            firstConditionExecuted.Should().BeFalse();
            secondConditionExecuted.Should().BeTrue();
        }
Пример #2
0
        public void Can_await_one_condition()
        {
            var executed         = false;
            var initializedEvent = new AutoResetEvent(false);
            var awaiter          = new SpeechJournalAwaiter(cancellation);

            var task = Task.Run(() =>
            {
                awaiter.When("test word", entry => executed = true);
                initializedEvent.Set();
                awaiter.WaitAny();
            });

            initializedEvent.WaitOne(100);
            awaiter.ReceiveJournalEntry(new JournalEntry(0, "test", "test word", new ObjectId(1234), (ModelId)4321));
            task.Wait();

            executed.Should().Be(true);
        }
Пример #3
0
        public void Can_await_multiple_words()
        {
            var executed         = false;
            var initializedEvent = new AutoResetEvent(false);
            var awaiter          = new SpeechJournalAwaiter(cancellation);

            var task = Task.Run(() =>
            {
                awaiter
                .When(new[] { "word1", "test word", "word2" }, entry => executed = true);
                initializedEvent.Set();
                awaiter.WaitAny();
            });

            initializedEvent.WaitOneFast();
            awaiter.ReceiveJournalEntry(new JournalEntry(0, "test", "test word", new ObjectId(1234), (ModelId)4321, (Color)0));
            task.AssertWaitFastSuccess();

            executed.Should().Be(true);
        }