Ejemplo n.º 1
0
        public void AddCourseTest()
        {
            //// 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.AddCourse(s, ref errors));
            mockRepository.Setup(x => x.IsNotDuplicateCourse(s, ref errors)).Returns(true);

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

            //// Assert
            mockRepository.Verify(x => x.AddCourse(s, ref errors), Times.Once());
        }
Ejemplo n.º 2
0
        public void AssignPreReqPassTest()
        {
            //// Arranage
            string courseName1 = "Test5";
            string courseName2 = "Test6";
            string courseName3 = "Test7";
            var errors1 = new List<string>();
            var errors2 = new List<string>();
            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);
            var course1 = new Course { Title = courseName1 };
            var course2 = new Course { Title = courseName2 };
            var course3 = new Course { Title = courseName3 };
            courseService.InsertCourse(course1, ref errors1);
            courseService.InsertCourse(course2, ref errors1);
            courseService.InsertCourse(course3, ref errors1);

            //// Act
            courseService.AssignPreReq(1, 2, ref errors2);

            //// Assert
            Assert.AreEqual(0, errors2.Count);
        }
Ejemplo n.º 3
0
        public void InsertCourseErrorTest2()
        {
            //// 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.InsertCourse(course, ref errors);

            //// Assert last name cannot be empty
            Assert.AreEqual(1, errors.Count);
        }
Ejemplo n.º 4
0
        public void InsertCourseErrorTest1()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);

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

            //// Assert cant be null course object
            Assert.AreEqual(1, errors.Count);
        }
Ejemplo n.º 5
0
        public string InsertCourse(Course course)
        {
            var errors = new List<string>();
            var repository = new CourseRepository(this.entities);
            var service = new CourseService(repository);
            service.InsertCourse(course, ref errors);

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

            return "error";
        }