public void DadoUmComandoValido() { var validCommand = new UpdateRegionCommand(1, "MG", "Minas Gerais"); validCommand.Validate(); Assert.True(validCommand.Valid); }
public void DadoUmComandoInvalido() { var invalidCommand = new UpdateRegionCommand(0, "", ""); invalidCommand.Validate(); Assert.False(invalidCommand.Valid); }
public async Task <BaseApiResponse> SetRegion(SetRegionRequest request) { request.CheckNotNull(nameof(request)); TryInitUserModel(); //更新 var command = new UpdateRegionCommand(request.Region) { AggregateRootId = _user.Id }; var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } //更新缓存 _user.Region = request.Region; _apiSession.UpdateUserInfo(_user.Id.ToString(), _user); return(new BaseApiResponse()); }
public void DadoUmComandoInvalidoPeloNome() { var invalidCommand = new UpdateRegionCommand(1, "MG", ""); invalidCommand.Validate(); Assert.Equal("O nome da região precisa ter pelo menos 3 letras.", invalidCommand.Notifications.First().Message); }
public void DadoUmComandoInvalidoPelaSigla() { var invalidCommand = new UpdateRegionCommand(1, "", "Minas Gerais"); invalidCommand.Validate(); Assert.Equal("A sigla tem que ter pelo menos 1 letra.", invalidCommand.Notifications.First().Message); }
public void DadoUmComandoInvalidoPelaId() { var invalidCommand = new UpdateRegionCommand(0, "MG", "Minas Gerais"); invalidCommand.Validate(); Assert.Equal("Identidade tem que ser maior que 0.", invalidCommand.Notifications.First().Message); }
public async Task <APIResult> Update([FromBody] UpdateRegionCommand command) { var rs = await mediator.Send(command); return(new APIResult() { Result = rs }); }
public async Task <BaseApiResponse> SetRegion([FromBody] SetRegionRequest request) { request.CheckNotNull(nameof(request)); var currentAccount = _contextService.GetCurrentAccount(HttpContext); //更新 var command = new UpdateRegionCommand(request.Region) { AggregateRootId = currentAccount.UserId.ToGuid() }; var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } return(new BaseApiResponse()); }
public HandlerResult <UpdateRegionCommand> Put( [FromServices] IHandler <UpdateRegionCommand> handler, [FromBody] UpdateRegionCommand command) { return(handler.Handle(command)); }
public void Handle(ICommandContext context, UpdateRegionCommand command) { context.Get <User>(command.AggregateRootId).UpdateRegion(command.Region); }