コード例 #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 Throws_exception_When_awaiting_timeouts_and_no_timeout_action()
        {
            var source  = new SpeechJournalSource();
            var awaiter = new SpeechJournalAwaiter(cancellation, source);

            source.AddMessage("name1", "message1", 0x12345, 0x1234);

            ((Action)(() => awaiter.WaitAny(TimeSpan.FromMilliseconds(10))))
            .ShouldThrow <TimeoutException>();
        }
コード例 #3
0
        public void Can_execute_action_when_awaiting_timeouts()
        {
            bool executed = false;
            var  awaiter  = new SpeechJournalAwaiter(cancellation);

            awaiter.WhenTimeout(() => executed = true)
            .WaitAny(TimeSpan.FromMilliseconds(10));

            executed.Should().BeTrue();
        }
コード例 #4
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);
        }
コード例 #5
0
        public void Can_cancell_awaiting()
        {
            var initializedEvent = new AutoResetEvent(false);
            var awaiter          = new SpeechJournalAwaiter(cancellation);

            var task = Task.Run(() =>
            {
                Action action = () =>
                {
                    initializedEvent.Set();
                    awaiter.WaitAny();
                };
                action.ShouldThrow <OperationCanceledException>();
            });

            initializedEvent.WaitOne(100);
            cancellationTokenSource.Cancel();
            task.Wait(1000).Should().BeTrue();
        }
コード例 #6
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);
        }