Esempio n. 1
0
        public void AquiringARandomIntegerShouldReturnNumbersBetweenOneAndTenInclusiveWhenTheNumberOfRowsInATableAreTen()
        {
            // Arrange
            Mock <IDataBaseTable> mockDatabase = new Mock <IDataBaseTable>();

            mockDatabase.Setup(r => r.RetrieveNumberOfRowsInTable()).Returns(10);
            sut = new Trivia(mockDatabase.Object, question);
            int     i = 0;
            Boolean flag;

            // Act
            while (i < 1000)
            {
                int test = sut.RandomGenerator();

                // Assert
                Assert.AreNotEqual(0, test);
                Assert.AreNotEqual(11, test);

                if (test <= 0 || test >= 11)
                {
                    Assert.Fail();
                }
                if (test >= 1 && test <= 10)
                {
                    flag = true;
                    Assert.IsTrue(flag);
                }

                i++;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="questionPack"></param>
 public QuestionEvaluation(IQuestionPack questionPack)
 {
     //questionTable = new QuestionTable();
     question = new Questions();
     //trivia = new Trivia(questionTable, question);3
     trivia = new Trivia(questionPack);
 }
Esempio n. 3
0
 public void AddLeadingTrivia(ITrivia trivia)
 {
     if (_leadingTrivia == null)
     {
         var pool = SharedPools.Default <List <ITrivia> >();
         _leadingTrivia = pool.AllocateAndClear();
     }
     _leadingTrivia.Add(trivia);
 }
Esempio n. 4
0
        public void AddTrailingTrivia(ITrivia trivia)
        {
            if (_trailingTrivia is null)
            {
                var pool = SharedPools.Default <List <ITrivia> >();
                _trailingTrivia = pool.AllocateAndClear();
            }

            _trailingTrivia.Add(trivia);
        }
Esempio n. 5
0
        public void AddTrailingTrivia(ITrivia trivia)
        {
            if (this.trailingTrivia == null)
            {
                var pool = SharedPools.Default <List <ITrivia> >();
                this.trailingTrivia = ObjectPoolExtensions.Allocate(pool);
            }

            this.trailingTrivia.Add(trivia);
        }
Esempio n. 6
0
        public void AnswerEvaluationShouldMatchTheActualAnswerEvenIfTheAnswerGivenHasADifferentCaseOrHasExtraWhiteSpace()
        {
            // Arrange
            string           answerGiven = "  fAlSe  ";
            Mock <IQuestion> mockAnswer  = new Mock <IQuestion>();

            mockAnswer.Setup(r => r.Answer).Returns("False");
            sut = new Trivia(database, mockAnswer.Object);

            // Act
            Boolean test = sut.EvaluateAnswer(answerGiven);

            // Assert
            Assert.IsTrue(test);
        }
Esempio n. 7
0
        public void AnswerEvaluationShouldReturnFalseIfTheAnswerGivenDoesNotMatchTheActualAnswersStringValue()
        {
            // Arrange
            string           answerGiven = "True";
            Mock <IQuestion> mockAnswer  = new Mock <IQuestion>();

            mockAnswer.Setup(r => r.Answer).Returns("False");
            sut = new Trivia(database, mockAnswer.Object);

            // Act
            Boolean test = sut.EvaluateAnswer(answerGiven);

            // Assert
            Assert.IsFalse(test);
        }
Esempio n. 8
0
        public void AquiringARandomQuestionShouldReturnARandomTableRowFromDatabaseAndExtractOnlyTheQuestionFromTheRow()
        {
            // Arrange
            Mock <IDataBaseTable> mockDatabase = new Mock <IDataBaseTable>();

            mockDatabase.Setup(r => r.RetrieveNumberOfRowsInTable()).Returns(5);
            mockDatabase.Setup(r => r.TableName).Returns("Table Name");
            mockDatabase.Setup(r => r.RetrieveTableRow("Table Name", 1)).Returns("This is the first row.\n And this is its answer\n Question Type");
            mockDatabase.Setup(r => r.RetrieveTableRow("Table Name", 2)).Returns("This is the second row.\n And this is its answer\n Question Type");
            mockDatabase.Setup(r => r.RetrieveTableRow("Table Name", 3)).Returns("This is the third row.\n And this is its answer\n Question Type");
            mockDatabase.Setup(r => r.RetrieveTableRow("Table Name", 4)).Returns("This is the fourth row.\n And this is its answer\n Question Type");
            mockDatabase.Setup(r => r.RetrieveTableRow("Table Name", 5)).Returns("This is the fifth row.\n And this is its answer\n Question Type");
            sut = new Trivia(mockDatabase.Object, question);
            int i = 0;

            // Act
            while (i <= 5)
            {
                IQuestion test = sut.GetRandomQuestion();
                // Assert
                if (test.Question.Equals("This is the first row."))
                {
                    Assert.AreEqual("This is the first row.", test.Question);
                }
                else if (test.Question.Equals("This is the second row."))
                {
                    Assert.AreEqual("This is the second row.", test.Question);
                }
                else if (test.Question.Equals("This is the third row."))
                {
                    Assert.AreEqual("This is the third row.", test.Question);
                }
                else if (test.Question.Equals("This is the fourth row."))
                {
                    Assert.AreEqual("This is the fourth row.", test.Question);
                }
                else if (test.Question.Equals("This is the fifth row."))
                {
                    Assert.AreEqual("This is the fifth row.", test.Question);
                }
                else
                {
                    Assert.Fail();
                }
                i++;
            }
        }
Esempio n. 9
0
 public void Initialize()
 {
     question = new Questions();
     //        database = new QuestionTable();
     sut = null;
 }