Пример #1
0
        public void Handle(UserRegistrationStarted e)
        {
            // Registration succeeds only if no other user has the same login name.
            var status = _querySearch
                         .UserExists(u => u.LoginName == e.Name && u.UserIdentifier != e.AggregateIdentifier)
                                ? "Failed" : "Succeeded";

            _commander.Send(new CompleteUserRegistration(e.AggregateIdentifier, status));
        }
Пример #2
0
        private void describe_HandleAsync_UserRegistrationProcessCreated()
        {
            var userRegistrationProcessCreated = new UserRegistrationStarted(
                _userId,
                UserRegistrationFormMother.JohnDow());

            context["when user registration process is in Created state"] = () =>
            {
                before = () =>
                {
                    var process = UserRegistrationProcessMother.InCreatedState(_userId);
                    _userRegistrationProcessRepository.SaveAsync(process).Wait();
                };

                context["and user-by-email index accepts email"] = () =>
                {
                    before = () =>
                    {
                        _userByEmailIndex.SetResult(IndexResult.EmailAccepted);
                        _sut.HandleAsync(userRegistrationProcessCreated).Wait();
                    };

                    it["saves EmailAccepted event"] =
                        () => _eventStore.LastSavedEvents.Single().should_cast_to <EmailAccepted>();

                    it["is idempotent"] = () =>
                    {
                        _sut.HandleAsync(userRegistrationProcessCreated).Wait();
                        _eventStore.LastSavedEvents.should_be_empty();
                    };
                };

                context["and user-by-email index rejects email"] = () =>
                {
                    before = () =>
                    {
                        _userByEmailIndex.SetResult(IndexResult.EmailRejected);
                        _sut.HandleAsync(userRegistrationProcessCreated)
                        .Wait();
                    };

                    it["saves UserRegistrationFailed event"] = () =>
                                                               _eventStore.LastSavedEvents.Single().should_cast_to <UserRegistrationFailed>();

                    it["is idempotent"] = () =>
                    {
                        _sut.HandleAsync(userRegistrationProcessCreated).Wait();
                        _eventStore.LastSavedEvents.should_be_empty();
                    };
                };
            };
        }
        public async Task HandleAsync(UserRegistrationStarted @event)
        {
            var indexResult = await _userByEmailIndex.AddAsync(@event.Form.Email, @event.UserId);

            var process = await GetProcessOrExceptionAsync(@event.UserId);

            switch (indexResult)
            {
            case IndexResult.EmailAccepted:
                process.HandleEmailAccepted();
                break;

            case IndexResult.EmailRejected:
                process.HandleEmailRejected();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            await _userRegistrationProcessRepository.SaveAsync(process);
        }
Пример #4
0
 public void Handle(UserRegistrationStarted c)
 {
     _store.InsertUser(c.AggregateIdentifier, c.Name, c.Password, "Started");
 }