public bool UpdateCourse(int id, [FromBody] CreateCourseCommand request)
        {
            CourseContext       context = HttpContext.RequestServices.GetService(typeof(CourseContext)) as CourseContext;
            UpdateCourseHandler handler = new UpdateCourseHandler(context);

            return(handler.Handle(id, request));
        }
        public void UpdateCourseTest()
        {
            // arrange
            List <MedicalCourse> list = new List <MedicalCourse>();
            int id = 2;

            MedicalCourse expected = new MedicalCourse
            {
                Id            = id,
                Name          = "Ёндокринологи¤",
                Qualification = 2
            };

            CreateCourseCommand command = new CreateCourseCommand
            {
                Name          = "Ёндокринологи¤",
                Qualification = 2
            };

            //act
            Course.Data.CourseContext courseContext       = new Course.Data.CourseContext(connString);
            UpdateCourseHandler       createCourseHandler = new UpdateCourseHandler(courseContext);

            createCourseHandler.Handle(2, command);


            using (conn = new MySqlConnection(connString))
            {
                conn.Open();
                string query = string.Format("select * from Courses where course_name='Ёндокринологи¤' and qualification=2");

                MySqlCommand cmd = new MySqlCommand(query, conn);

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        list.Add(new MedicalCourse()
                        {
                            Id            = Convert.ToInt32(reader["course_id"]),
                            Name          = reader["course_name"].ToString(),
                            Qualification = Convert.ToInt32(reader["qualification"])
                        });
                    }
                }
            }

            if (list[0].Name == expected.Name && list[0].Qualification == expected.Qualification && list[0].Id == id)
            {
                Assert.IsTrue(true);
            }
        }
Exemplo n.º 3
0
        public async Task UpdateCourseTest_Should_Return_Id()
        {
            //Arrange
            var request = new UpdateCourseCommand
            {
                Id        = 1,
                Name      = "Math",
                Price     = 5000,
                StartTime = new DateTime(2021, 02, 02, 10, 00, 00),
                EndTime   = new DateTime(2021, 02, 04, 12, 00, 00),
            };

            var handler = new UpdateCourseHandler(_mapper, _fakeRepository);

            //Act
            var id = await handler.Handle(request, new CancellationToken());

            //Assert
            Assert.AreEqual(id, 1);
        }