summaryrefslogtreecommitdiffstats
path: root/src/main.test/Mock/Services/InputService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.test/Mock/Services/InputService.cs')
-rw-r--r--src/main.test/Mock/Services/InputService.cs26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/main.test/Mock/Services/InputService.cs b/src/main.test/Mock/Services/InputService.cs
index 3771cab..58e8d2b 100644
--- a/src/main.test/Mock/Services/InputService.cs
+++ b/src/main.test/Mock/Services/InputService.cs
@@ -43,25 +43,31 @@ namespace PKISharp.WACS.UnitTests.Mock.Services
FirstOrDefault(c => string.Equals(c.Command, input, StringComparison.CurrentCultureIgnoreCase)).Item);
}
- public Task<TResult> ChooseFromMenu<TResult>(string what, List<Choice<TResult>> choices)
- {
- var input = GetNextInput();
- return Task.
- FromResult(choices.
- FirstOrDefault(c => string.Equals(c.Command, input, StringComparison.CurrentCultureIgnoreCase)).Item);
- }
-
public string FormatDate(DateTime date) => "";
public Task<bool> PromptYesNo(string message, bool defaultOption)
{
var input = GetNextInput();
return Task.FromResult(string.Equals(input, "y", StringComparison.CurrentCultureIgnoreCase));
}
- public Task<string> ReadPassword(string what) => Task.FromResult(GetNextInput());
+ public Task<string?> ReadPassword(string what) => Task.FromResult(GetNextInput());
public Task<string> RequestString(string what) => Task.FromResult(GetNextInput());
public Task<string> RequestString(string[] what) => Task.FromResult(GetNextInput());
- public void Show(string label, string value = null, bool first = false, int level = 0) { }
+ public void Show(string? label, string? value = null, bool first = false, int level = 0) { }
public Task<bool> Wait(string message = "") => Task.FromResult(true);
public Task WritePagedList(IEnumerable<Choice> listItems) => Task.CompletedTask;
+ public Task<TResult> ChooseFromMenu<TResult>(string what, List<Choice<TResult>> choices, Func<string, Choice<TResult>>? unexpected = null)
+ {
+ var input = GetNextInput();
+ var choice = choices.FirstOrDefault(c => string.Equals(c.Command, input, StringComparison.CurrentCultureIgnoreCase));
+ if (choice == null && unexpected != null)
+ {
+ choice = unexpected(input);
+ }
+ if (choice != null)
+ {
+ return Task.FromResult(choice.Item);
+ }
+ throw new Exception();
+ }
}
}