Skip to content

Commit 46c1adc

Browse files
committed
fix: internal ctors on Stub not working with Activator.CreateInstance
1 parent ebd2271 commit 46c1adc

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

src/bunit.web/ComponentFactories/StubComponentFactory.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public bool CanCreate(Type componentType)
2222
public IComponent Create(Type componentType)
2323
{
2424
var typeToCreate = StubType.MakeGenericType(componentType);
25-
return replacementContent is not null
26-
? (IComponent)Activator.CreateInstance(typeToCreate, new object?[] { replacementContent })!
27-
: (IComponent)Activator.CreateInstance(typeToCreate, Array.Empty<object?>())!;
25+
return (IComponent)Activator.CreateInstance(typeToCreate, new object?[] { replacementContent })!;
2826
}
2927
}
3028
#endif

src/bunit.web/TestDoubles/Components/Stub{TComponent}.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ public sealed class Stub<TComponent> : ComponentDoubleBase<TComponent>
1616
/// <summary>
1717
/// Initializes a new instance of the <see cref="Stub{TComponent}"/> class.
1818
/// </summary>
19-
internal Stub() { }
19+
public Stub() { }
2020

2121
/// <summary>
2222
/// Initializes a new instance of the <see cref="Stub{TComponent}"/> class
2323
/// that uses the provided <paramref name="replacement"/> when rendering.
2424
/// </summary>
2525
/// <param name="replacement">The replacement template to use when rendering.</param>
26-
internal Stub(object replacement)
26+
public Stub(object? replacement)
2727
{
2828
if (replacement is RenderFragment<CapturedParameterView<TComponent>> replacementTemplate)
2929
this.replacementTemplate = replacementTemplate;
3030
else if (replacement is RenderFragment replacementFragment)
3131
this.replacementFragment = replacementFragment;
32-
else
32+
else if (replacement is not null)
3333
throw new ArgumentException($"The type of replacement is not supported. Replacement type = {replacement.GetType()}", nameof(replacement));
3434
}
3535

0 commit comments

Comments
 (0)