/// <summary> /// Provides a hint for the supplied word as a JSON object /// </summary> /// <param name="userWord"></param> /// <returns></returns> public JsonResult Hint(WordQuiz userWord) { // Apply the hint for the word userWord.Hint(); // Return the word with updated hint info serialized as Json return Json(userWord, JsonRequestBehavior.AllowGet); }
public void Model_WordQuiz_Hint() { // Arrange var quiz = new WordQuiz(); quiz.English = "Saturday"; quiz.Czech = "Sobota"; // Act + Assert Assert.IsTrue(quiz.userTranslation.Equals(String.Empty)); quiz.Hint(); Assert.IsTrue (quiz.userTranslation.Equals ("S*****"),"Hint failed on level 1"); quiz.Hint(); Assert.IsTrue(quiz.userTranslation.Equals("So****"), "Hint failed on level 2"); quiz.Hint(); Assert.IsTrue(quiz.userTranslation.Equals("Sob***"), "Hint failed on level 3"); quiz.Hint(); Assert.IsTrue(quiz.userTranslation.Equals("Sobo**"), "Hint failed on level 4"); quiz.Hint(); Assert.IsTrue(quiz.userTranslation.Equals("Sobot*"), "Hint failed on level 5"); quiz.Hint(); Assert.IsTrue(quiz.userTranslation.Equals("Sobota"), "Hint failed on level 6"); // At this point, it should validate OK var validationErrors = quiz.Validate(null); Assert.IsTrue(validationErrors.ToList().Count == 0, "Word quiz does not validate successfully after as many hints as its word length"); // Test that any further quizzes don't break for (int i = 0; i < 100; i++) { quiz.Hint(); Assert.IsTrue(quiz.userTranslation.Equals("Sobota"), "Hint failed when over the word length"); } }
public void Model_WordQuiz_HintOnEmptyCzech() { // Arrange var quiz = new WordQuiz(); quiz.English = "ABCDE"; // Act + Assert Assert.IsTrue(quiz.userTranslation.Equals(String.Empty)); quiz.Hint(); // This should throw as English is null ATM }