Refactor group mode switching logic to ensure proper list management
Updated the Group and UpdateGroupCommandHandler classes to clarify the behavior of group mode switching. The transition to dynamic mode now clears the existing item list to prevent old items from interfering with the new rule-based composition. Enhanced documentation and comments to explain the implications of mode changes. Updated tests to reflect the new behavior, ensuring that the group correctly handles item lists during mode transitions. Localization strings were also updated to inform users about the changes in item management during mode switching.
This commit is contained in:
@@ -103,22 +103,26 @@ public class GroupTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetMode_ToDynamic_KeepsItemsAsPinned()
|
||||
public void SetMode_ToDynamic_DropsTheOldList()
|
||||
{
|
||||
// Смена режима не должна вымывать из эфира то, что уже стояло в слотах.
|
||||
// Прежний состав, перенесённый закреплённым, отменял бы сам переход: правило считало бы
|
||||
// набор заново, а старые позиции оставались бы в нём навсегда — сузить группу правилом
|
||||
// стало бы нечем.
|
||||
var group = Group.Create("Боевики");
|
||||
var show = Guid.NewGuid();
|
||||
group.AddElement(GroupElementKind.Show, show);
|
||||
group.AddElement(GroupElementKind.Show, Guid.NewGuid());
|
||||
group.AddElement(GroupElementKind.Show, Guid.NewGuid());
|
||||
|
||||
group.SetMode(GroupMode.Dynamic);
|
||||
|
||||
Assert.Equal(GroupMode.Dynamic, group.Mode);
|
||||
Assert.Equal(GroupItemRole.Pinned, group.Items.Single().Role);
|
||||
Assert.Empty(group.Items);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetMode_BackToStatic_DropsExclusionsAndUnpins()
|
||||
public void SetMode_BackToStatic_DropsCorrectionsToo()
|
||||
{
|
||||
// В обратную сторону симметрично: закрепления и исключения — поправки к правилу, и без
|
||||
// правила они бессмысленны. Состав статической группе выдаёт прикладной слой.
|
||||
var group = Group.Create("Боевики");
|
||||
group.SetMode(GroupMode.Dynamic);
|
||||
group.AddElement(GroupElementKind.Show, Guid.NewGuid());
|
||||
@@ -126,9 +130,7 @@ public class GroupTests
|
||||
|
||||
group.SetMode(GroupMode.Static);
|
||||
|
||||
// Исключать в статической группе нечего: состав и есть список.
|
||||
var item = Assert.Single(group.Items);
|
||||
Assert.Equal(GroupItemRole.Member, item.Role);
|
||||
Assert.Empty(group.Items);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user