예제 #1
0
        public void AddUserAuth_adds_auth_data_and_find_by_id_finds_it()
        {
            _userAuthenticationDataRepository.AddUserAuth(authData);

            var found = _userAuthenticationDataRepository.FindUserAuthById(authData.UserId);

            found.Should().NotBeNull();
            found.Should().BeEquivalentTo(authData);
        }
예제 #2
0
        protected override Task <RequestStatus> HandleCommand(SignUpCommand request, CancellationToken cancellationToken)
        {
            var existing = _userAuthenticationDataRepository.FindUserAuth(request.Username);

            if (existing != null)
            {
                throw new UsernameConflictException($"User {request.Username} already exists");
            }

            var user = new User();

            user.Register(request.Username);

            var response = RequestStatus.CreateFromCommandContext(request.CommandContext, Status.COMPLETED);
            var userAuth = new UserAuthenticationData()
            {
                Password = request.Password,
                UserId   = user.UserIdentity.UserId,
                UserName = user.UserIdentity.UserName,
                Email    = request.Email
            };

            _userAuthenticationDataRepository.AddUserAuth(userAuth);
            _userRepository.AddUser(user);
            _eventBusService.Publish(user.PendingEvents, response.CorrelationId, request);
            user.MarkPendingEventsAsHandled();

            return(Task.FromResult(response));
        }