コード例 #1
0
        public void GetExamFromAPI()
        {
            var examService      = new ExamService();
            var candidateService = new CandidateService();

            var exam = examService.GetLatestOpenExamWithQuestionOptions(candidateService.GetCandidate("*****@*****.**").Id);

            exam.Questions.ToList().ForEach(x => x.Options.ToList().ForEach(y =>
            {
                var relatedQuestions = examService.GetRelatedQuestions(y.Id);

                var answer = new Answer
                {
                    AnswerText = string.Empty,
                    Level      = x.Level,
                    ScorePoint = x.ScorePoint,
                    Id         = Guid.NewGuid(),

                    //need to use DbContext.QuestionsOption.Attach() if you want to use this
                    Option = new Option {
                        Id = y.Id, IsSelected = y.IsSelected
                    },
                    Exam = new Exam {
                        Id = exam.Id, Text = exam.Text
                    }
                };

                var answerReturned = examService.AddAnswer(answer);

                Debug.WriteLine(relatedQuestions.Count);
            }));

            Assert.IsNotNull(exam);
        }