コード例 #1
0
        public async Task Should_throw_not_found_exception()
        {
            var updateCourseCommand = new UpdateCourseCommand()
            {
                Id          = Guid.NewGuid(),
                Code        = 1,
                Name        = "Course 1",
                Description = "Test"
            };

            var updateCourseCommandHandler = new UpdateCourseCommandHandler(this.autoMapper, this.context);

            await Assert.ThrowsAsync <NotFoundException>(() => updateCourseCommandHandler.Handle(updateCourseCommand, CancellationToken.None));
        }
コード例 #2
0
        public void SetUp()
        {
            _service       = new Mock <IUpdateCourseService>();
            _commonService = new Mock <ICoursesCommonService>();
            _unitOfWork    = new Mock <IUnitOfWork>();
            _command       = new UpdateCourseCommand()
            {
                CourseId = "courseId"
            };
            _sut = new UpdateCourseCommandHandler(_service.Object, _commonService.Object, _unitOfWork.Object);

            _courseToUpdate = new Course("title", "creatorId", DateTime.Now);
            _commonService.Setup(x => x.GetCourseFromRepo(_command.CourseId, default))
            .ReturnsAsync(_courseToUpdate);
        }
コード例 #3
0
        public async Task Should_update_student()
        {
            // create course
            var createCourseCommand = new CreateCourseCommand()
            {
                Id          = Guid.NewGuid(),
                Code        = 1,
                Name        = "Course 1",
                Description = "Test"
            };

            var createCourseCommandHandler = new CreateCourseCommandHandler(this.autoMapper, this.context);

            var result = await createCourseCommandHandler.Handle(createCourseCommand, CancellationToken.None);

            result.ShouldBe(true);

            var updateCourseCommand = new UpdateCourseCommand()
            {
                Id          = createCourseCommand.Id,
                Code        = 1,
                Name        = "Course 2",
                Description = "Test"
            };

            var updateCourseCommandHandler = new UpdateCourseCommandHandler(this.autoMapper, this.context);

            result = await updateCourseCommandHandler.Handle(updateCourseCommand, CancellationToken.None);

            result.ShouldBe(true);

            var dbCourse = await this.context.Course.FirstOrDefaultAsync(s => s.Id == updateCourseCommand.Id);

            dbCourse.ShouldNotBeNull();
            dbCourse.Name.ShouldBe(updateCourseCommand.Name);
        }