コード例 #1
0
        public UserCreateOperationTest()
        {
            _fixture = new Fixture();
            _fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
            _fixture.Behaviors.Add(new OmitOnRecursionBehavior());

            _store      = Substitute.For <IUserAggregateStore>();
            _logger     = Substitute.For <ILogger <UserCreateOperation> >();
            _mapper     = Substitute.For <IMapper <Domain.Common.User, User> >();
            _repository = Substitute.For <IUserRepository>();
            _operation  = new UserCreateOperation(_store, _repository, _logger, _mapper);
        }
コード例 #2
0
ファイル: UserController.cs プロジェクト: lillo42/book-store
        public async Task <IActionResult> Create([FromBody] UserResponse user, [FromServices] UserCreateOperation operation)
        {
            var result = await operation.ExecuteAsync(new UserAdd
            {
                FirstName = user.FirstName,
                LastNames = user.LastNames,
                BirthDate = user.BirthDay,
                Email     = user.Email
            });

            if (result is OkResult <UserResponse> ok)
            {
                return(Created("", ok.Value));
            }

            if (result is ErrorResult error && error.ErrorCode.StartsWith("USR"))
            {
                return(UnprocessableEntity(error));
            }

            return(BadRequest(result));
        }