示例#1
0
        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");
            }
        }
 /// <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));
 }
示例#3
0
        public void Model_WordQuiz_DefaultConstructor()
        {
            //arrange
            var quiz = new WordQuiz();

            // act

            // Assert
            Assert.IsNotNull(quiz, "WordQuiz created by default constructor is supposed to be non-null");
        }
示例#4
0
        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
        }
示例#5
0
        public void Controller_Quiz_Check()
        {
            // Arrange
            var controller = new QuizController();
            var word       = new WordQuiz();

            word.English = "Day";
            word.Czech   = "Den";

            // Act
            var jsonResult = controller.CheckWord(word) as JsonResult;

            // Assert
            Assert.IsNotNull(jsonResult, "Expected a non-null PartialViewResult");
            Assert.IsInstanceOfType(jsonResult.Data, typeof(bool), "Expected a bool result");
        }
示例#6
0
        public void Model_WordQuiz_Constructor()
        {
            //Arrange
            var word = new Word();

            word.English = ENGLISH;
            word.Czech   = CZECH;
            var quiz = new WordQuiz(word);

            //Act

            //Assert: ensure that the properties map to the word object
            Assert.IsNotNull(quiz, "WordQuiz created by constructor is supposed to be non-null");
            Assert.AreEqual(quiz.English, word.English, "Word and Test Word English property do not match");
            Assert.AreEqual(quiz.Czech, word.Czech, "Word and Test Word Czech property do not match");
            Assert.IsTrue(quiz.hintLevel == 0, "Initial hint level is not 0");
        }
示例#7
0
        protected async Task GetWordQuiz()
        {
            if (QuizArea == null || QuizLevel == 0)
            {
                return;
            }

            QuizData = await WordQuiz.GetWordQuiz(QuizArea, QuizLevel);

            Quizzes     = QuizData.Quizlist;
            CurrentQuiz = Quizzes[track];
            isQuizReady = true;
            isZoomDown  = true;
            seconds     = 10;
            isStartTime = true;

            StateHasChanged();
        }
示例#8
0
        public void Model_WordQuiz_Validation()
        {
            //Arrange
            var quiz = new WordQuiz();

            quiz.Czech   = CZECH;
            quiz.English = ENGLISH;

            //Assert (wrong translation yields validation errors)
            quiz.userTranslation = ENGLISH;
            var validationErrors = quiz.Validate(null);

            Assert.IsFalse(validationErrors.ToList().Count == 0);

            //Assert (right translation yields no validation errors)
            quiz.userTranslation = CZECH;
            validationErrors     = quiz.Validate(null);
            Assert.IsTrue(validationErrors.ToList().Count == 0);
        }
示例#9
0
        public void Controller_Quiz_Hint()
        {
            // Arrange
            var controller = new QuizController();
            var word       = new WordQuiz();

            word.English = "Day";
            word.Czech   = "Den";

            // Act
            var result = controller.Hint(word) as JsonResult;

            // Assert: we get back a wordquiz object with the same properties, but hint level increased by 1
            Assert.IsNotNull(word, "Expected a non-null JsonResult");
            var Data = result.Data as WordQuiz;

            Assert.IsNotNull(word, "Expected a non-null WordQuiz instance");
            Assert.AreEqual(word.English, Data.English, "English field modified after a Hint () request");
            Assert.AreEqual(word.Czech, Data.Czech, "Czech field modified after a Hint () request");
            Assert.AreEqual(Data.hintLevel, 1, "Hint level field not increased by 1 after a Hint () request");
        }
示例#10
0
 public JsonResult CheckWord(WordQuiz word)
 {
     // Use validation to check whether the user's guess was successful or not
     return(Json(ModelState.IsValid));
 }