Skip to content

Commit

Permalink
(chocolateyGH-181) prompt_for_confirmation_short code review
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrondeau committed Mar 30, 2015
1 parent c738ce1 commit af5191c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,17 +495,42 @@ public void should_error_when_the_prompt_input_is_null()
choices = new List<string> { "bob" };
prompt_value = null;
bool errored = false;
string errorMessage = string.Empty;
console.Setup(c => c.ReadLine()).Returns(""); //Enter pressed
try
{
prompt();
}
catch (Exception)
catch (Exception ex)
{
errored = true;
errorMessage = ex.Message;
}

errored.ShouldBeTrue();
errorMessage.ShouldContain("Value for prompt cannot be null.");
console.Verify(c => c.ReadLine(), Times.Never);
}

[Fact]
public void should_error_when_the_choicelist_contains_empty_values()
{
choices = new List<string> { "bob", "" };
bool errored = false;
string errorMessage = string.Empty;
console.Setup(c => c.ReadLine()).Returns(""); //Enter pressed
try
{
prompt();
}
catch (Exception ex)
{
errored = true;
errorMessage = ex.Message;
}

errored.ShouldBeTrue();
errorMessage.ShouldContain("Some choices are empty.");
console.Verify(c => c.ReadLine(), Times.Never);
}

Expand All @@ -527,7 +552,7 @@ public void should_error_when_the_choicelist_has_multiple_items_with_same_first_
}

errored.ShouldBeTrue();
errorMessage.ShouldContain("Multiple choices have the same first letter. Please ensure you pass choices with different first letters.");
errorMessage.ShouldContain("Multiple choices have the same first letter.");
console.Verify(c => c.ReadLine(), Times.Never);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public static string prompt_for_confirmation_short(string prompt, IEnumerable<st
.meets(
c => c.Any(),
(name, value) => { throw new ApplicationException("No choices passed in. Please ensure you pass choices."); });
Ensure
.that(() => choices)
.meets(
c => !c.Any(String.IsNullOrWhiteSpace),
(name, value) => { throw new ApplicationException("Some choices are empty. Please ensure you provide no empty choices."); });
Ensure
.that(() => choices)
.meets(
Expand All @@ -65,7 +70,7 @@ public static string prompt_for_confirmation_short(string prompt, IEnumerable<st
// check to see if value was passed
foreach (var choice in choices)
{
if (choice.is_equal_to(selection) || choice.FirstOrDefault().ToString().is_equal_to(selection))
if (choice.is_equal_to(selection) || choice.Substring(0, 1).is_equal_to(selection))
{
selection = choice;
return selection;
Expand Down

0 comments on commit af5191c

Please sign in to comment.