Skip to content

Commit 73a08bf

Browse files
committed
Changed to "new()" syntax where possible and changelog update
1 parent fa03e61 commit 73a08bf

23 files changed

Lines changed: 36 additions & 31 deletions

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ List of new features.
1414
### Changed
1515
List of changes in existing functionality.
1616

17+
- bUnit's mock IJSRuntime has been moved to an "always on" state by default, in strict mode, and is now available through `TestContext`'s `JSInterop` property. This makes it possible for first party Blazor components like the `<Virtualize>` component, which depend on JSInterop, to "just work" in tests.
18+
19+
**Compatible with previous releases:** To get the same effect as calling `Services.AddMockJSRuntime()` in beta-11, which used to add the mock IJSRuntime in "loose" mode, you now just need to change the mode of the already on JSInterop, i.e. `ctx.JSInterop.Mode = JSRuntimeMode.Loose`.
20+
21+
**Inspect registered handlers:** Since the new design allows registering invoke handlers in the context of the `TestContext`, you might need to get already registered handlers in your individual tests. This can be done with the `TryGetInvokeHandler()` method, that will return handler that can handle the parameters passed to it. E.g. to get a handler for a `IJSRuntime.InvokaAsync<string>("getValue")`, call `ctx.JSInterop.TryGetInvokeHandler<string>("getValue")`.
22+
23+
Learn more [issue #237](https://github.com/egil/bUnit/issues/237). By [@egil](https://github.com/egil) in [#247](https://github.com/egil/bUnit/pull/247).
24+
1725
### Removed
1826
List of now removed features.
1927

src/bunit.core/ComponentParameterCollectionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public sealed class ComponentParameterCollectionBuilder<TComponent> where TCompo
2626
.OfType<ParameterAttribute>()
2727
.Any(x => x.CaptureUnmatchedValues);
2828

29-
private readonly ComponentParameterCollection _parameters = new ComponentParameterCollection();
29+
private readonly ComponentParameterCollection _parameters = new();
3030

3131
/// <summary>
3232
/// Creates an instance of the <see cref="ComponentParameterCollectionBuilder{TComponent}"/>.

src/bunit.core/Rendering/RenderTreeFrameCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Bunit.Rendering
88
/// </summary>
99
public sealed class RenderTreeFrameCollection
1010
{
11-
private readonly Dictionary<int, ArrayRange<RenderTreeFrame>> _currentRenderTree = new Dictionary<int, ArrayRange<RenderTreeFrame>>();
11+
private readonly Dictionary<int, ArrayRange<RenderTreeFrame>> _currentRenderTree = new();
1212

1313
/// <summary>
1414
/// Gets the <see cref="ArrayRange{RenderTreeFrame}"/> associated with the <paramref name="componentId"/>.

src/bunit.core/Rendering/TestRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ namespace Bunit.Rendering
1414
/// </summary>
1515
public partial class TestRenderer : Renderer, ITestRenderer
1616
{
17-
private readonly object _renderTreeAccessLock = new object();
17+
private readonly object _renderTreeAccessLock = new();
1818
private readonly ILogger _logger;
1919
private readonly IRenderedComponentActivator _activator;
2020
private Exception? _unhandledException;
21-
private readonly Dictionary<int, IRenderedFragmentBase> _renderedComponents = new Dictionary<int, IRenderedFragmentBase>();
21+
private readonly Dictionary<int, IRenderedFragmentBase> _renderedComponents = new();
2222

2323
/// <inheritdoc/>
2424
public override Dispatcher Dispatcher { get; } = Dispatcher.CreateDefault();

src/bunit.web/Diffing/DiffMarkupFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class DiffMarkupFormatter : PrettyMarkupFormatter, IMarkupFormatter
1313
/// <summary>
1414
/// Gets an instance of the <see cref="DiffMarkupFormatter"/>.
1515
/// </summary>
16-
public new static readonly DiffMarkupFormatter Instance = new DiffMarkupFormatter();
16+
public new static readonly DiffMarkupFormatter Instance = new();
1717

1818
/// <summary>
1919
/// Creates an instance of the <see cref="DiffMarkupFormatter"/>.

src/bunit.web/EventDispatchExtensions/Key.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ public static implicit operator KeyboardEventArgs(Key key)
566566
}
567567

568568
// This has to be placed last since it is referencing other static fields, that must be initialized first.
569-
private static readonly Dictionary<(string value, string code), Key> PredefinedKeys = new Dictionary<(string value, string code), Key>
569+
private static readonly Dictionary<(string value, string code), Key> PredefinedKeys = new()
570570
{
571571
{ (Key.Backspace.Value, Key.Backspace.Code), Key.Backspace },
572572
{ (Key.Tab.Value, Key.Tab.Code), Key.Tab },

src/bunit.web/EventDispatchExtensions/TriggerEventDispatchExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ namespace Bunit
1616
/// </summary>
1717
public static class TriggerEventDispatchExtensions
1818
{
19-
private static readonly HashSet<string> NonBubblingEvents = new HashSet<string> { "onabort", "onblur", "onchange", "onerror", "onfocus", "onload", "onloadend", "onloadstart", "onmouseenter", "onmouseleave", "onprogress", "onreset", "onscroll", "onsubmit", "onunload", "ontoggle", "ondomnodeinsertedintodocument", "ondomnoderemovedfromdocument" };
20-
private static readonly HashSet<string> DisabledEventNames = new HashSet<string> { "onclick", "ondblclick", "onmousedown", "onmousemove", "onmouseup" };
19+
private static readonly HashSet<string> NonBubblingEvents = new() { "onabort", "onblur", "onchange", "onerror", "onfocus", "onload", "onloadend", "onloadstart", "onmouseenter", "onmouseleave", "onprogress", "onreset", "onscroll", "onsubmit", "onunload", "ontoggle", "ondomnodeinsertedintodocument", "ondomnoderemovedfromdocument" };
20+
private static readonly HashSet<string> DisabledEventNames = new() { "onclick", "ondblclick", "onmousedown", "onmousemove", "onmouseup" };
2121

2222
/// <summary>
2323
/// Raises the event <paramref name="eventName"/> on the element <paramref name="element"/>

src/bunit.web/JSInterop/BunitJSInterop.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace Bunit
1313
/// </summary>
1414
public class BunitJSInterop
1515
{
16-
private readonly Dictionary<string, List<JSRuntimeInvocation>> _invocations = new Dictionary<string, List<JSRuntimeInvocation>>();
17-
private readonly Dictionary<string, List<object>> _handlers = new Dictionary<string, List<object>>();
16+
private readonly Dictionary<string, List<JSRuntimeInvocation>> _invocations = new();
17+
private readonly Dictionary<string, List<object>> _handlers = new();
1818

1919
/// <summary>
2020
/// Gets a dictionary of all <see cref="List{JSRuntimeInvocation}"/> this mock has observed.

src/bunit.web/RazorTesting/Fixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Bunit
1111
/// <inheritdoc/>
1212
public class Fixture : FixtureBase<Fixture>
1313
{
14-
private readonly Dictionary<string, IRenderedFragment> _renderedFragments = new Dictionary<string, IRenderedFragment>();
14+
private readonly Dictionary<string, IRenderedFragment> _renderedFragments = new();
1515
private IReadOnlyList<FragmentBase>? _testData;
1616

1717
private IReadOnlyList<FragmentBase> TestData

src/bunit.web/Rendering/BunitHtmlParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public sealed class BunitHtmlParser : IDisposable
2424

2525
private readonly IBrowsingContext _context;
2626
private readonly IHtmlParser _htmlParser;
27-
private readonly List<IDocument> _documents = new List<IDocument>();
27+
private readonly List<IDocument> _documents = new();
2828

2929
/// <summary>
3030
/// Creates an instance of the parser with a AngleSharp context

0 commit comments

Comments
 (0)