Refactor error handling in Bumper, Media, Group, and Junction components to include contextual information
Updated error definitions in BumperErrors, MediaErrors, GroupErrors, and TemplateErrors to accept a parameter for contextual information, enhancing the clarity of error messages. Refactored related command handlers to utilize these updated error messages, ensuring that users receive specific details about the usage context when attempting to delete resources. Adjusted unit tests to verify the correctness of the new error handling logic.
This commit is contained in:
@@ -155,7 +155,7 @@ public class DeleteGuardsTests
|
||||
);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(MediaErrors.InUse, result.Error);
|
||||
Assert.Equal(MediaErrors.InUse(string.Empty).Code, result.Error.Code);
|
||||
// Файлы не тронуты: до чистки хранилища дело не дошло.
|
||||
await storage
|
||||
.DidNotReceiveWithAnyArgs()
|
||||
@@ -184,7 +184,7 @@ public class DeleteGuardsTests
|
||||
).Handle(new DeleteMediaAssetCommand(asset.Id), CancellationToken.None);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(MediaErrors.InUse, result.Error);
|
||||
Assert.Equal(MediaErrors.InUse(string.Empty).Code, result.Error.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -222,7 +222,7 @@ public class DeleteGuardsTests
|
||||
);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(GroupErrors.InUse, result.Error);
|
||||
Assert.Equal(GroupErrors.InUse(string.Empty).Code, result.Error.Code);
|
||||
}
|
||||
|
||||
/// <summary>Запасная группа шаблона внешнего ключа не имеет — её пришлось бы ловить отдельно.</summary>
|
||||
@@ -248,7 +248,38 @@ public class DeleteGuardsTests
|
||||
);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(GroupErrors.InUse, result.Error);
|
||||
Assert.Equal(GroupErrors.InUse(string.Empty).Code, result.Error.Code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Отказ должен называть адрес: «используется в сетке» без имени канала отправляет обходить
|
||||
/// их все руками. Связи полные — значит и канал в тексте есть.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DeleteGroup_UsedByChannel_NamesIt()
|
||||
{
|
||||
var fixture = new TestDb();
|
||||
var group = Group.Create("G");
|
||||
var channel = Channel.Create("Первый", $"first-{Guid.NewGuid():N}", T0);
|
||||
var template = ScheduleTemplate.Create(channel.Id, "Сетка");
|
||||
template.SetFallbackGroup(group.Id);
|
||||
|
||||
await using (var seed = fixture.New())
|
||||
{
|
||||
seed.Groups.Add(group);
|
||||
seed.Channels.Add(channel);
|
||||
seed.ScheduleTemplates.Add(template);
|
||||
await seed.SaveChangesAsync(CancellationToken.None);
|
||||
}
|
||||
|
||||
await using var db = fixture.New();
|
||||
var result = await new DeleteGroupCommandHandler(db).Handle(
|
||||
new DeleteGroupCommand(group.Id),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Contains("Первый", result.Error.Message, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user