public async Task <IActionResult> DeleteProduct(int id) { var command = new DeleteCourseCommand(id); var removedId = await _mediator.Send(command); return(Ok(removedId)); }
public async Task <IActionResult> Delete(int id, [FromBody] StudentDto studentDto) { var deleteCourseCommand = new DeleteCourseCommand(studentDto); var response = await _mediator.Send(deleteCourseCommand); return(Ok(response)); }
public DeleteCourseService(DeleteCourseCommand courseCommand, ICourseRepository courseRepository) : base(courseCommand) { _courseRepository = courseRepository; _courseCommand = courseCommand; Run(); }
public Command DeleteCourse(int id) { var courseCommand = new DeleteCourseCommand(id); new DeleteCourseService(courseCommand, _courseRepository); return(courseCommand); }
public async Task <IActionResult> Delete([FromRoute] int courseId) { var command = new DeleteCourseCommand { Id = courseId }; return(Ok(await Mediator.Send(command))); }
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 void ShouldReturnValidWhenDeleteCommandValid() { var command = new DeleteCourseCommand(); command.Id = Guid.NewGuid(); var handler = new CourseHandler(new CourseRepositoryMock()); var result = handler.Handle(command); Assert.AreEqual(true, result.Status); }
public Task <bool> Handle(DeleteCourseCommand request, CancellationToken cancellationToken) { var course = new Course { Id = request.Id }; _repository.Delete(course); return(Task.FromResult(true)); }
public void Delete(DeleteCourseCommand command) { _db.Connection().Execute( "spDeleteCourse", new { id = command.Id }, commandType: CommandType.StoredProcedure ); }
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 async Task Handle_WhenCourseDoesNotExists_ReturnResultWithNotFound() { var deleteCourseCommand = new DeleteCourseCommand { Id = Guid.NewGuid() }; CourseRepository.Setup(ur => ur.GetByCourseIdAsync(deleteCourseCommand.Id)).Returns(Task.FromResult <Course>(null)); var result = await DeleteCourseCommandHandler.Handle(deleteCourseCommand, CancellationToken.None); result.Should().Be(CommandResultStatus.NotFound); }
public async Task HandleAsync(DeleteCourseCommand command) { var course = await _repository.GetByCode(command.Code); if (course == null) { throw new EntityNotFoundException($"Course with code '{command.Code}' Not Found."); } await _repository.Remove(course); await _commandStoreService.PushAsync(command); }
public async Task Handle_WhenCourseExisted_ReturnResultWithDeleted() { var course = new Course(Guid.NewGuid(), "Physics"); CourseRepository.Setup(ur => ur.GetByCourseIdAsync(course.Id)).Returns(Task.FromResult <Course>(course)); var deleteCourseCommand = new DeleteCourseCommand { Id = course.Id }; var result = await DeleteCourseCommandHandler.Handle(deleteCourseCommand, CancellationToken.None); result.Should().Be(CommandResultStatus.Deleted); }
public async Task <ActionResult> Delete(string code) { try { var command = new DeleteCourseCommand { Code = code }; await _commandHandler.HandleAsync(command); return(NoContent()); } catch (EntityNotFoundException ex) { return(NotFound(ex.Message)); } catch (Exception) { return(BadRequest()); } }
public async Task <IActionResult> DeleteCourse(string name, CancellationToken token) { var command = new DeleteCourseCommand(name); try { await _commandBus.DispatchAsync(command, token); } catch (SqlConstraintViolationException e) { return(BadRequest(e.Message)); } return(Ok()); }
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 ICommandResult Handle(DeleteCourseCommand command) { string id = command.Id.ToString(); if (string.IsNullOrEmpty(id)) { AddNotification("Id", "Identificador inválido"); } if (Invalid) { return(new CommandResult(false, "Erro ao deletar curso", Notifications)); } _repository.Delete(command); return(new CommandResult(true, "Curso deletado com sucesso", null)); }
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 async Task DeleteCourseTest_And_Check_Collection_Should_Return_Id() { //Arrange var request = new DeleteCourseCommand(1); var handler = new DeleteCourseHandler(_fakeRepository); var getRequest = new GetCoursesQuery(); var getHandler = new GetCoursesHandler(_mapper, _fakeRepository); //Act var id = await handler.Handle(request, new CancellationToken()); var courses = await getHandler.Handle(getRequest, new CancellationToken()); //Assert Assert.AreEqual(id, 1); Assert.AreEqual(courses.Count(), 1); }
public ICommandResult Handle(DeleteCourseCommand command) { //Fail Fast Validation command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, Messages.Ex_ExceptionGeneric, command.Notifications)); } var course = _repository.GetById(command.Id); if (course == null) { return(new GenericCommandResult(false, Messages.Ex_ItemNotFound.ToFormat(command.Id.ToString() ?? ""), command.Notifications)); } _repository.Delete(course); return(new GenericCommandResult(true, Messages.Act_Deleted, course)); }
protected void mat_ItemCommand(object source, RepeaterCommandEventArgs e) { ImageButton action = (ImageButton)e.CommandSource; string actionString = action.ID; if (action.ID.Equals("delete")) { try { Course course = new Course(); string id = ((Label)mat_data.Items[e.Item.ItemIndex].FindControl("Id")).Text; course.Id = id; DeleteCourseCommand cmd = new DeleteCourseCommand(course); cmd.Execute(); if (course.Code == 200) { ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme()", true); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertmeErr()", true); } } catch (Exception ex) { } } else if (action.ID.Equals("modify")) { try { string id = ((Label)mat_data.Items[e.Item.ItemIndex].FindControl("Id")).Text; Session["Id_mat"] = id; Response.Redirect("/site/admin/adm_course/edit_mat.aspx"); } catch (Exception ex) { } } }
public async Task OnGetAsync(Query query) { Data = await _mediator.Send(query); }
public async Task <IActionResult> Delete(DeleteCourseCommand command) { return(this.Ok(await this.mediator.Send(command))); }
public GenericCommandResult Delete([FromBody] DeleteCourseCommand command, [FromServices] CourseHandler handler) { return((GenericCommandResult)handler.Handle(command)); }
public void ValidCourseId_ShouldNotHaveError() { var command = new DeleteCourseCommand {CourseId = "courseId"}; _sut.ShouldNotHaveValidationErrorFor(x => x.CourseId, command); }
public void EmptyOrNullCourseId_ShouldHaveError(string courseId) { var command = new DeleteCourseCommand {CourseId = courseId}; _sut.ShouldHaveValidationErrorFor(x => x.CourseId, command); }
public void Delete(DeleteCourseCommand command) { }
public ICommandResult Delete(DeleteCourseCommand command) { return(_handler.Handle(command)); }