public void UpdateSpecifiedProperties() { // Arrange this._dbFixture.TestInitialize(); const string newName = "John Doe"; // Validate command handler (it must call UpdateSpecifiedProperties() method) var mockedRepository = new Mock <IRepository>(); var cmdHandler = new DataAccess.CommandHandlers.Users.UpdateUserNameCommandHandler(mockedRepository.Object); cmdHandler.Execute(new UpdateUserNameCommand(this._sampleData.Id, newName)); mockedRepository.Verify(r => r.UpdateSpecifiedProperties( It.IsAny <UserDto>(), It.IsAny <Expression <Func <UserDto, object> >[]>()), Times.AtLeastOnce()); // NOTE: handler for this command should update login only (without reading entire entity) var cmd = new UpdateUserNameCommand(this._sampleData.Id, newName); // Act this._unitOfWorkFactory.ExecuteSingleCommand(cmd); User user = this._unitOfWorkFactory .ExecuteSingleQuery <IGetUserByIdQuery, User>(q => q.Execute(cmd.Id, includeLinks: false)); // Assert Assert.NotNull(user); Assert.Equal(this._sampleData.Id, user.Id); Assert.Equal(newName, user.Name); Assert.Equal(this._sampleData.IsDisabled, user.IsDisabled); }
public async Task <IActionResult> SetUserName([FromBody] UpdateUserNameDto dto, Guid id) { var cmd = new UpdateUserNameCommand { UserId = id, UserName = dto.UserName }; var result = await _sagaBus.InvokeAsync <UpdateUserNameCommand, MessageResult>(cmd); if (result.Succeed) { return(Created(Url.Action(), null)); } //if error return(BadRequest(result.Message)); }
public async Task ExecuteAdvancedCommandAsync() { // Arrange this._dbFixture.TestInitialize(); User user = null; const string newName = "John Doe"; // NOTE: handler for this command should update login only (without reading entire entity) var cmd = new UpdateUserNameCommand(this._sampleData.Id, newName); // Act await this._unitOfWorkFactory.ExecuteSingleCommandAsync(cmd); user = this._unitOfWorkFactory .ExecuteSingleQuery <IGetUserByIdQuery, User>(q => q.Execute(cmd.Id, includeLinks: false)); // Assert Assert.NotNull(user); Assert.Equal(this._sampleData.Id, user.Id); Assert.Equal(newName, user.Name); Assert.Equal(this._sampleData.IsDisabled, user.IsDisabled); }
public async Task <BaseResponse> UpdateUserName(UpdateUserNameCommand updateUserNameCommand) { var result = await _mediator.Send(updateUserNameCommand); return(result); }
public Task <Response <User> > UpdateUserName(UpdateUserNameCommand command) { return(_context.UpdateUserName(command)); }
public async Task<IActionResult> SetUserName([FromBody]UpdateUserNameDto dto, Guid id) { var cmd = new UpdateUserNameCommand { UserId = id, UserName = dto.UserName }; var result = await _sagaBus.InvokeAsync<UpdateUserNameCommand,MessageResult> (cmd); if(result.Succeed) { return Created(Url.Action(), null); } //if error return BadRequest(result.Message); }