Esempio n. 1
0
        public void GetResult_ThrowOnBackgroundThread() {
            var cts = new CancellationTokenSource();
            var awaitable = new MainThreadAwaitable(_mainThread, cts.Token);
            cts.Cancel();

            Action a = () => awaitable.GetAwaiter().GetResult();
            a.ShouldThrow<OperationCanceledException>();
        }
Esempio n. 2
0
        public async Task Await_OnDispatcherThread() {
            var awaitable = new MainThreadAwaitable(_mainThread);

            await awaitable;

            Thread.CurrentThread.ManagedThreadId.Should().Be(_mainThread.ThreadId);
            Action a = () => awaitable.GetAwaiter().GetResult();
            a.ShouldNotThrow();
        }
Esempio n. 3
0
        public void IsCompleleted_DispatcherThread() {
            var awaitable = new MainThreadAwaitable(_mainThread);

            Thread.CurrentThread.ManagedThreadId.Should().Be(_mainThread.ThreadId);
            awaitable.GetAwaiter().IsCompleted.Should().Be(true);
        }
Esempio n. 4
0
        public void IsCompleleted_BackgroundThread() {
            var awaitable = new MainThreadAwaitable(_mainThread);

            Thread.CurrentThread.ManagedThreadId.Should().NotBe(_mainThread.ThreadId);
            awaitable.GetAwaiter().IsCompleted.Should().Be(false);
        }