Beispiel #1
0
        public void UpdateResultsOfExamTest()
        {
            List <bool> boolList = new List <bool>();
            int         id       = 7;

            ResultsOfExam resultsOfExam = (ResultsOfExam)dbContext.ResultsOfExamsRepository.GetById(id);
            ResultsOfExam tmp           = new ResultsOfExam();

            tmp.Id      = resultsOfExam.Id;
            tmp.Exam    = resultsOfExam.Exam;
            tmp.Student = resultsOfExam.Student;
            tmp.Result  = resultsOfExam.Result;

            resultsOfExam.Result = 2;
            boolList.Add(dbContext.ResultsOfExamsRepository.Update(resultsOfExam));

            ResultsOfExam updatedResultsOfExam = (ResultsOfExam)dbContext.ResultsOfExamsRepository.GetById(id);

            boolList.Add(updatedResultsOfExam.Result == resultsExamObjCase.Result ? true : false);

            dbContext.ResultsOfExamsRepository.Update(tmp);

            bool isEqualCollections = boolList.Contains(false);

            Assert.IsTrue(!isEqualCollections);
        }
Beispiel #2
0
        public void GetAllResultsOfExamsTest()
        {
            List <bool>          isEqualList    = new List <bool>();
            List <ResultsOfExam> resultsOfExams = dbContext.ResultsOfExamsRepository.GetAll();

            foreach (var resultsOfExam in resultsOfExams)
            {
                ResultsOfExam obj = resultsExamsCases.Where(o => o.Id == resultsOfExam.Id &&
                                                            o.ExamId == resultsOfExam.ExamId &&
                                                            o.StudentId == resultsOfExam.StudentId &&
                                                            o.Result == resultsOfExam.Result)
                                    .FirstOrDefault();
                isEqualList.Add(obj == null ? false : true);
            }
            bool isEqualCollections = isEqualList.Contains(false);

            Assert.IsTrue(!isEqualCollections);
        }
Beispiel #3
0
        /// <summary>
        /// Method for get results of exam by id value from the database
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public override BaseModel GetById(int id)
        {
            ResultsOfExam results = null;

            using (SqlConnection connection = new SqlConnection(base.ConnectionString))
            {
                using (var query = new SqlCommand())
                {
                    query.Connection  = connection;
                    query.CommandText = SqlQueriesHelper.FormSelectByIdQuery(typeof(ResultsOfExam), id);

                    query.Connection.Open();
                    using (SqlDataReader reader = query.ExecuteReader())
                    {
                        if (reader.HasRows && reader.Read())
                        {
                            results = new ResultsOfExam()
                            {
                                Id      = (int)reader["Id"],
                                Student = new Student {
                                    Id = (int)reader["StudentId"]
                                },
                                Exam = new Exam {
                                    Id = (int)reader["ExamId"]
                                },
                                Result = (int)reader["Result"]
                            };
                        }
                    }
                    query.Connection.Close();
                }
            }
            if (results != null)
            {
                Student student = (Student)base.DbContext.StudentsRepository.GetById(results.Student.Id);
                Exam    exam    = (Exam)base.DbContext.ExamsRepository.GetById(results.Exam.Id);
                results.Student = student;
                results.Exam    = exam;
            }
            return(results);
        }
Beispiel #4
0
        public void GetResultsOfExamsByIdTest()
        {
            List <bool> isEqualList = new List <bool>();
            List <int>  ids         = new List <int>()
            {
                4, 5, 7
            };

            foreach (int id in ids)
            {
                ResultsOfExam resultsOfExam = dbContext.ResultsOfExamsRepository.GetById(id);
                ResultsOfExam obj           = resultsExamsCases.Where(o => o.Id == resultsOfExam.Id &&
                                                                      o.ExamId == resultsOfExam.ExamId &&
                                                                      o.StudentId == resultsOfExam.StudentId &&
                                                                      o.Result == resultsOfExam.Result)
                                              .FirstOrDefault();
                isEqualList.Add(obj == null ? false : true);
            }
            bool isEqualCollections = isEqualList.Contains(false);

            Assert.IsTrue(!isEqualCollections);
        }