public async Task Should_throw_delete_failure_exception() { // 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 commandResult = await createCourseCommandHandler.Handle(createCourseCommand, CancellationToken.None); commandResult.ShouldBe(true); // Create student var createStudentCommand = new CreateStudentCommand() { Id = Guid.NewGuid(), FirstName = "Milos", LastName = "Stojkovic", Address = "Bata Noleta 31", City = "Sokobanja", DateOfBirth = new DateTime(1991, 3, 18), State = "Srbija", Gender = 0 }; var createStudentCommandHandler = new CreateStudentCommandHandler(this.autoMapper, this.context); commandResult = await createStudentCommandHandler.Handle(createStudentCommand, CancellationToken.None); commandResult.ShouldBe(true); var createOrUpdateEnrollmentCommand = new CreateOrUpdateEnrollmentCommand() { Id = createStudentCommand.Id, CourseCode = createCourseCommand.Code, Grade = (int)Domain.Enumerations.Grade.Seven }; var createOrUpdateEnrollmentCommandHandler = new CreateOrUpdateEnrollmentCommandHandler(this.context); commandResult = await createOrUpdateEnrollmentCommandHandler.Handle(createOrUpdateEnrollmentCommand, CancellationToken.None); commandResult.ShouldBe(true); var deleteCourseCommand = new DeleteCourseCommand() { Id = createCourseCommand.Id }; var deleteCourseCommandHandler = new DeleteCourseCommandHandler(this.context); await Assert.ThrowsAsync <DeleteFailureException>(() => deleteCourseCommandHandler.Handle(deleteCourseCommand, CancellationToken.None)); }
public async Task Should_throw_not_found_exception() { var deleteCourseCommand = new DeleteCourseCommand() { Id = Guid.NewGuid() }; var deleteCourseCommandHandler = new DeleteCourseCommandHandler(this.context); await Assert.ThrowsAsync <NotFoundException>(() => deleteCourseCommandHandler.Handle(deleteCourseCommand, CancellationToken.None)); }
public void SetUp() { _service = new Mock <IDeleteCourseService>(); _commonService = new Mock <ICoursesCommonService>(); _unitOfWork = new Mock <IUnitOfWork>(); _mediator = new Mock <IMediator>(); _command = new DeleteCourseCommand { CourseId = "courseId" }; _sut = new DeleteCourseCommandHandler(_service.Object, _commonService.Object, _unitOfWork.Object, _mediator.Object); _courseToDelete = new Course("name", "creatorId", DateTime.Now); _commonService.Setup(x => x.GetCourseFromRepo(_command.CourseId, default)) .ReturnsAsync(_courseToDelete); }
public async Task Should_delete_course() { var deleteCourseCommand = new DeleteCourseCommand() { Id = Guid.NewGuid() }; var deleteCourseCommandHandler = new DeleteCourseCommandHandler(this.context); var result = await deleteCourseCommandHandler.Handle(deleteCourseCommand, CancellationToken.None); result.ShouldBe(true); var dbCourse = await this.context.Course.FirstOrDefaultAsync(s => s.Id == deleteCourseCommand.Id); dbCourse.ShouldBeNull(); }
public DeleteCourseCommandHandlerTest() { CourseRepository = new Mock <ICourseRepository>(); DeleteCourseCommandHandler = new DeleteCourseCommandHandler(CourseRepository.Object); }