Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/bunit.core/ComponentParameterCollection.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Bunit.Rendering;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Rendering;

namespace Bunit
Expand Down
1 change: 0 additions & 1 deletion src/bunit.core/ComponentParameterCollectionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Bunit.Rendering;
using Microsoft.AspNetCore.Components;

namespace Bunit
Expand Down
1 change: 0 additions & 1 deletion src/bunit.core/ComponentParameterFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading.Tasks;
using Bunit.Rendering;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Bunit.Rendering;
using Microsoft.AspNetCore.Components;

namespace Bunit
Expand Down
3 changes: 2 additions & 1 deletion src/bunit.web/Asserting/CompareToDiffingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using AngleSharp.Diffing.Core;
using AngleSharp.Dom;
using Bunit.Diffing;
using Bunit.Rendering;
using Microsoft.Extensions.DependencyInjection;

namespace Bunit
Expand All @@ -27,7 +28,7 @@ public static IReadOnlyList<IDiff> CompareTo(this IRenderedFragment actual, stri
if (expected is null)
throw new ArgumentNullException(nameof(expected));

var htmlParser = actual.Services.GetRequiredService<HtmlParser>();
var htmlParser = actual.Services.GetRequiredService<BunitHtmlParser>();
var expectedNodes = htmlParser.Parse(expected);

return actual.Nodes.CompareTo(expectedNodes);
Expand Down
11 changes: 6 additions & 5 deletions src/bunit.web/Asserting/MarkupMatchesAssertExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using AngleSharp.Dom;
using Bunit.Diffing;
using Bunit.Rendering;
using Microsoft.Extensions.DependencyInjection;

namespace Bunit
Expand All @@ -20,7 +21,7 @@ public static class MarkupMatchesAssertExtensions
/// <param name="userMessage">A custom user message to display in case the verification fails.</param>
public static void MarkupMatches(this string actual, string expected, string? userMessage = null)
{
using var parser = new HtmlParser();
using var parser = new BunitHtmlParser();
var actualNodes = parser.Parse(actual);
var expectedNodes = parser.Parse(expected);
actualNodes.MarkupMatches(expectedNodes, userMessage);
Expand All @@ -39,7 +40,7 @@ public static void MarkupMatches(this string actual, IRenderedFragment expected,
if (expected is null)
throw new ArgumentNullException(nameof(expected));

var actualNodes = actual.ToNodeList(expected.Services.GetRequiredService<HtmlParser>());
var actualNodes = actual.ToNodeList(expected.Services.GetRequiredService<BunitHtmlParser>());
actualNodes.MarkupMatches(expected, userMessage);
}

Expand Down Expand Up @@ -92,7 +93,7 @@ public static void MarkupMatches(this IRenderedFragment actual, string expected,
if (expected is null)
throw new ArgumentNullException(nameof(expected));

var expectedNodes = expected.ToNodeList(actual.Services.GetRequiredService<HtmlParser>());
var expectedNodes = expected.ToNodeList(actual.Services.GetRequiredService<BunitHtmlParser>());
actual.Nodes.MarkupMatches(expectedNodes, userMessage);
}

Expand Down Expand Up @@ -239,11 +240,11 @@ public static void MarkupMatches(this INode actual, INodeList expected, string?
throw new HtmlEqualException(diffs, expected, actual, userMessage);
}

private static INodeList ToNodeList(this string markup, HtmlParser? htmlParser)
private static INodeList ToNodeList(this string markup, BunitHtmlParser? htmlParser)
{
if (htmlParser is null)
{
using var newHtmlParser = new HtmlParser();
using var newHtmlParser = new BunitHtmlParser();
return newHtmlParser.Parse(markup);
}
else
Expand Down
5 changes: 3 additions & 2 deletions src/bunit.web/Asserting/ShouldBeAdditionAssertExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using AngleSharp.Diffing.Core;
using AngleSharp.Dom;
using Bunit.Diffing;
using Bunit.Rendering;

namespace Bunit
{
Expand All @@ -29,13 +30,13 @@ public static void ShouldBeAddition(this IDiff actualChange, string expectedChan
var actual = actualChange as UnexpectedNodeDiff ?? throw new DiffChangeAssertException(actualChange.Result, DiffResult.Unexpected, "The change was not an addition.");

INodeList expected;
if (actual.Test.Node.GetHtmlParser() is HtmlParser parser)
if (actual.Test.Node.GetHtmlParser() is BunitHtmlParser parser)
{
expected = parser.Parse(expectedChange);
}
else
{
using var newParser = new HtmlParser();
using var newParser = new BunitHtmlParser();
expected = newParser.Parse(expectedChange);
}

Expand Down
5 changes: 3 additions & 2 deletions src/bunit.web/Asserting/ShouldBeRemovalAssertExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using AngleSharp.Diffing.Core;
using AngleSharp.Dom;
using Bunit.Diffing;
using Bunit.Rendering;

namespace Bunit
{
Expand All @@ -29,13 +30,13 @@ public static void ShouldBeRemoval(this IDiff actualChange, string expectedChang
var actual = actualChange as MissingNodeDiff ?? throw new DiffChangeAssertException(actualChange.Result, DiffResult.Missing, "The change was not an removal.");

INodeList expected;
if (actual.Control.Node.GetHtmlParser() is HtmlParser parser)
if (actual.Control.Node.GetHtmlParser() is BunitHtmlParser parser)
{
expected = parser.Parse(expectedChange);
}
else
{
using var newParser = new HtmlParser();
using var newParser = new BunitHtmlParser();
expected = newParser.Parse(expectedChange);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using AngleSharp.Dom;
using Bunit.Asserting;
using Bunit.Diffing;
using Bunit.Rendering;

namespace Bunit
{
Expand Down Expand Up @@ -39,7 +40,7 @@ public static void ShouldBeTextChange(this IDiff actualChange, string expectedCh

var actual = actualChange as NodeDiff ?? throw new DiffChangeAssertException(actualChange.Result, DiffResult.Different, "The change was not a text change.");

var parser = actual.Control.Node.Owner.Context.GetService<HtmlParser>();
var parser = actual.Control.Node.Owner.Context.GetService<BunitHtmlParser>();
var expected = parser.Parse(expectedChange);

ShouldBeTextChange(actualChange, expected, userMessage);
Expand Down
1 change: 0 additions & 1 deletion src/bunit.web/ComponentTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading.Tasks;
using Bunit.Rendering;
using Microsoft.AspNetCore.Components;

namespace Bunit
Expand Down
69 changes: 0 additions & 69 deletions src/bunit.web/Diffing/HtmlParser.cs

This file was deleted.

15 changes: 8 additions & 7 deletions src/bunit.web/Extensions/Internal/AngleSharpExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using AngleSharp.Dom;
using Bunit.Diffing;
using Bunit.Rendering;

namespace Bunit
{
Expand All @@ -20,23 +21,23 @@ public static IEnumerable<INode> AsEnumerable(this INode node)
}

/// <summary>
/// Gets the <see cref="HtmlParser"/> stored in the <paramref name="node"/>s
/// Gets the <see cref="BunitHtmlParser"/> stored in the <paramref name="node"/>s
/// owning context, if one is available.
/// </summary>
/// <param name="node"></param>
/// <returns>The <see cref="HtmlParser"/> or null if not found.</returns>
public static HtmlParser? GetHtmlParser(this INode? node)
/// <returns>The <see cref="BunitHtmlParser"/> or null if not found.</returns>
public static BunitHtmlParser? GetHtmlParser(this INode? node)
{
return node?.Owner.Context.GetService<HtmlParser>();
return node?.Owner.Context.GetService<BunitHtmlParser>();
}

/// <summary>
/// Gets the <see cref="HtmlParser"/> stored in the <paramref name="nodes"/>s
/// Gets the <see cref="BunitHtmlParser"/> stored in the <paramref name="nodes"/>s
/// owning context, if one is available.
/// </summary>
/// <param name="nodes"></param>
/// <returns>The <see cref="HtmlParser"/> or null if not found.</returns>
public static HtmlParser? GetHtmlParser(this INodeList nodes)
/// <returns>The <see cref="BunitHtmlParser"/> or null if not found.</returns>
public static BunitHtmlParser? GetHtmlParser(this INodeList nodes)
{
return nodes?.Length > 0 ? nodes[0].GetHtmlParser() : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bunit.web/Extensions/TestServiceProviderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static IServiceCollection AddDefaultTestContextServices(this IServiceColl
services.AddSingleton<IAuthorizationService, PlaceholderAuthorizationService>();
services.AddSingleton<IJSRuntime, PlaceholderJSRuntime>();
services.AddSingleton<HtmlComparer>();
services.AddSingleton<HtmlParser>();
services.AddSingleton<BunitHtmlParser>();
services.AddSingleton<IRenderedComponentActivator, RenderedComponentActivator>();
return services;
}
Expand Down
4 changes: 2 additions & 2 deletions src/bunit.web/RazorTesting/SnapshotTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Threading.Tasks;
using Bunit.Diffing;
using Bunit.Extensions;
using Bunit.RazorTesting;
using Bunit.Rendering;
using Microsoft.AspNetCore.Components;

namespace Bunit
Expand Down Expand Up @@ -62,7 +62,7 @@ protected override async Task Run()

private void VerifySnapshot(string inputHtml, string expectedHtml)
{
using var parser = new HtmlParser();
using var parser = new BunitHtmlParser();
var inputNodes = parser.Parse(inputHtml);
var expectedNodes = parser.Parse(expectedHtml);

Expand Down
Loading