public async Task ShouldNot_Delete_Incomplete_Task() { var items = new Dictionary <string, TaskToDo>() { { "task1", new TaskToDo() { Name = "task1", StatusCode = "NotStarted" } } }; var collection = new InMemoryItemsCollection <TaskToDo>(items); var handler = new DefaultCommandHandlers(collection); var deleteTaskCmd = new DeleteTaskCommand() { Id = "task1" }; var ex = await Assert.ThrowsAsync <AppException>(async() => await handler.Handle(deleteTaskCmd, CancellationToken.None)); Assert.Equal("Only 'Completed' task can be deleted", ex.Message); }
public async System.Threading.Tasks.Task HandleDeleteTask(DeleteTaskCommand deleteTaskCommand) { await _taskRepository.Remove(deleteTaskCommand.Id); // You may raise an event in case you need to propagate this change to other microservices await _mediator.PublishAsync(new TaskDeletedEvent(deleteTaskCommand.Id)); }
public async Task <CommandResponse> ExecuteAsync(DeleteTaskCommand command) { // delete bool deletingStatus = false; string message = "Task deleted"; try { deletingStatus = await taskRepository.DeleteAsync(command.TaskId); await unitOfWork.SaveAsync(); if (!deletingStatus) { message = "Could not delete task"; } } catch (System.Exception e) { deletingStatus = false; message = Common.Algorithms.GetFullText(e); } // result return(new CommandResponse { IsSucessed = deletingStatus, Message = message }); }
public async Task <IActionResult> DeleteTask(Guid id) { var query = new DeleteTaskCommand(id); var result = await _mediator.Send(query); return(result != null ? (IActionResult)Ok(result) : NotFound()); }
private void DeleteTaskCommand_Executed(object sender, RoutedEventArgs e) { DeleteTaskCommand DeleteClick = new DeleteTaskCommand(this); DeleteClick.Execute(); this.ViewableTasks.View.Refresh(); }
public async Task <IActionResult> DeleteAsync([FromBody] DeleteTaskCommand deleteCommand) { if (deleteCommand.Id == Guid.Empty) { return(BadRequest("Id can't be empty.")); } if (deleteCommand.ProjectId == Guid.Empty) { return(BadRequest("Project Id can't be empty.")); } try { await _mediator.Send(deleteCommand); return(Ok()); } catch (DataNotFoundException ex) { return(NotFound(ex.Message)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void Handle(DeleteTaskCommand message) { var task = Repository.GetById <Task>(message.TaskId); task.MarkAsDeleted(); Repository.Save(task); }
public static void TaskMapper(this InputModelToDomainMappingProfile profile) { profile.CreateMap <CreateTaskInputModel, CreateTaskCommand>() .ForMember(x => x.Id, opt => opt.Ignore()) .ForMember(x => x.Status, opt => opt.Ignore()) .ForMember(x => x.Name, opt => opt.Ignore()) .ForMember(x => x.ValidationResult, opt => opt.Ignore()) .ConstructUsing(x => CreateTaskCommand.Create( x.Title, x.Description)); profile.CreateMap <UpdateTaskInputModel, UpdateTaskCommand>() .ForMember(x => x.Name, opt => opt.Ignore()) .ForMember(x => x.ValidationResult, opt => opt.Ignore()) .ConstructUsing(x => UpdateTaskCommand.Create( x.Id, x.Title, x.Description, x.Status)); profile.CreateMap <DeleteTaskInputModel, DeleteTaskCommand>() .ForMember(x => x.Title, opt => opt.Ignore()) .ForMember(x => x.Description, opt => opt.Ignore()) .ForMember(x => x.Status, opt => opt.Ignore()) .ForMember(x => x.Name, opt => opt.Ignore()) .ForMember(x => x.ValidationResult, opt => opt.Ignore()) .ConstructUsing(x => DeleteTaskCommand.Create(x.id)); }
public async Task Execute_ReturnsCompletedTaskOnSuccess() { var repo = new Mock <IListRepository>(); var listId = Guid.NewGuid().ToString(); var taskId = Guid.NewGuid().ToString(); var list = new List { Id = listId, Tasks = new List <Domain.Task> { new Domain.Task { Id = taskId } } }; var command = new DeleteTaskCommand { ListId = listId, TaskId = taskId }; var handler = new DeleteTaskCommandHandler(repo.Object); repo.Setup(r => r.GetById(It.IsAny <string>())).ReturnsAsync(list); var result = handler.Execute(command); await result; Assert.AreEqual(true, result.IsCompleted); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "list/{listid}/task/{taskid}")] HttpRequest req, string listid, string taskid) { try { var command = new DeleteTaskCommand { ListId = listid, TaskId = taskid }; var handler = Container.GetInstance <ICommandHander <DeleteTaskCommand> >(); await handler.Execute(command); return(new NoContentResult()); } catch (ResourceNotFoundException ex) { Container.GetInstance <TelemetryClient>().TrackException(ex); return(new NotFoundResult()); } catch (Exception ex) { Container.GetInstance <TelemetryClient>().TrackException(ex); return(new InternalServerErrorResult()); } }
public Task Delete(DeleteTaskCommand command) { var task = _repository.GetById(command.Id); _repository.Delete(task.Id); return(task); }
public void Delete_should_run_delete_task_command() { var command = new DeleteTaskCommand(); taskController.Delete(command); commandBus.Verify(cb => cb.Run(command)); }
public void Should_get_task_by_id() { var command = new DeleteTaskCommand(); handler.Handle(command); repository.Verify(r => r.GetById <Task>(command.Id)); }
public async Task <Result <DeleteTaskResponse> > Put( [FromBody] DeleteTaskCommand command, [FromRoute] string taskId, CancellationToken cancellationToken = default ) { command.Id = taskId; return(await _mediator.Send(command, cancellationToken)); }
public void ShouldRequireValidTaskId() { var command = new DeleteTaskCommand { Id = 99 }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
private void CutCommand_Executed(object sender, RoutedEventArgs e) { temporaryClipboard = (Task)TaskListBox.SelectedValue; DeleteTaskCommand DeleteClick = new DeleteTaskCommand(this); DeleteClick.Execute(); this.ViewableTasks.View.Refresh(); }
public object Handler(DeleteTaskCommand command) { var task = _repository.Get(command.Id); task.SetAsDeleted(); _uow.Commit(); return(new { command.Id }); }
public async Task DeleteTaskCommandHandler_ReturnsZeroForBlankLine() { var command = new DeleteTaskCommand { ItemNumber = 4 }; var result = await _handler.Handle(command, new CancellationToken()); result.Should().Be(0); }
public async Task DeleteTaskCommandHandler_ReturnsLineNumberOfDeletedTask() { var command = new DeleteTaskCommand { ItemNumber = 3 }; var result = await _handler.Handle(command, new CancellationToken()); result.Should().Be(3); }
public void TestInitialize() { var commandFactory = AssemblyConfiguration.Kernel.Get <CommandFactory>(); var queryFactory = AssemblyConfiguration.Kernel.Get <QueryFactory>(); _mapper = AssemblyConfiguration.Kernel.Get <IMapper>(); _createTaskCommand = commandFactory.GetInstance <CreateTaskCommand>(); _getTaskQuery = queryFactory.GetInstance <GetTasksQuery>(); _sut = commandFactory.GetInstance <DeleteTaskCommand>(); }
private void NotifyCanExecuteCommands() { if (EditTaskCommand == null || DeleteTaskCommand == null) { return; } EditTaskCommand.NotifyCanExecuteChanged(); DeleteTaskCommand.NotifyCanExecuteChanged(); }
public async Task <IActionResult> DeleteTask(DeleteTaskCommand command) { if (command is null) { return(BadRequest()); } await _mediator.Send(command); return(NoContent()); }
public async Task DeleteTaskCommandHandler_RemovesTaskAndBlankLinesFromFile() { var command = new DeleteTaskCommand { ItemNumber = 3 }; _ = await _handler.Handle(command, new CancellationToken()); _taskFile.TaskLines.Should().HaveCount(6); _taskFile.TaskLines[2].Should().Be("(D) This is lower"); }
public async Task <IActionResult> DeleteTaskAsync(int id, [FromBody] DeleteTaskCommand command) { command.Id = id; var response = await CommandAsync(command); if (response.Errors.Any()) { return(BadRequest(response.Errors)); } return(Ok(response.Result)); }
public ResultDto DeleteTask(long jobId, long id) { return(Result(() => { var command = new DeleteTaskCommand { JobId = jobId, TaskId = id, }; CommandDispatcher.Send(command); })); }
public async Task <Result <DeleteTaskResponse> > Handle(DeleteTaskCommand request, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var entity = await _repository.GetByIdAsync <Entities.Task.Task, Guid>(Guid.Parse(request.Id)); await _repository.DeleteAsync(entity); return(Result.Ok(new DeleteTaskResponse { Id = entity.Id.ToString() })); }
public static int DeleteTask(int id) { DeleteTaskCommand command = new DeleteTaskCommand(); command.EMail = EMAIL; command.Hash = HASH; command.ID = id; ResultWithNoData result = JsonConvert.DeserializeObject <ResultWithNoData>(TCPManager.SendRequest(JsonConvert.SerializeObject(command))); return(result.statusCode); }
public ActionResult DeleteTaskWorkTime(Guid TaskId) { if (ModelState.IsValid) { var query = new DeleteTaskCommand { TaskId = TaskId }; var task = mediator.Send(query); return(Json("successful")); } return(RedirectToAction("TimesheetManagement")); }
private void _model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == nameof(Model.Start) || e.PropertyName == nameof(Model.End)) { if (Model.Start > Model.End) { Application.Current.MainPage.DisplayAlert( "Error", "End date must be equal to or greater than Start date", "cancel"); } } SaveTaskCommand.RaiseCanExecuteChanged(); DeleteTaskCommand.RaiseCanExecuteChanged(); }
public void ClientDeleteTaskRequest(int RandomID) { Console.WriteLine("Received request to: Delete Task" + RandomID); User mUser = FindUser(Context.ConnectionId); if (mUser.Tasks.Count == 0) { EmptyListBroadcast(); return; } DeleteTaskCommand mDeleteTask = new DeleteTaskCommand(mUser, RandomID); mDeleteTask.Execute(); Clients.Clients(mUser.ConnectionIDs).UpdateTask(RandomID, "", 5); }
public ActionResult Delete(DeleteTaskCommand command) { return new DeleteResponder(this) .RespondWith(mediator, command); }
public void Delete_Delete_should_send_delete_task_command() { var command = new DeleteTaskCommand(1); tasksController.Delete(command); mockMediator.Verify(x => x.Send(command), Times.Once()); }