зеркало из https://github.com/dotnet/aspnetcore.git
Suppress warning + add tests
This commit is contained in:
Родитель
7e3032f303
Коммит
a6154bb2a0
|
@ -186,11 +186,13 @@ public class CascadingValueSource<TValue> : ICascadingValueSupplier
|
|||
}
|
||||
|
||||
[InlineArray(Capacity)]
|
||||
private struct ComponentStateBuffer
|
||||
internal struct ComponentStateBuffer
|
||||
{
|
||||
public const int Capacity = 64;
|
||||
#pragma warning disable IDE0051 // Remove unused private members
|
||||
#pragma warning disable IDE0044 // Add readonly modifier
|
||||
private ComponentState _values;
|
||||
#pragma warning restore IDE0044 // Add readonly modifier
|
||||
#pragma warning restore IDE0051 // Remove unused private members
|
||||
}
|
||||
}
|
||||
|
|
|
@ -827,6 +827,40 @@ public class CascadingParameterTest
|
|||
Assert.Equal(2, services.Count());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(CascadingValueSource<MyParamType>.ComponentStateBuffer.Capacity - 1)]
|
||||
[InlineData(CascadingValueSource<MyParamType>.ComponentStateBuffer.Capacity)]
|
||||
[InlineData(CascadingValueSource<MyParamType>.ComponentStateBuffer.Capacity + 1)]
|
||||
[InlineData(CascadingValueSource<MyParamType>.ComponentStateBuffer.Capacity * 2)]
|
||||
public async Task CanHaveManySubscribers(int numSubscribers)
|
||||
{
|
||||
// Arrange
|
||||
var services = new ServiceCollection();
|
||||
var paramValue = new MyParamType("Initial value");
|
||||
var cascadingValueSource = new CascadingValueSource<MyParamType>(paramValue, isFixed: false);
|
||||
services.AddCascadingValue(_ => cascadingValueSource);
|
||||
var renderer = new TestRenderer(services.BuildServiceProvider());
|
||||
var components = Enumerable.Range(0, numSubscribers).Select(_ => new SimpleSubscriberComponent()).ToArray();
|
||||
|
||||
// Act/Assert: Initial render
|
||||
foreach (var component in components)
|
||||
{
|
||||
await renderer.Dispatcher.InvokeAsync(() => renderer.AssignRootComponentId(component));
|
||||
component.TriggerRender();
|
||||
Assert.Equal(1, component.NumRenders);
|
||||
}
|
||||
|
||||
// Act/Assert: All components re-render when the cascading value changes
|
||||
paramValue.ChangeValue("Final value");
|
||||
await cascadingValueSource.NotifyChangedAsync();
|
||||
foreach (var component in components)
|
||||
{
|
||||
Assert.Equal(2, component.NumRenders);
|
||||
}
|
||||
}
|
||||
|
||||
private class SingleDeliveryValue(string text)
|
||||
{
|
||||
public string Text => text;
|
||||
|
|
Загрузка…
Ссылка в новой задаче