public void GivenAnInvalidWord_ThenMessageIsInvalidWord() { goWords.Add(new GoWord() { Word = "ZUPER" }); itemLister.ToString(Arg.Any <IEnumerable <string> >()).Returns("ZUPER"); var result = goWordValidator.ValidateWords(goWords); result.Message.ShouldBe("ZUPER is not a valid word"); }
private GoValidationResult CheckWords(IEnumerable <GoWord> goWords) { var invalidWords = new List <string>(); foreach (var goWord in goWords) { if (!wordValidator.IsWord(goWord.Word)) { invalidWords.Add(goWord.Word); } } if (!invalidWords.Any()) { return(SuccessResult()); } var words = itemLister.ToString(invalidWords); var areInvalid = (invalidWords.Count() == 1) ? " is not a valid word" : " are not valid words"; return(new GoValidationResult() { IsValid = false, Message = $"{words}{areInvalid}" }); }
public string GetGoMessage(string playerName, IEnumerable <GoWord> goWords, int goScore) { var words = GetWordsList(goWords); string message; if (words.Count == 0) { message = "You made no words."; } else if (words.Count() == 1) { message = $"{playerName}'s word is {words.First()}."; } else { message = $"{playerName}'s words are {itemLister.ToString(words)}."; } if (goScore > 0) { message += $" {playerName} scored {goScore}."; } return(message); }