Exemplo n.º 1
0
        static Task RunArbitraryFn(CancellationToken cancel, FnInner fn)
        {
            var tcs = new TaskCompletionSource <bool>();

            try
            {
                var thread = new Thread(new ThreadStart(() =>
                {
                    try
                    {
                        _context = new FakeAspContext(tcs, fn, cancel);
                        HttpRuntime.ProcessRequest(new SimpleWorkerRequest("", "", new StringWriter()));
                    }
                    catch (Exception ex)
                    {
                        tcs.TrySetException(ex);
                    }
                }));

                thread.Start();

                cancel.Register(() =>
                {
                    thread.Abort();
                    tcs.TrySetException(new Exception("Cancelled!"));
                });
            }
            catch (Exception ex)
            {
                tcs.TrySetException(ex);
            }

            return(tcs.Task);
        }
Exemplo n.º 2
0
 public FakeAspContext(TaskCompletionSource <bool> tcs, FnInner fn, CancellationToken cancel)
 {
     _tcs    = tcs;
     _fn     = fn;
     _cancel = cancel;
 }
Exemplo n.º 3
0
 public static Test Create(FnInner fn) => new Test((ct, fnInner) => fnInner(ct), fn);
Exemplo n.º 4
0
 public static Test RunAsp(FnInner fn)
 => Test.Create(fn)
 .WrapOuter(_ => RunArbitraryFn)
 .Timeout(300);
Exemplo n.º 5
0
 private Test(FnOuter fnOuter, FnInner fnInner)
 {
     _fnOuter = fnOuter;
     _fnInner = fnInner;
 }