Exemplo n.º 1
0
        public static void test_async_cancel()
        {
            efl.ILoop     loop = efl.App.GetLoopMain();
            test.ITesting obj  = new test.Testing();

            CancellationTokenSource cancelSrc = new CancellationTokenSource();
            Task <eina.Value>       task      = obj.GetFutureAsync(cancelSrc.Token);

            cancelSrc.Cancel();
            loop.Iterate();

            bool raised = false;

            try
            {
                eina.Value v = task.Result;
            }
            catch (AggregateException ae)
            {
                raised = true;
                ae.Handle((x) =>
                {
                    Test.Assert(x is TaskCanceledException, "AggregateException must have been TaskCanceledException");
                    return(true);
                });
            }

            Test.Assert(raised, "AggregateException must have been raised.");
        }
Exemplo n.º 2
0
        public static void test_async_reject()
        {
            efl.ILoop     loop = efl.App.GetLoopMain();
            test.ITesting obj  = new test.Testing();

            Task <eina.Value> task = obj.GetFutureAsync();

            eina.Error sentError = 1337;
            obj.RejectPromise(sentError);

            loop.Iterate();

            bool raised = false;

            try
            {
                eina.Value v = task.Result;
            }
            catch (AggregateException ae)
            {
                raised = true;
                ae.Handle((x) =>
                {
                    Test.Assert(x is efl.FutureException, "AggregateException must have been TaskCanceledException");
                    efl.FutureException ex = x as efl.FutureException;
                    Test.AssertEquals(ex.Error, sentError);
                    return(true);
                });
            }

            Test.Assert(raised, "AggregateException must have been raised.");
        }
Exemplo n.º 3
0
        public static void test_async_fulfill()
        {
            efl.ILoop     loop = efl.App.GetLoopMain();
            test.ITesting obj  = new test.Testing();

            Task <eina.Value> task = obj.GetFutureAsync();

            int sentValue = 1337;

            obj.FulfillPromise(sentValue);
            loop.Iterate();

            eina.Value v = task.Result;
            Test.AssertEquals(v.GetValueType(), eina.ValueType.Int32);

            int receivedValue;

            v.Get(out receivedValue);
            Test.AssertEquals(receivedValue, sentValue);
        }