public async void handle_Exception_test() { Project returnn = new Project(); OrganisationProject op = new OrganisationProject(); ProjectCategory pc = new ProjectCategory(); ProjectResearcher pr = new ProjectResearcher(); this._unitOfUnitMock.Setup(mock => mock.ProjectRepository.Update(It.IsAny <Project>())).Returns(returnn); this._unitOfUnitMock.Setup(mock => mock.RelationsRepository.DeleteProjectOrganisation(It.IsAny <int>())) .Returns(true); this._unitOfUnitMock.Setup(mock => mock.RelationsRepository.CreateOrganisationProject(It.IsAny <OrganisationProject>())).Returns(op); this._unitOfUnitMock.Setup(mock => mock.RelationsRepository.DeleteCategoriesProject(It.IsAny <int>())) .Returns(true); this._unitOfUnitMock .Setup(mock => mock.RelationsRepository.CreateProjectCategory(It.IsAny <ProjectCategory>())).Returns(pc); this._unitOfUnitMock .Setup(mock => mock.RelationsRepository.DeleteProjectResearcherWithProjectId(It.IsAny <int>())) .Returns(true); this._unitOfUnitMock .Setup(mock => mock.RelationsRepository.CreateProjectResearcher(It.IsAny <ProjectResearcher>())) .Throws(new Exception()); UpdateProjectCommand command = new UpdateProjectCommand(new CreateProjectModel() { ProjectName = "test", Categories = new List <Category>() { new Category() { CategoryId = 1, CategoryName = "test", Created = DateTime.Now, Id = 1 } }, ResearcherCategories = new List <ResearcherCategory>() { new ResearcherCategory() { Researcher = new Researcher() { Id = 1 }, Category = new Category() { Id = 1 } } }, Organisations = new List <Organisation>() { new Organisation() { Id = 1, } } }); UpdateProjectHandler handler = new UpdateProjectHandler(this._unitOfUnitMock.Object); var result = await handler.Handle(command, new CancellationTokenSource().Token); Assert.Null(result); }
public async Task ShouldUpdateProjectSuccessfully() { var userId = RunAsDefaultUser(); var projectId = await SendAsync(new CreateProjectCommand { Key = "TKWZ", Name = "Test Project", OwnerId = userId }); var command = new UpdateProjectCommand { Id = projectId, IsDeleted = true, Name = "Deleted Project", OwnerId = userId }; await SendAsync(command); var item = await FindAsync <Project>(projectId); item.Should().NotBeNull(); item.IsDeleted.Should().Be(command.IsDeleted); item.Name.Should().Be(command.Name); item.LastModifiedBy.Should().Be(userId); item.LastModified.Should().BeCloseTo(DateTime.Now, 10000); }
public void ShouldRequireMinimumFields() { var command = new UpdateProjectCommand(); FluentActions.Invoking(() => SendAsync(command)).Should().Throw <ValidationException>(); }
public async Task <Result <CommandResult> > Handle(UpdateProjectCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { await PublishValidationErrorsAsync(request); return(Result.Failure <CommandResult>(ApplicationMessages.Update_Failed)); } var project = await _projectRepository.GetByIdAsync(request.Id); var exist = await _projectRepository.ExistByNameAsync(project.Id, request.Name); if (exist) { await _mediator.Publish(new DomainNotification("", ApplicationMessages.Name_Already_Exist)); return(Result.Failure <CommandResult>(ApplicationMessages.Update_Failed)); } project.SetName(request.Name); project.SetDescription(request.Description); await _projectRepository.UpdateAsync(project); return(Result.Success(new CommandResult(project.Id, ApplicationMessages.Update_Success))); }
public async Task <CommandResult> Handle(UpdateProjectCommand command) { try { var project = await _eventStore.LoadAggregateAsync <Project>(command.ProjectId); if (project.Description != command.Description) { project.ChangeDescription(command.Description); } if (project.ProjectType != command.ProjectType) { project.ChangeProjectType(command.ProjectType); } if (project.IsValid) { await _eventStore.SaveAggregateAsync(project); return(CommandResult.Success(project.Id)); } return(CommandResult.Fail(project.ViolatedRules)); } catch (Exception ex) { return(CommandResult.Fail(ex.Message)); } }
public async Task <IActionResult> Update(int id, [FromBody] UpdateProjectCommand command) { command.Id = id; await _mediator.Send(command); return(Ok()); }
public void Update(ProjectModel project) { // you can use automapper to map source and destination var UpdateCommand = new UpdateProjectCommand(project.Id, project.Name, project.Description, project.IsPrivate); _bus.SendCommand(UpdateCommand); }
public async Task ShouldUpdateProject() { var userId = await RunAsDefaultUserAsync(); var owner = new Participant(userId, "firstName", "lastName"); var entity = new Project(owner, "Project Name", "Key"); await AddAsync(entity); var command = new UpdateProjectCommand { Id = entity.Id, Name = "Updated Project Name" }; await SendAsync(command); var project = await FindAsync <Project>(entity.Id); project.Name.Should().Be(command.Name); project.LastModifiedBy.Should().NotBeNull(); project.LastModifiedBy.Should().Be(userId); project.LastModified.Should().NotBeNull(); project.LastModified.Should().BeCloseTo(DateTime.Now, 1000); }
public async Task <CommandResponse> ExecuteAsync(UpdateProjectCommand command) { // map project Project entityToUpdate = mapper.Map <Project>(command.UpdateProjectDTO); // update bool isUpdated = true; string message = "Record updated"; try { unitOfWork.Update(entityToUpdate, excludeProperties: $"{nameof(Project.CreatedAt)}"); await unitOfWork.SaveAsync(); } catch (System.Exception e) { isUpdated = false; message = Common.Algorithms.GetFullText(e); } // result return(new CommandResponse { IsSucessed = isUpdated, Message = message }); }
public async Task UpdateProjectSuccessful() { var newName = "new name"; var newDescription = "new description"; var newDate = DateTime.UtcNow.AddDays(20); var request = new UpdateProjectCommand() { Id = Utilities.Project1.Id, Name = newName, Description = newDescription, DueDate = newDate, }; var response = await Client.PutAsync("/api/MyProjects", Utilities.GetRequestContent(request)); response.EnsureSuccessStatusCode(); var getResponse = await Client.GetAsync($"/api/MyProjects/{Utilities.Project1.Id}"); var projectAfterUpdate = await Utilities.GetResponseContent <DetailedProjectDto>(getResponse); projectAfterUpdate.Name.Should().Be(newName); projectAfterUpdate.Description.Should().Be(newDescription); projectAfterUpdate.DueDate.Should().Be(newDate); }
public async Task <IActionResult> Put(int id, UpdateProjectCommand command) { if (id != command.Id) { return(BadRequest()); } return(Ok(await Mediator.Send(command))); }
public static Project.ProjectDetail ToProjectDetail(this UpdateProjectCommand command) => new Project.ProjectDetail( ProjectName.From(command.Name), Money.From(command.Budget), Email.From(command.Owner), ProjectStatus.From(command.Status), ServiceOrderNumber.From(command.OrderNumber) );
public async Task <IActionResult> Update(UpdateProjectCommand command) { //TODO: validate command var result = await _mediator.Send(command); return(result != null ? (IActionResult)Ok(result) : BadRequest(new ValidationResponse { Code = 1, Message = "Validation message" })); }
public async Task <IActionResult> UpdateProject([FromBody] UpdateProjectCommand command) { if (command is null) { return(BadRequest()); } return(Json(await _mediator.Send(command))); }
public void Update(UpdateProjectCommand model) { MySqlCommand command = new MySqlCommand(GetUpdateCommandText(), _connection); command.Parameters.Add("@name", MySqlDbType.VarChar).Value = model.Name; command.Parameters.Add("@resume", MySqlDbType.VarChar).Value = model.Resume; command.Parameters.Add("@projectId", MySqlDbType.VarChar).Value = model.ProjectId; command.ExecuteNonQuery(); }
public ProjectEntity Update(UpdateProjectCommand source, ProjectEntity destination) { destination.Name = source.Name; destination.Description = source.Description; destination.FontName = source.FontName; destination.FontSize = source.FontSize; destination.RowHeight = source.RowHeight; return(destination); }
public async Task <IActionResult> UpdateProject( [FromRoute] string id, [FromBody] UpdateProjectCommand command, [FromServices] IMediator mediator) { command.AddProjectId(id); var result = await mediator.Send(command); return(StatusCode(200, result)); }
public void ShouldRequireValidProjectId() { var command = new UpdateProjectCommand { Id = 99, Name = "New Name" }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task <IActionResult> EditRedirect(UpdateProjectCommand command) { if (await Mediator.Send(command) != null) { return(RedirectToAction("Details", new { id = command.Id })); } return(View("Edit", command)); }
public async Task <ActionResult> EditAsync(Guid Id, UpdateProjectCommand command) { if (Id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public async Task <ActionResult> Update(int id, UpdateProjectCommand command) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public ActionResult Edit(int id, UpdateProjectCommand command) { command.ProjectId = id; command.UpdatedByUserId = User.Identity.GetUserId(); if (!ModelState.IsValid) { return(View(command)); } PipelineService.HandleCommand(command); return(RedirectToAction("Index")); }
public async Task <IActionResult> Put(int id, [FromBody] UpdateProjectCommand command) { if (command.Description.Length > 200) { return(BadRequest()); } //_projectService.Update(inputModel); await _mediator.Send(command); return(Ok()); }
public async Task <IActionResult> Put(int id, [FromBody] UpdateProjectCommand command) { //if (!ModelState.IsValid) //{ // var messages = ModelState.SelectMany(ms => ms.Value.Errors).Select(e => e.ErrorMessage).ToList(); // return BadRequest(messages); //} //_projectService.Update(id, inputModel); await _mediator.Send(command); return(NoContent()); }
public Option <SuccessResult, ErrorResult> Update(UpdateProjectCommand command) { return(_updateProjectCommandValidator .Validate(command) .OnSuccess(errorBuilder => { var option = _projectRepository.GetById(command); option.MatchSome(x => { _projectRepository.Update(_mapper.Update(command, x)); }); option.MatchNone(errorBuilder.AddRecordNotFound); })); }
public Project Update(UpdateProjectCommand command) { var project = _repository.GetById(command.ProjectId); project.UpdateProject(project); _repository.Update(project); if (Commit()) { return(project); } return(null); }
public async void handle_ProjectResutlNull_test() { Project returnn = null; this._unitOfUnitMock.Setup(mock => mock.ProjectRepository.Update(It.IsAny <Project>())).Returns(returnn); UpdateProjectCommand command = new UpdateProjectCommand(new CreateProjectModel() { ProjectName = "test" }); UpdateProjectHandler handler = new UpdateProjectHandler(this._unitOfUnitMock.Object); var result = await handler.Handle(command, new CancellationTokenSource().Token); Assert.Null(result); }
public IActionResult Patch(Guid id, [FromBody] ProjectUpdateModel model) { var query = new GetProjectQuery(id); var project = _bus.PublishQuery(query); // validation if (project == null) { return(NotFound()); } var command = new UpdateProjectCommand(id, model.Title, model.Description); _bus.PublishCommand(command); return(Ok()); }
public async Task <ActionResult> UpdateProject([FromBody] UpdateProjectCommand updateProjectCommand) { try { await Mediator.Send(updateProjectCommand); return(Ok()); } catch (UnauthorizedException e) { return(StatusCode(401, e.Message)); } catch (Exception e) { return(BadRequest(e.Message)); } }
/// <summary> /// Update project handler. /// </summary> /// <param name="command">Command.</param> /// <param name="uowFactory">Application unit of work factory.</param> public void HandleUpdateProject(UpdateProjectCommand command, IAppUnitOfWorkFactory uowFactory) { using (var uow = uowFactory.Create()) { var project = uow.ProjectRepository.Get(command.ProjectId); if (project.User.Id != command.UpdatedByUserId) { throw new ForbiddenException("Only user who created project can update it."); } project.Name = command.Name; project.Color = command.Color; project.UpdatedAt = DateTime.Now; uow.SaveChanges(); } }