Skip to content

Commit 2552ac0

Browse files
committed
Updated tests for latest AngleSharp
1 parent b99ff2a commit 2552ac0

2 files changed

Lines changed: 10 additions & 58 deletions

File tree

src/AngleSharp.Js.Tests/IntegrationTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Js.Tests
1+
namespace AngleSharp.Js.Tests
22
{
33
using AngleSharp.Dom;
44
using NUnit.Framework;
@@ -10,7 +10,9 @@ public class IntegrationTests
1010
{
1111
private static Task<IDocument> LoadPage(String url)
1212
{
13-
var configuration = Helpers.GetCssConfig().WithDefaultLoader().WithCookies();
13+
var configuration = Helpers.GetCssConfig()
14+
.WithDefaultLoader()
15+
.WithDefaultCookies();
1416
var context = BrowsingContext.New(configuration);
1517
return context.OpenAsync(url);
1618
}
Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
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-
111
namespace 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

Comments
 (0)