Esempio n. 1
0
        public void SetExamTest()
        {
            //Arrange

            UseSqlite();
            using (var context = GetDBContext())
            {
                FakeAccountRepository FAccount        = new FakeAccountRepository();
                FakeCourseQuestions   courseQuestions = new FakeCourseQuestions();
                context.Account.Add(FAccount.FakeAccounts.First());
                context.Course.Add(courseQuestions.Architecture);
                context.SaveChanges();


                var CQuestions = (from cq in context.ClosedQuestions
                                  where cq.CourseID == 1
                                  select cq).ToList();
                CQuestions = CQuestions.DistinctBy(q => q.Question).ToList();


                var OQuestions = (from cq in context.OpenedQuestions
                                  where cq.CourseID == 1
                                  select cq).ToList();
                OQuestions = OQuestions.DistinctBy(q => q.Question).ToList();


                //Act
                CQuestions = SelectClosedQuestions(CQuestions, 4);
                OQuestions = SelectOpenedQuestions(OQuestions, 4);

                var ExamCQuestions = CreateExamClosedQuestions(CQuestions.ToList());
                var ExamOQuestions = CreateExamOpenedQuestions(OQuestions.ToList());

                FakeExam FExam = new FakeExam();
                FExam.FakeNewExam.ExamClosedQuestions = ExamCQuestions;
                FExam.FakeNewExam.ExamOpenedQuestions = ExamOQuestions;


                context.Exams.Add(FExam.FakeNewExam);

                context.SaveChanges();

                var exam = (from ex
                            in context.Exams
                            where ex.ExamsID == 1
                            select ex).ToList();
                var x = exam.GetType();

                //Assert
                Assert.Equal("Co to jest Boxing i Unboxing", exam.First().ExamOpenedQuestions.First().OpenedQuestions.Question);
            }
        }
Esempio n. 2
0
 private void Arrange()
 {
     FSA_Repository  = new FakeAccountRepository();
     SecurityAccount = FSA_Repository.FakeAccounts;
 }
Esempio n. 3
0
        public void SaveScoreFromClosedQuestionIntoDatabaseTest()
        {
            //Arrange
            UseSqlite();
            using (var context = GetDBContext())
            {
                FakeAccountRepository FAccount        = new FakeAccountRepository();
                FakeCourseQuestions   courseQuestions = new FakeCourseQuestions();

                context.Account.Add(FAccount.FakeAccounts.First());
                context.Course.Add(courseQuestions.Architecture);
                context.SaveChanges();

                var ClosedQuestionsFromDB = context.ClosedQuestions.DistinctBy(q => q.Question).ToList();
                var ExamQuestions         = CreateExamQuestions(ClosedQuestionsFromDB);

                Exams exam = new Exams()
                {
                    AmountClosedQuestions = 7,
                    AmountOpenedQuestions = 7,

                    ExamClosedQuestions = ExamQuestions,
                    CourseID            = 1,
                    AccountID           = 1,
                    ExamTimeInMinute    = 30,
                    DateOfExam          = new DateTime(),
                    ExamResult          = new Results()
                };
                context.Exams.Add(exam);
                context.SaveChanges();


                Dictionary <string, string>           ClosedQuestionsAnswer  = new Dictionary <string, string>();
                List <KeyValuePair <string, string> > ClosedQuestionsAnswers = new List <KeyValuePair <string, string> >();

                //Act
                foreach (var x in exam.ExamClosedQuestions)
                {
                    ClosedQuestionsAnswers.Add(new KeyValuePair <string, string>(x.ClosedQuestions.Question, x.ClosedQuestions.ProperAnswer));
                }

                var examCQuestions = (from ex
                                      in context.ExamClosedQuestions
                                      where ex.ExamsID == 1
                                      select ex.ClosedQuestions).ToList();

                SetExamScoreFromClosedQuestionAnswers(examCQuestions, ClosedQuestionsAnswers, exam);


                context.Exams.Update(exam);
                context.SaveChangesAsync();

                //Assert

                var examScoreFromClosedQuestions = (from ex
                                                    in context.ExamClosedQuestions
                                                    where ex.ExamsID == 1
                                                    select ex.Exam.ExamResult.Score).Single();

                Assert.Equal(4, examScoreFromClosedQuestions);
            }
        }
 private void Arrange()
 {
     FA_Repository = new FakeAccountRepository();
     NewAccount    = FA_Repository.FakeAccounts;
 }