コード例 #1
0
        public IEnumerable <TrainingTest> GetAllTrainingTests()
        {
            TestContext        context = HttpContext.RequestServices.GetService(typeof(TestContext)) as TestContext;
            GetAllTestsHandler handler = new GetAllTestsHandler(context);

            return(handler.Handle());
        }
コード例 #2
0
        public void GetAllTests()
        {
            // arrange
            List <TrainingTest> list     = new List <TrainingTest>();
            List <TrainingTest> expected = new List <TrainingTest>(2);

            expected.Add(new TrainingTest
            {
                CourseId     = 1,
                SpecialistId = 1,
                TopicId      = 1,
                Date         = new DateTime(),
                Result       = 97
            });

            expected.Add(new TrainingTest
            {
                CourseId     = 1,
                SpecialistId = 1,
                TopicId      = 1,
                Date         = new DateTime(),
                Result       = 30
            });

            //act
            Test.Data.TestContext context = new Test.Data.TestContext(connString);
            GetAllTestsHandler    handler = new GetAllTestsHandler(context);

            handler.Handle();


            using (conn = new MySqlConnection(connString))
            {
                conn.Open();
                string query = string.Format("select * from training_tests");

                MySqlCommand cmd = new MySqlCommand(query, conn);

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        list.Add(new TrainingTest()
                        {
                            Id           = Convert.ToInt32(reader["training_id"]),
                            Date         = Convert.ToDateTime(reader["date"]),
                            Result       = Convert.ToInt32(reader["result"]),
                            SpecialistId = Convert.ToInt32(reader["Specialists_specialist_id"]),
                            TopicId      = Convert.ToInt32(reader["Topics_topic_id"]),
                            CourseId     = Convert.ToInt32(reader["Topics_Courses_course_id"])
                        });
                    }
                }
            }

            if (list[0].Result == expected[0].Result && list[0].SpecialistId == expected[0].SpecialistId &&
                list[0].TopicId == expected[0].TopicId && list[0].Date == expected[0].Date &&
                list[0].CourseId == expected[0].CourseId &&
                list[1].Result == expected[1].Result && list[1].SpecialistId == expected[1].SpecialistId &&
                list[0].TopicId == expected[1].TopicId && list[1].Date == expected[1].Date &&
                list[1].CourseId == expected[1].CourseId)
            {
                Assert.IsTrue(true);
            }
        }