Пример #1
0
        public void UpdateCourseTest()
        {
            //// Arranage
            var errors = new List<string>();

            Mock<ICourseRepository> mockRepository = new Mock<ICourseRepository>();
            CourseService iserv = new CourseService(mockRepository.Object);

            Course s = new Course { CourseId = 99, Title = "T", Description = "Test" };

            mockRepository.Setup(x => x.UpdateCourse(s, ref errors));

            //// Act
            iserv.UpdateCourse(s, ref errors);

            //// Assert
            mockRepository.Verify(x => x.UpdateCourse(s, ref errors), Times.Once());
        }
Пример #2
0
        public void UpdateCourseErrorTest1()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);

            //// Act
            courseService.UpdateCourse(null, ref errors);

            //// Assert course object not null
            Assert.AreEqual(1, errors.Count);
        }
Пример #3
0
        public void UpdateCourseErrorTest2()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);
            var course = new Course { Title = string.Empty };

            //// Act
            courseService.UpdateCourse(course, ref errors);

            //// Assert first name cannot be empty
            Assert.AreEqual(1, errors.Count);
        }
Пример #4
0
        public string UpdateCourse(Course course)
        {
            var errors = new List<string>();
            var repository = new CourseRepository(this.entities);
            var service = new CourseService(repository);
            service.UpdateCourse(course, ref errors);

            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }