示例#1
0
        public async Task CourseShouldCallCorrectServiceMethodOnce()
        {
            var userService   = new Mock <IUserService>();
            var courseService = new Mock <ICourseService>();

            userService.Setup(us => us.GetUserByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(new User());
            courseService.Setup(cs => cs.RetrieveCoursesByTeacherAsync(It.IsAny <int>()))
            .ReturnsAsync(new List <Course>()
            {
                new Course()
                {
                    CourseId = 1, Name = "Mocking"
                }
            });

            var controller = new DashboardController(courseService.Object, userService.Object, this.SetupWrapperForInvokeTests());

            var result = await controller.Course(1);

            courseService.Verify(cs => cs.GetCourseByIdAsync(1), Times.Once);
        }