private void describe_GetAsync()
        {
            var userRegistrationForm = UserRegistrationFormMother.JohnDow();

            context["when user is present in repository"] = () =>
            {
                var presentUser = new User(Guid.NewGuid(), userRegistrationForm);

                before = () =>
                {
                    _sut.SaveAsync(presentUser).Wait();
                    _result = _sut.GetAsync(presentUser.Id).Result;
                };

                it["returns not none"]             = () => _result.HasValue.should_be_true();
                it["returns user with correct Id"] = () =>
                                                     _result.ValueOrFailure().Id.should_be(presentUser.Id);
            };

            context["when user is not present in repository"] = () =>
            {
                var result = new Option <User>();

                before             = () => result = _sut.GetAsync(Guid.NewGuid()).Result;
                it["returns none"] = () => result.HasValue.should_be_false();
            };
        }
        private void describe_StartRegistrationAsync()
        {
            before = () => _sut.StartRegistrationAsync(UserRegistrationFormMother.JohnDow()).Wait();

            it["saves UserRegistrationStarted event"] = () =>
                                                        _eventStore.LastSavedEvents.Single().should_cast_to <UserRegistrationStarted>();
        }
Esempio n. 3
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();
                    };
                };
            };
        }
Esempio n. 4
0
        private void describe_HandleAsync_UserCreated()
        {
            var userCreated = new UserCreated(_userId, UserRegistrationFormMother.JohnDow());

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

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

                it["is idempotent"] = () =>
                {
                    _sut.HandleAsync(userCreated).Wait();
                    _eventStore.LastSavedEvents.should_be_empty();
                };
            };
        }
        private void describe_application()
        {
            context["when two user registration processes have been started for users with same emails"] = () =>
            {
                var userId1 = new Guid();
                var userId2 = new Guid();

                before = () =>
                {
                    var userRegistrationForm = UserRegistrationFormMother.JohnDow();

                    userId1 = _commandService
                              .StartRegistrationAsync(userRegistrationForm)
                              .Result;

                    userId2 = _commandService
                              .StartRegistrationAsync(userRegistrationForm)
                              .Result;
                };

                it["eventually returns succeeded result for one user and failed result for another user"] = () =>
                {
                    Eventually.IsTrue(() =>
                    {
                        var queryResults = new[]
                        {
                            _queryService.GetAsync(userId1).Result,
                            _queryService.GetAsync(userId2).Result
                        };

                        return
                        (queryResults.Contains(Option.Some(UserRegstrationProcessQueryResult.Succeeded)) &&
                         queryResults.Contains(Option.Some(UserRegstrationProcessQueryResult.Failed)));
                    });
                };
            };
        }