예제 #1
0
        public void DadoUmComandoValido()
        {
            var validCommand = new UpdateRegionCommand(1, "MG", "Minas Gerais");

            validCommand.Validate();
            Assert.True(validCommand.Valid);
        }
예제 #2
0
        public void DadoUmComandoInvalido()
        {
            var invalidCommand = new UpdateRegionCommand(0, "", "");

            invalidCommand.Validate();
            Assert.False(invalidCommand.Valid);
        }
예제 #3
0
        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());
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        public async Task <APIResult> Update([FromBody] UpdateRegionCommand command)
        {
            var rs = await mediator.Send(command);

            return(new APIResult()
            {
                Result = rs
            });
        }
예제 #8
0
        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());
        }
예제 #9
0
 public HandlerResult <UpdateRegionCommand> Put(
     [FromServices] IHandler <UpdateRegionCommand> handler,
     [FromBody] UpdateRegionCommand command)
 {
     return(handler.Handle(command));
 }
예제 #10
0
 public void Handle(ICommandContext context, UpdateRegionCommand command)
 {
     context.Get <User>(command.AggregateRootId).UpdateRegion(command.Region);
 }