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; } }
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); }
public void InitializeQuestionsDBTest() { // Arrange InitializeDB initializeDB = new InitializeDB(); // Act var questions = initializeDB.InitializeQuestionsDB(); // Assert Assert.IsNotNull(questions); }
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"); }