Ejemplo n.º 1
0
        public async Task <TResult> ExecuteUnsafe <TResult>(RunContext runContext, CancellationToken cancellationToken)
        {
            TestOperationStatus.AssertNotStarted(this.Status);

            var nestedRunContext = this.sourceContext != null
                                ? runContext.MakeNested(this.sourceContext.Value)
                                : runContext;

            this.Status = new TestOperationStatus.Waiting(this.Status, runContext.MakeWaitContext());

            try
            {
                var result = await this.ExecuteInner(nestedRunContext, cancellationToken);

                this.Status = new TestOperationStatus.Completed(this.Status);
                return((TResult)(object)result);                // See the Execute extension method for why this is safe.
            }
            catch (OperationCanceledException)
            {
                this.Status = new TestOperationStatus.Canceled(this.Status);
                throw;
            }
            catch (Exception e)
            {
                this.Status = new TestOperationStatus.Failed(this.Status, e, nestedRunContext.SourceContext);
                throw;
            }
        }