Skip to content

Commit 2611704

Browse files
egilactions-user
andauthored
BunitHtmlFinder: parse context finder for markup strings that start with an html5 tag implemented (#220)
* reset changelog with unreleased section * Cleanup using and resorted them * Improvements to parameter passing in c# based tests (#203) * componentparametercollection * Support for passing multiple template and render fragments * Automated dotnet-format update * cascading values * Finished component parameter collection, closed #142, updated tests to component parameter factory * Fixed null warnings * Automated dotnet-format update * Fixes for CodeQL warnings * Added ChildContent and RenderFragment tests * Added support for passing template fragments * Removed ComponentParameterBuilder, added support for unmatched and cascading values * Switched to C# 9 compile * Automated dotnet-format update * unnamed cascading value with add * Removed .net move hack from workflows * Fix for null errors * Automated dotnet-format update * Added extra factory method and moved ComponentParameter out into Bunit namespace * Updated docs with new parameter passing logic * Automated dotnet-format update * Updated changelog Co-authored-by: Github Actions <actions@github.com> * Updated version to beta-11 * Context finder for strings that start with an html5 tag * Fix for build error * Added support for HTML, HEAD, and BODY, stopped reusing element contexts * Cleanup usings Co-authored-by: Github Actions <actions@github.com>
1 parent fafa45c commit 2611704

25 files changed

Lines changed: 392 additions & 117 deletions

src/bunit.core/ComponentParameterCollection.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics.CodeAnalysis;
43
using System.Linq;
54
using System.Reflection;
6-
using System.Text;
7-
using System.Threading.Tasks;
8-
using Bunit.Rendering;
95
using Microsoft.AspNetCore.Components;
10-
using Microsoft.AspNetCore.Components.Forms;
116
using Microsoft.AspNetCore.Components.Rendering;
127

138
namespace Bunit

src/bunit.core/ComponentParameterCollectionBuilder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq.Expressions;
55
using System.Reflection;
66
using System.Threading.Tasks;
7-
using Bunit.Rendering;
87
using Microsoft.AspNetCore.Components;
98

109
namespace Bunit

src/bunit.core/ComponentParameterFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Threading.Tasks;
3-
using Bunit.Rendering;
43
using Microsoft.AspNetCore.Components;
54
using Microsoft.AspNetCore.Components.Rendering;
65

src/bunit.core/Extensions/RenderedComponentRenderExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using Bunit.Rendering;
43
using Microsoft.AspNetCore.Components;
54

65
namespace Bunit

src/bunit.web/Asserting/CompareToDiffingExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using AngleSharp.Diffing.Core;
55
using AngleSharp.Dom;
66
using Bunit.Diffing;
7+
using Bunit.Rendering;
78
using Microsoft.Extensions.DependencyInjection;
89

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

30-
var htmlParser = actual.Services.GetRequiredService<HtmlParser>();
31+
var htmlParser = actual.Services.GetRequiredService<BunitHtmlParser>();
3132
var expectedNodes = htmlParser.Parse(expected);
3233

3334
return actual.Nodes.CompareTo(expectedNodes);

src/bunit.web/Asserting/MarkupMatchesAssertExtensions.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using AngleSharp.Dom;
33
using Bunit.Diffing;
4+
using Bunit.Rendering;
45
using Microsoft.Extensions.DependencyInjection;
56

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

42-
var actualNodes = actual.ToNodeList(expected.Services.GetRequiredService<HtmlParser>());
43+
var actualNodes = actual.ToNodeList(expected.Services.GetRequiredService<BunitHtmlParser>());
4344
actualNodes.MarkupMatches(expected, userMessage);
4445
}
4546

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

95-
var expectedNodes = expected.ToNodeList(actual.Services.GetRequiredService<HtmlParser>());
96+
var expectedNodes = expected.ToNodeList(actual.Services.GetRequiredService<BunitHtmlParser>());
9697
actual.Nodes.MarkupMatches(expectedNodes, userMessage);
9798
}
9899

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

242-
private static INodeList ToNodeList(this string markup, HtmlParser? htmlParser)
243+
private static INodeList ToNodeList(this string markup, BunitHtmlParser? htmlParser)
243244
{
244245
if (htmlParser is null)
245246
{
246-
using var newHtmlParser = new HtmlParser();
247+
using var newHtmlParser = new BunitHtmlParser();
247248
return newHtmlParser.Parse(markup);
248249
}
249250
else

src/bunit.web/Asserting/ShouldBeAdditionAssertExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using AngleSharp.Diffing.Core;
44
using AngleSharp.Dom;
55
using Bunit.Diffing;
6+
using Bunit.Rendering;
67

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

3132
INodeList expected;
32-
if (actual.Test.Node.GetHtmlParser() is HtmlParser parser)
33+
if (actual.Test.Node.GetHtmlParser() is BunitHtmlParser parser)
3334
{
3435
expected = parser.Parse(expectedChange);
3536
}
3637
else
3738
{
38-
using var newParser = new HtmlParser();
39+
using var newParser = new BunitHtmlParser();
3940
expected = newParser.Parse(expectedChange);
4041
}
4142

src/bunit.web/Asserting/ShouldBeRemovalAssertExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using AngleSharp.Diffing.Core;
44
using AngleSharp.Dom;
55
using Bunit.Diffing;
6+
using Bunit.Rendering;
67

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

3132
INodeList expected;
32-
if (actual.Control.Node.GetHtmlParser() is HtmlParser parser)
33+
if (actual.Control.Node.GetHtmlParser() is BunitHtmlParser parser)
3334
{
3435
expected = parser.Parse(expectedChange);
3536
}
3637
else
3738
{
38-
using var newParser = new HtmlParser();
39+
using var newParser = new BunitHtmlParser();
3940
expected = newParser.Parse(expectedChange);
4041
}
4142

src/bunit.web/Asserting/ShouldBeTextChangeAssertExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using AngleSharp.Dom;
66
using Bunit.Asserting;
77
using Bunit.Diffing;
8+
using Bunit.Rendering;
89

910
namespace Bunit
1011
{
@@ -39,7 +40,7 @@ public static void ShouldBeTextChange(this IDiff actualChange, string expectedCh
3940

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

42-
var parser = actual.Control.Node.Owner.Context.GetService<HtmlParser>();
43+
var parser = actual.Control.Node.Owner.Context.GetService<BunitHtmlParser>();
4344
var expected = parser.Parse(expectedChange);
4445

4546
ShouldBeTextChange(actualChange, expected, userMessage);

src/bunit.web/ComponentTestFixture.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Threading.Tasks;
3-
using Bunit.Rendering;
43
using Microsoft.AspNetCore.Components;
54

65
namespace Bunit

0 commit comments

Comments
 (0)