Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Keybinding.Test/BlankCommandIdTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2023-2026 ktsu-dev contributors

namespace ktsu.Keybinding.Test;

using ktsu.Keybinding.Core.Services;

[TestClass]
public class BlankCommandIdTests
{
private ProfileManager _profiles = null!;
private KeybindingService _service = null!;

[TestInitialize]
public void Setup()
{
_profiles = new ProfileManager();
_profiles.CreateProfile("p", "Profile");
_service = new KeybindingService(new CommandRegistry(), _profiles);
}

[TestMethod]
[DataRow("")]
[DataRow(" ")]
[DataRow(null)]
public void ActiveProfileOverloads_BlankCommandId_MatchTheProfileIdOverloads(string? commandId)
{
Assert.IsNull(_service.GetChord(commandId!));
Assert.IsFalse(_service.UnbindChord(commandId!));
Assert.IsFalse(_service.HasChordBinding(commandId!));

_profiles.SetActiveProfile("p");

Assert.IsNull(_service.GetChord(commandId!), "GetChord should not depend on whether a profile is active.");
Assert.IsFalse(_service.UnbindChord(commandId!), "UnbindChord should not depend on whether a profile is active.");
Assert.IsFalse(_service.HasChordBinding(commandId!), "HasChordBinding should not depend on whether a profile is active.");

Assert.AreEqual(_service.GetChord("p", commandId!), _service.GetChord(commandId!));
Assert.AreEqual(_service.UnbindChord("p", commandId!), _service.UnbindChord(commandId!));
Assert.AreEqual(_service.HasChordBinding("p", commandId!), _service.HasChordBinding(commandId!));
}
}
15 changes: 15 additions & 0 deletions Keybinding/Services/KeybindingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
throw new ArgumentException("Profile ID cannot be null or whitespace", nameof(id));
}

ArgumentException.ThrowIfNullOrWhiteSpace(name, nameof(name));

Check warning on line 39 in Keybinding/Services/KeybindingService.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this argument from the method call; it hides the caller information.

Check warning on line 39 in Keybinding/Services/KeybindingService.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this argument from the method call; it hides the caller information.

Check warning on line 39 in Keybinding/Services/KeybindingService.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this argument from the method call; it hides the caller information.

Check warning on line 39 in Keybinding/Services/KeybindingService.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this argument from the method call; it hides the caller information.

Check warning on line 39 in Keybinding/Services/KeybindingService.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this argument from the method call; it hides the caller information.

Check warning on line 39 in Keybinding/Services/KeybindingService.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this argument from the method call; it hides the caller information.

Check warning on line 39 in Keybinding/Services/KeybindingService.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this argument from the method call; it hides the caller information.

Check warning on line 39 in Keybinding/Services/KeybindingService.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this argument from the method call; it hides the caller information.

Check warning on line 39 in Keybinding/Services/KeybindingService.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this argument from the method call; it hides the caller information.

Check warning on line 39 in Keybinding/Services/KeybindingService.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this argument from the method call; it hides the caller information.

return _profileManager.CreateProfile(id, name, description);
}
Expand Down Expand Up @@ -89,6 +89,11 @@
/// <inheritdoc/>
public Chord? GetChord(string commandId)
{
if (string.IsNullOrWhiteSpace(commandId))
{
return null;
}

Profile? activeProfile = _profileManager.GetActiveProfile();
return activeProfile?.GetChord(commandId);
}
Expand Down Expand Up @@ -127,6 +132,11 @@
/// <inheritdoc/>
public bool UnbindChord(string commandId)
{
if (string.IsNullOrWhiteSpace(commandId))
{
return false;
}

Profile? activeProfile = _profileManager.GetActiveProfile();
return activeProfile?.RemoveChord(commandId) ?? false;
}
Expand Down Expand Up @@ -249,6 +259,11 @@
/// <inheritdoc/>
public bool HasChordBinding(string commandId)
{
if (string.IsNullOrWhiteSpace(commandId))
{
return false;
}

Profile? activeProfile = _profileManager.GetActiveProfile();
return activeProfile?.HasChord(commandId) ?? false;
}
Expand Down
Loading