This commit is contained in:
Mackinnon Buck 2024-08-09 10:08:42 -07:00 коммит произвёл github-actions
Родитель 7e3032f303
Коммит a6154bb2a0
2 изменённых файлов: 37 добавлений и 1 удалений

Просмотреть файл

@ -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;