예제 #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_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);
        }
예제 #4
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();
        }
예제 #5
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);
        }