Beispiel #1
0
            public void Indirect_Task_No_Transform_Is_Error()
            {
                //Arrange
                var functions    = new Mock <Functions>();
                var target       = new AsyncManager(functions.Object);
                var namespaceCtx = new IntPtr(37);

                //Act
                var hr = target.ProcessCommandPossibleAsync(namespaceCtx, 1, (Func <CancellationTokenSource, Task>)((cts) => Task.FromException(new Exception())));

                //Assert
                Assert.Equal(HRESULT.E_INVALIDARG, hr);
            }
Beispiel #2
0
            public void Task_With_Transform_Is_Other_Result()
            {
                //Arrange
                var functions    = new Mock <Functions>();
                var target       = new AsyncManager(functions.Object);
                var namespaceCtx = new IntPtr(37);

                //Act
                var hr = target.ProcessCommandPossibleAsync(namespaceCtx, 1, (cts) => Task.FromResult(4), (value) => HRESULT.S_FALSE);

                //Assert
                Assert.Equal(HRESULT.S_FALSE, hr);
            }
Beispiel #3
0
            public void Direct_Task_Transform_With_Error_In_Transform_Is_Error()
            {
                //Arrange
                var functions    = new Mock <Functions>();
                var target       = new AsyncManager(functions.Object);
                var namespaceCtx = new IntPtr(37);

                //Act
                var hr = target.ProcessCommandPossibleAsync <int>(namespaceCtx, 1, (cts) => Task.FromResult(1), (value) => throw new Exception());

                //Assert
                Assert.Equal(HRESULT.E_INVALIDARG, hr);
            }
Beispiel #4
0
            public void ValueTask_No_Transform_Is_S_OK()
            {
                //Arrange
                var functions    = new Mock <Functions>();
                var target       = new AsyncManager(functions.Object);
                var namespaceCtx = new IntPtr(37);

                //Act
                var hr = target.ProcessCommandPossibleAsync(namespaceCtx, 1, (cts) => new ValueTask());

                //Assert
                Assert.Equal(HRESULT.S_OK, hr);
            }
Beispiel #5
0
            public void Indirect_Task_Transform_With_Error_In_Kickoff_Is_Error()
            {
                //Arrange
                var functions    = new Mock <Functions>();
                var target       = new AsyncManager(functions.Object);
                var namespaceCtx = new IntPtr(37);
                var tcs          = new TaskCompletionSource <int>();

                tcs.SetException(new Exception());

                //Act
                var hr = target.ProcessCommandPossibleAsync <int>(namespaceCtx, 1, (cts) => tcs.Task, UncalledCallback <int>);

                //Assert
                Assert.Equal(HRESULT.E_INVALIDARG, hr);
            }
Beispiel #6
0
            public async Task Task_With_Transform_Is_Other_Result()
            {
                //Arrange
                var functions    = new Mock <Functions>();
                var namespaceCtx = new IntPtr(37);

                functions.Setup(f => f.PrjCompleteCommand(namespaceCtx, 1, HRESULT.S_FALSE, IntPtr.Zero));
                var tcs    = new TaskCompletionSource <int>();
                var target = new AsyncManager(functions.Object);

                //Act
                var hr = target.ProcessCommandPossibleAsync(namespaceCtx, 1, (cts) => tcs.Task, (value) => HRESULT.S_FALSE);

                tcs.SetResult(4);
                await Task.Delay(50);

                //Assert
                Assert.Equal(HRESULT.ERROR_IO_PENDING, hr);
                functions.VerifyAll();
            }
Beispiel #7
0
            public async Task Direct_Task_Transform_With_Error_In_Transform_Is_Error()
            {
                //Arrange
                var functions    = new Mock <Functions>();
                var namespaceCtx = new IntPtr(37);

                functions.Setup(f => f.PrjCompleteCommand(namespaceCtx, 1, HRESULT.E_INVALIDARG, IntPtr.Zero));
                var tcs    = new TaskCompletionSource <int>();
                var target = new AsyncManager(functions.Object);

                //Act
                var hr = target.ProcessCommandPossibleAsync <int>(namespaceCtx, 1, (cts) => tcs.Task, (value) => throw new Exception());

                tcs.SetResult(4);
                await Task.Delay(50);

                //Assert
                Assert.Equal(HRESULT.ERROR_IO_PENDING, hr);
                functions.VerifyAll();
            }
Beispiel #8
0
            public async Task Direct_ValueTask_No_Transform_Is_Error()
            {
                //Arrange
                var functions    = new Mock <Functions>();
                var namespaceCtx = new IntPtr(37);

                functions.Setup(f => f.PrjCompleteCommand(namespaceCtx, 1, HRESULT.E_INVALIDARG, IntPtr.Zero));
                var tcs    = new TaskCompletionSource <NotificationRequired>();
                var target = new AsyncManager(functions.Object);

                //Act
                var hr = target.ProcessCommandPossibleAsync(namespaceCtx, 1, (Func <CancellationTokenSource, ValueTask>)((cts) => new ValueTask(tcs.Task)));

                tcs.SetException(new Exception());
                await Task.Delay(50);

                //Assert
                Assert.Equal(HRESULT.ERROR_IO_PENDING, hr);
                functions.VerifyAll();
            }