// ReSharper disable once PartialTypeWithSinglePart
[TestClass]
[SuppressMessage("Microsoft.Design","CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable",Justification="Test classes use TestCleanupAttribute for deterministic teardown.")]
engine.Execute("(async function () { try { result = await promise; } catch (exception) { result = exception.hostException.InnerException.InnerException.Message; } })()");
Assert.AreEqual(message,engine.Script.result);
engine.Script.task=task;
engine.Execute("(async function () { try { result = await task.ToPromise(); } catch (exception) { result = exception.hostException.InnerException.InnerException.Message; } })()");
Assert.AreEqual(message,engine.Script.result);
}
[TestMethod,TestCategory("Extensions")]
publicvoidExtensions_JavaScript_ToTask()
{
engine.AddHostType(typeof(Task));
Assert.AreEqual(Math.PI,EvaluateAsync("(async function () { await Task.Delay(100).ToPromise(); return Math.PI; })()").Result);
}
[TestMethod,TestCategory("Extensions")]
publicvoidExtensions_JavaScript_ToTask_Fail()
{
engine.AddHostType(typeof(Task));
TestUtil.AssertException<ScriptEngineException>(()=>EvaluateAsync("(async function () { await Task.Delay(100).ToPromise(); throw new Error('Unauthorized'); })()").Wait());