1- using System ;
2- using System . Collections . Generic ;
3- using System . Reflection ;
4- using System . Threading ;
5- using System . Threading . Tasks ;
6- using AngleSharp . Browser ;
7- using AngleSharp . Common ;
8- using AngleSharp . Html ;
9- using NUnit . Framework ;
10-
111namespace AngleSharp . Js . Tests
122{
3+ using NUnit . Framework ;
4+ using System . Threading . Tasks ;
5+
136 [ TestFixture ]
147 public class JavascriptErrorTests
158 {
169 [ Test ]
17- public void JavascriptErrorInListenerShouldNotThrowJavascriptException ( )
10+ public async Task JavascriptErrorInListenerShouldNotThrowJavascriptException ( )
1811 {
1912 var config = Configuration . Default
20- . WithJs ( )
21- . WithOnly ( ctx => new CustomEventLoop ( ) ) ;
13+ . WithJs ( ) ;
2214
2315 var context = BrowsingContext . New ( config ) ;
2416
@@ -35,49 +27,7 @@ public void JavascriptErrorInListenerShouldNotThrowJavascriptException()
3527 </html>
3628 " ;
3729
38- Assert . DoesNotThrowAsync ( async ( ) =>
39- {
40- try
41- {
42- await context . OpenAsync ( r => r . Content ( content ) ) ;
43-
44- var loop = ( CustomEventLoop ) context . GetService < IEventLoop > ( ) ;
45- await Task . WhenAll ( loop . Tasks ) ;
46- }
47- catch ( TargetInvocationException ex )
48- {
49- // unmask exception
50- var innerAggregate = ex . InnerException as AggregateException ;
51- if ( innerAggregate != null )
52- throw innerAggregate . InnerException ;
53- throw ;
54- }
55- } ) ;
56- }
57-
58- class CustomEventLoop : IEventLoop
59- {
60- private readonly List < Task > tasks = new List < Task > ( ) ;
61- public ICancellable Enqueue ( Action < CancellationToken > action , TaskPriority priority )
62- {
63- var task = new Task ( ( ) => action ( CancellationToken . None ) ) ;
64- tasks . Add ( task ) ;
65- task . Start ( ) ;
66- return new TaskCancellable ( task ) ;
67- }
68-
69- public Task [ ] Tasks => tasks . ToArray ( ) ;
70- public void Spin ( ) { }
71- public void CancelAll ( ) { }
72-
73- class TaskCancellable : ICancellable
74- {
75- private readonly Task task ;
76- public TaskCancellable ( Task task ) { this . task = task ; }
77- public void Cancel ( ) { }
78- public bool IsCompleted => task . IsCompleted ;
79- public bool IsRunning => task . Status == TaskStatus . Running ;
80- }
30+ await context . OpenAsync ( r => r . Content ( content ) ) ;
8131 }
8232 }
8333}
0 commit comments