示例#1
0
        public bool AnswerQuestion(string json)
        {
            try
            {
                var answer = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);

                int question = 0;
                Int32.TryParse(answer["Question"], out question);
                string answers = answer["Answer"];

                var inializeDb = new InitializeDB(this.configuration);
                this.questions = inializeDb.InitializeQuestionsDB();
                this.variants  = inializeDb.InitializeAnswersDB();

                var qId = this.questions.Where(x => x.Id == question)
                          .Select(x => x.Id).FirstOrDefault();

                var qIdVariants = this.variants.Where(x => x.QuestionsId == qId)
                                  .Select(x => new { Answer = x.Answer, Correct = x.Correct });

                var verdict = qIdVariants.Where(x => x.Answer == answers)
                              .Select(x => x.Correct).FirstOrDefault();

                return(verdict);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
示例#2
0
        public List <int> RandomQuestionIds()
        {
            var initializeDb = new InitializeDB(this.configuration);
            var questionIds  = initializeDb.InitializeQuestionsDB().Count;
            var RandomIds    = new List <int>(Enumerable.Range(1, questionIds));

            RandomIds.Shuffle();

            return(RandomIds);
        }
示例#3
0
        public void InitializeQuestionsDBTest()
        {
            // Arrange
            InitializeDB initializeDB = new InitializeDB();

            // Act
            var questions = initializeDB.InitializeQuestionsDB();

            // Assert
            Assert.IsNotNull(questions);
        }
示例#4
0
        public string GetNextQuestion(int questionId)
        {
            if (questionId != 0)
            {
                var inializeDb = new InitializeDB(this.configuration);
                this.questions = inializeDb.InitializeQuestionsDB();
                this.variants  = inializeDb.InitializeAnswersDB();

                var question = this.questions.Where(x => x.Id == questionId).FirstOrDefault();
                var answers  = this.variants.Where(x => x.QuestionsId == questionId)
                               .Select(x => x.Answer).ToArray();
                return(this.CreateJsonQuestion(question, answers));
            }

            return("Не верный id");
        }