Skip to content

Commit c5c236f

Browse files
committed
ComponentTestFixture factory methods now just redirect to ComponentParameterFactory's methods.
1 parent e7c76b2 commit c5c236f

4 files changed

Lines changed: 22 additions & 52 deletions

File tree

src/bunit.web/ComponentTestFixture.cs

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ public abstract class ComponentTestFixture : TestContext
2727
/// <param name="callback">The event callback.</param>
2828
/// <returns>The <see cref="ComponentParameter"/>.</returns>
2929
protected static ComponentParameter EventCallback(string name, Action callback)
30-
{
31-
return ComponentParameter.CreateParameter(name, new EventCallback(null, callback));
32-
}
30+
=> ComponentParameterFactory.EventCallback(name, callback);
3331

3432
/// <summary>
3533
/// Creates a <see cref="ComponentParameter"/> with an <see cref="Microsoft.AspNetCore.Components.EventCallback"/> as parameter value for this <see cref="TestContext"/> and
@@ -39,9 +37,7 @@ protected static ComponentParameter EventCallback(string name, Action callback)
3937
/// <param name="callback">The event callback.</param>
4038
/// <returns>The <see cref="ComponentParameter"/>.</returns>
4139
protected static ComponentParameter EventCallback(string name, Action<object> callback)
42-
{
43-
return ComponentParameter.CreateParameter(name, new EventCallback(null, callback));
44-
}
40+
=> ComponentParameterFactory.EventCallback(name, callback);
4541

4642
/// <summary>
4743
/// Creates a <see cref="ComponentParameter"/> with an <see cref="Microsoft.AspNetCore.Components.EventCallback"/> as parameter value for this <see cref="TestContext"/> and
@@ -51,9 +47,7 @@ protected static ComponentParameter EventCallback(string name, Action<object> ca
5147
/// <param name="callback">The event callback.</param>
5248
/// <returns>The <see cref="ComponentParameter"/>.</returns>
5349
protected static ComponentParameter EventCallback(string name, Func<Task> callback)
54-
{
55-
return ComponentParameter.CreateParameter(name, new EventCallback(null, callback));
56-
}
50+
=> ComponentParameterFactory.EventCallback(name, callback);
5751

5852
/// <summary>
5953
/// Creates a <see cref="ComponentParameter"/> with an <see cref="Microsoft.AspNetCore.Components.EventCallback"/> as parameter value for this <see cref="TestContext"/> and
@@ -63,9 +57,7 @@ protected static ComponentParameter EventCallback(string name, Func<Task> callba
6357
/// <param name="callback">The event callback.</param>
6458
/// <returns>The <see cref="ComponentParameter"/>.</returns>
6559
protected static ComponentParameter EventCallback(string name, Func<object, Task> callback)
66-
{
67-
return ComponentParameter.CreateParameter(name, new EventCallback(null, callback));
68-
}
60+
=> ComponentParameterFactory.EventCallback(name, callback);
6961

7062
/// <summary>
7163
/// Creates a <see cref="ComponentParameter"/> with an <see cref="Microsoft.AspNetCore.Components.EventCallback"/> as parameter value for this <see cref="TestContext"/> and
@@ -75,9 +67,7 @@ protected static ComponentParameter EventCallback(string name, Func<object, Task
7567
/// <param name="callback">The event callback.</param>
7668
/// <returns>The <see cref="ComponentParameter"/>.</returns>
7769
protected static ComponentParameter EventCallback<TValue>(string name, Action callback)
78-
{
79-
return ComponentParameter.CreateParameter(name, new EventCallback<TValue>(null, callback));
80-
}
70+
=> ComponentParameterFactory.EventCallback<TValue>(name, callback);
8171

8272
/// <summary>
8373
/// Creates a <see cref="ComponentParameter"/> with an <see cref="Microsoft.AspNetCore.Components.EventCallback"/> as parameter value for this <see cref="TestContext"/> and
@@ -87,9 +77,7 @@ protected static ComponentParameter EventCallback<TValue>(string name, Action ca
8777
/// <param name="callback">The event callback.</param>
8878
/// <returns>The <see cref="ComponentParameter"/>.</returns>
8979
protected static ComponentParameter EventCallback<TValue>(string name, Action<TValue> callback)
90-
{
91-
return ComponentParameter.CreateParameter(name, new EventCallback<TValue>(null, callback));
92-
}
80+
=> ComponentParameterFactory.EventCallback<TValue>(name, callback);
9381

9482
/// <summary>
9583
/// Creates a <see cref="ComponentParameter"/> with an <see cref="Microsoft.AspNetCore.Components.EventCallback"/> as parameter value for this <see cref="TestContext"/> and
@@ -99,9 +87,7 @@ protected static ComponentParameter EventCallback<TValue>(string name, Action<TV
9987
/// <param name="callback">The event callback.</param>
10088
/// <returns>The <see cref="ComponentParameter"/>.</returns>
10189
protected static ComponentParameter EventCallback<TValue>(string name, Func<Task> callback)
102-
{
103-
return ComponentParameter.CreateParameter(name, new EventCallback<TValue>(null, callback));
104-
}
90+
=> ComponentParameterFactory.EventCallback<TValue>(name, callback);
10591

10692
/// <summary>
10793
/// Creates a <see cref="ComponentParameter"/> with an <see cref="Microsoft.AspNetCore.Components.EventCallback"/> as parameter value for this <see cref="TestContext"/> and
@@ -111,9 +97,7 @@ protected static ComponentParameter EventCallback<TValue>(string name, Func<Task
11197
/// <param name="callback">The event callback.</param>
11298
/// <returns>The <see cref="ComponentParameter"/>.</returns>
11399
protected static ComponentParameter EventCallback<TValue>(string name, Func<TValue, Task> callback)
114-
{
115-
return ComponentParameter.CreateParameter(name, new EventCallback<TValue>(null, callback));
116-
}
100+
=> ComponentParameterFactory.EventCallback<TValue>(name, callback);
117101

118102
/// <summary>
119103
/// Creates a component parameter which can be passed to a test contexts render methods.
@@ -122,9 +106,7 @@ protected static ComponentParameter EventCallback<TValue>(string name, Func<TVal
122106
/// <param name="value">Value or null of the parameter</param>
123107
/// <returns>The <see cref="ComponentParameter"/>.</returns>
124108
protected static ComponentParameter Parameter(string name, object? value)
125-
{
126-
return ComponentParameter.CreateParameter(name, value);
127-
}
109+
=> ComponentParameterFactory.Parameter(name, value);
128110

129111
/// <summary>
130112
/// Creates a cascading value which can be passed to a test contexts render methods.
@@ -133,19 +115,16 @@ protected static ComponentParameter Parameter(string name, object? value)
133115
/// <param name="value">Value of the parameter</param>
134116
/// <returns>The <see cref="ComponentParameter"/>.</returns>
135117
protected static ComponentParameter CascadingValue(string name, object value)
136-
{
137-
return ComponentParameter.CreateCascadingValue(name, value);
138-
}
118+
=> ComponentParameterFactory.CascadingValue(name, value);
119+
139120

140121
/// <summary>
141122
/// Creates a cascading value which can be passed to a test contexts render methods.
142123
/// </summary>
143124
/// <param name="value">Value of the parameter</param>
144125
/// <returns>The <see cref="ComponentParameter"/>.</returns>
145126
protected static ComponentParameter CascadingValue(object value)
146-
{
147-
return ComponentParameter.CreateCascadingValue(null, value);
148-
}
127+
=> ComponentParameterFactory.CascadingValue(value);
149128

150129
/// <summary>
151130
/// Creates a ChildContent <see cref="Microsoft.AspNetCore.Components.RenderFragment"/> with the provided
@@ -154,9 +133,7 @@ protected static ComponentParameter CascadingValue(object value)
154133
/// <param name="markup">Markup to pass to the child content parameter</param>
155134
/// <returns>The <see cref="ComponentParameter"/>.</returns>
156135
protected static ComponentParameter ChildContent(string markup)
157-
{
158-
return RenderFragment(nameof(ChildContent), markup);
159-
}
136+
=> ComponentParameterFactory.ChildContent(markup);
160137

161138
/// <summary>
162139
/// Creates a ChildContent <see cref="Microsoft.AspNetCore.Components.RenderFragment"/> which will render a <typeparamref name="TComponent"/> component
@@ -166,9 +143,7 @@ protected static ComponentParameter ChildContent(string markup)
166143
/// <param name="parameters">Parameters to pass to the <typeparamref name="TComponent"/>.</param>
167144
/// <returns>The <see cref="ComponentParameter"/>.</returns>
168145
protected static ComponentParameter ChildContent<TComponent>(params ComponentParameter[] parameters) where TComponent : class, IComponent
169-
{
170-
return RenderFragment<TComponent>(nameof(ChildContent), parameters);
171-
}
146+
=> ComponentParameterFactory.ChildContent<TComponent>(parameters);
172147

173148
/// <summary>
174149
/// Creates a <see cref="Microsoft.AspNetCore.Components.RenderFragment"/> with the provided
@@ -178,9 +153,8 @@ protected static ComponentParameter ChildContent<TComponent>(params ComponentPar
178153
/// <param name="markup">Markup to pass to the render fragment parameter</param>
179154
/// <returns>The <see cref="ComponentParameter"/>.</returns>
180155
protected static ComponentParameter RenderFragment(string name, string markup)
181-
{
182-
return ComponentParameter.CreateParameter(name, markup.ToMarkupRenderFragment());
183-
}
156+
=> ComponentParameterFactory.RenderFragment(name, markup);
157+
184158

185159
/// <summary>
186160
/// Creates a <see cref="Microsoft.AspNetCore.Components.RenderFragment"/> which will render a <typeparamref name="TComponent"/> component
@@ -191,9 +165,7 @@ protected static ComponentParameter RenderFragment(string name, string markup)
191165
/// <param name="parameters">Parameters to pass to the <typeparamref name="TComponent"/>.</param>
192166
/// <returns>The <see cref="ComponentParameter"/>.</returns>
193167
protected static ComponentParameter RenderFragment<TComponent>(string name, params ComponentParameter[] parameters) where TComponent : class, IComponent
194-
{
195-
return ComponentParameter.CreateParameter(name, parameters.ToComponentRenderFragment<TComponent>());
196-
}
168+
=> ComponentParameterFactory.RenderFragment<TComponent>(name, parameters);
197169

198170
/// <summary>
199171
/// Creates a template component parameter which will pass the <paramref name="template"/> <see cref="Microsoft.AspNetCore.Components.RenderFragment{TValue}" />
@@ -204,9 +176,7 @@ protected static ComponentParameter RenderFragment<TComponent>(string name, para
204176
/// <param name="template"><see cref="Microsoft.AspNetCore.Components.RenderFragment{TValue}" /> to pass to the parameter.</param>
205177
/// <returns>The <see cref="ComponentParameter"/>.</returns>
206178
protected static ComponentParameter Template<TValue>(string name, RenderFragment<TValue> template)
207-
{
208-
return ComponentParameter.CreateParameter(name, template);
209-
}
179+
=> ComponentParameterFactory.Template<TValue>(name, template);
210180

211181
/// <summary>
212182
/// Creates a template component parameter which will pass the a <see cref="Microsoft.AspNetCore.Components.RenderFragment{TValue}" />
@@ -218,8 +188,6 @@ protected static ComponentParameter Template<TValue>(string name, RenderFragment
218188
/// <param name="markupFactory">A markup factory that takes a <typeparamref name="TValue"/> as input and returns markup/HTML.</param>
219189
/// <returns>The <see cref="ComponentParameter"/>.</returns>
220190
protected static ComponentParameter Template<TValue>(string name, Func<TValue, string> markupFactory)
221-
{
222-
return Template<TValue>(name, value => (RenderTreeBuilder builder) => builder.AddMarkupContent(0, markupFactory(value)));
223-
}
191+
=> ComponentParameterFactory.Template<TValue>(name, markupFactory);
224192
}
225193
}

src/bunit.web/EventDispatchExtensions/MissingEventHandlerException.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public MissingEventHandlerException(IElement element, string missingEventName) :
2020
private static string CreateErrorMessage(IElement element, string missingEventName)
2121
{
2222
var result = $"The element does not have an event handler for the event '{missingEventName}'";
23+
// TODO: This should also filter out the other non-eventHandler attributes like stoProporgation
2324
var eventHandlers = element.Attributes?
2425
.Where(x => x.Name.StartsWith(Htmlizer.BLAZOR_ATTR_PREFIX, StringComparison.Ordinal) && !x.Name.StartsWith(Htmlizer.ELEMENT_REFERENCE_ATTR_NAME, StringComparison.Ordinal))
2526
.Select(x => $"'{x.Name.Remove(0, Htmlizer.BLAZOR_ATTR_PREFIX.Length)}'")

src/bunit.web/Mocking/JSInterop/MissingMockJsRuntimeException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Bunit.Mocking.JSInterop
1212
public class MissingMockJsRuntimeException : Exception
1313
{
1414
/// <summary>
15-
/// Identifer string used in the JSInvoke method.
15+
/// Identifier string used in the JSInvoke method.
1616
/// </summary>
1717
public string Identifier { get; }
1818

src/bunit.xunit.tests/GlobalSuppressions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77

88
[assembly: SuppressMessage("Usage", "BL0006:Do not use RenderTree types")]
99
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods")]
10+
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types")]

0 commit comments

Comments
 (0)