Ejemplo n.º 1
0
        public async Task DispatchAndWrapAsyncBase_calls_error_callback_on_exception_base_signature()
        {
            // Arrange
            var exception = 0;

            // Act
            void Callback() => throw new Exception();

            await AsyncWrapperBase.DispatchAndWrapAsyncBase(
                Callback,
                e => Interlocked.Increment(ref exception));

            // Assert
            Assert.AreEqual(1, exception);
        }
Ejemplo n.º 2
0
        public async Task DispatchAndWrapAsyncBase_Nominal()
        {
            // Arrange
            var count     = 0;
            var exception = 0;

            // Act
            await AsyncWrapperBase.DispatchAndWrapAsyncBase(
                () => Interlocked.Increment(ref count),
                e => Interlocked.Increment(ref exception));

            // Assert
            Assert.AreEqual(1, count);
            Assert.AreEqual(0, exception);
        }
Ejemplo n.º 3
0
        public async Task DispatchAndWrapAsyncBase_with_exception_And_No_OnError_Callback()
        {
            // Arrange
            var count = 0;

            // Act
            await AsyncWrapperBase.DispatchAndWrapAsyncBase(
                () =>
            {
                Interlocked.Increment(ref count);
                throw new Exception();
            },
                null);

            // Assert
            Assert.AreEqual(1, count);
        }
Ejemplo n.º 4
0
        public async Task DispatchAndWrapAsyncBase_Nominal_With_Return()
        {
            // Arrange
            var exception = 0;

            // Act
            var res = await AsyncWrapperBase.DispatchAndWrapAsyncBase(
                () =>
            {
                return(78);
            },
                e => Interlocked.Increment(ref exception));

            // Assert
            Assert.AreEqual(78, res);
            Assert.AreEqual(0, exception);
        }
Ejemplo n.º 5
0
        public async Task DispatchAndWrapAsyncBase_Exception_Finally()
        {
            // Arrange
            var finallyCalls = 0;
            var exception    = 0;

            // Act
            await AsyncWrapperBase.DispatchAndWrapAsyncBase(
                () =>
            {
                throw new Exception();
            },
                e => Interlocked.Increment(ref exception),      // On exception
                () => Interlocked.Increment(ref finallyCalls)); // On finally

            // Assert
            Assert.AreEqual(1, finallyCalls);
            Assert.AreEqual(1, exception);
        }
Ejemplo n.º 6
0
        public async Task DispatchAndWrapAsyncBase_with_exception_on_finally()
        {
            // Arrange
            var count        = 0;
            var countFinally = 0;

            // Act
            await AsyncWrapperBase.DispatchAndWrapAsyncBase(
                () => Interlocked.Increment(ref count),
                null,
                () =>
            {
                Interlocked.Increment(ref countFinally);
                throw new Exception();
            });

            // Assert
            Assert.AreEqual(1, count);
            Assert.AreEqual(1, countFinally);
        }
Ejemplo n.º 7
0
        public async Task DispatchAndWrapAsyncBase_Nominal_Async_Exception()
        {
            // Arrange
            var count     = 0;
            var exception = 0;

            // Act
            await AsyncWrapperBase.DispatchAndWrapAsyncBase(
                async() =>
            {
                await Task.Delay(50);
                Interlocked.Increment(ref count);
                throw new Exception();
            },
                e => Interlocked.Increment(ref exception));

            // Assert
            Assert.AreEqual(1, count);
            Assert.AreEqual(1, exception);
        }
Ejemplo n.º 8
0
        public async Task WrapAsync_call_exception_callback_on_error()
        {
            // Arrange
            var exception = 0;

            // Act
            await AsyncWrapperBase.WrapAsync(
                async() =>
            {
                await Task.Delay(50);
                if (exception == 0)
                {
                    throw new Exception();
                }
                return(78);
            },
                e => Interlocked.Increment(ref exception));

            // Assert
            Assert.AreEqual(1, exception);
        }
Ejemplo n.º 9
0
        public async Task DispatchAndWrapAsyncBase_calls_error_callback_on_exception()
        {
            // Arrange
            var exception = 0;

            // Act
            var res = await AsyncWrapperBase.DispatchAndWrapAsyncBase(
                () =>
            {
                if (exception == 0)
                {
                    // only to be sure to get the correct signature
                    throw new Exception();
                }
                return(1);
            },
                e => Interlocked.Increment(ref exception));

            // Assert
            Assert.AreEqual(1, exception);
        }