public void Check_UpdateActivityCommandHandler_Succeed() { var description = "Given Description"; var id = 1u; var projectId = 1u; var dispatcher = new DomainEventDispatcher(); var taskOptionsBuilder = new DbContextOptionsBuilder <ActivityDbContext>(); taskOptionsBuilder.UseSqlite("Data Source=todoagility_cqrs_test.db;"); var taskDbContext = new ActivityDbContext(taskOptionsBuilder.Options); var repTask = new ActivityRepository(taskDbContext); using var taskDbSession = new DbSession <IActivityRepository>(taskDbContext, repTask); var project = Project.From(EntityId.From(projectId), Description.From(description)); var originalTask = Activity.From(Description.From(description), EntityId.From(id), EntityId.From(projectId), ActivityStatus.From(1)); taskDbSession.Repository.AddProject(project); taskDbSession.Repository.Add(originalTask); taskDbSession.SaveChanges(); var descriptionNew = "Given Description Changed"; var command = new UpdateActivityCommand(id, descriptionNew); var handler = new UpdateActivityCommandHandler(taskDbSession, dispatcher); handler.Execute(command); var task = taskDbSession.Repository.Get(EntityId.From(id)); Assert.NotEqual(task, originalTask); }
public async Task <IActionResult> Put(Guid id, [FromBody] UpdateActivityCommand command) { command.Id = id; await _dispatcher.DispatchAsync(command); return(Ok()); }
public async Task <IActionResult> Edit(UpdateActivityCommand command) { if (await Mediator.Send(command) != null) { return(RedirectToAction("Details", "Activities", new { id = command.Id })); } return(View(command)); }
public async void ReturnNull_IfExceptionIsThrown() { Exception a = null; _unitOfWork.Setup(mock => mock.ActivityRepository.Update(It.IsAny <Activity>())) .Throws(a); var command = new UpdateActivityCommand(new ActivityModel()); var handler = new UpdateActivityHandler(_unitOfWork.Object); var returnValue = await handler.Handle(command, new CancellationToken()); Assert.Null(returnValue); }
public async Task <IActionResult> UpdateActivity([FromBody] ActivityModel model) { if (model.ActivityName == null || model.ActivityId <= 0) { return(new BadRequestObjectResult("somerhing went wrong")); } UpdateActivityCommand command = new UpdateActivityCommand(model); var result = await this._mediator.Send(command); if (result == null) { return(new BadRequestObjectResult("Could not update activity")); } if (result.GetType() == typeof(bool) && (bool)result == false) { return(new BadRequestObjectResult("Something went wrong")); } return(new OkObjectResult(result)); }
public async void ReturnActivity_IfSucceesfullyUpdated() { Activity a = new Activity() { ActivityName = "123", Id = 1 }; _unitOfWork.Setup(mock => mock.ActivityRepository.Update(It.IsAny <Activity>())) .Returns(a); var tempActivityModel = new ActivityModel() { ActivityName = "test", ActivityId = 1 }; var command = new UpdateActivityCommand(tempActivityModel); var handler = new UpdateActivityHandler(_unitOfWork.Object); var returnValue = await handler.Handle(command, new CancellationToken()); Assert.NotNull(returnValue); }
public async Task <Response <Activity> > Put([FromRoute] Guid id, UpdateActivityCommand cmd) { cmd.Id = id; return(await _mediator.Send(cmd)); }
public async Task <ActionResult <Unit> > Update(Guid id, UpdateActivityCommand command) { command.Id = id; return(await Mediator.Send(command)); }
public WebApiResult <ActivityViewModel> Put(int id, [FromBody] UpdateActivityCommand command) { var result = this._repository.ExecuteCommand(command); return(AutoMapper.Mapper.Map <CommandResult <Activity>, WebApiResult <ActivityViewModel> >(result)); }
public SActivity MapUpdateRequesttoActivity(UpdateActivityCommand request) { return(_mapper.Map <UpdateActivityCommand, SActivity>(request)); }
public async Task <ActionResult> UpdateActivityAsync([FromBody] UpdateActivityCommand command) { return(Ok(await CommandAsync(command))); }