예제 #1
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();
                    };
                };
            };
        }
예제 #2
0
        private void describe_HandleAsync_EmailAccepted()
        {
            var emailAccepted = new EmailAccepted(_userId);

            context["when user registration process is in CreatingUser state"] = () =>
            {
                before = () =>
                {
                    var process = UserRegistrationProcessMother.InCreatingUserState(_userId);
                    _userRegistrationProcessRepository.SaveAsync(process).Wait();
                    _sut.HandleAsync(emailAccepted).Wait();
                };

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

                it["is idempotent"] = () =>
                {
                    _sut.HandleAsync(emailAccepted).Wait();
                    _eventStore.LastSavedEvents.should_be_empty();
                };
            };
        }
예제 #3
0
        private void describe_GetAsync()
        {
            context["when user registration process is present in repository"] = () =>
            {
                var presentProcess = UserRegistrationProcessMother.InCreatedState(Guid.NewGuid());

                before = () =>
                {
                    _sut.SaveAsync(presentProcess).Wait();
                    _result = _sut.GetAsync(presentProcess.UserId).Result;
                };

                it["returns not none"] = () => _result.HasValue.should_be_true();
                it["returns user registration process with correct UserId"] =
                    () => { _result.ValueOrFailure().UserId.should_be(presentProcess.UserId); };
            };

            context["when user registration process is not present in repository"] = () =>
            {
                before             = () => _result = _sut.GetAsync(Guid.NewGuid()).Result;
                it["returns none"] = () => _result.HasValue.should_be_false();
            };
        }