public async Task Should_create_an_Account_for_invites_to_new_users()
        {
            var invitation = new Invitation("*****@*****.**", "inviter");
            var request    =
                new AcceptInvitation("arne", "pass", invitation.InvitationKey)
            {
                AcceptedEmail = "*****@*****.**"
            };

            invitation.Add(1, "arne");
            _repository.GetByInvitationKeyAsync(request.InvitationKey).Returns(invitation);
            _accountRepository
            .WhenForAnyArgs(x => x.CreateAsync(null))
            .Do(x => x.Arg <Account>().SetId(52));
            var principal = PrincipalHelper.Create(52, "arne");


            var actual = await _sut.AcceptInvitation(principal, request);

            await _accountRepository.Received().CreateAsync(Arg.Any <Account>());

            var evt = _messageBus.Method("SendAsync").Arg <InvitationAccepted>();

            evt.AccountId.Should().Be(52);
        }
        Should_publish_AccountActivated_if_a_new_account_is_created_as_we_bypass_the_regular_account_registration_flow()
        {
            var invitation = new Invitation("*****@*****.**", "inviter");
            var request    =
                new AcceptInvitation("arne", "pass", invitation.InvitationKey)
            {
                AcceptedEmail = "*****@*****.**"
            };

            invitation.Add(1, "arne");
            _repository.GetByInvitationKeyAsync(request.InvitationKey).Returns(invitation);
            _accountRepository
            .WhenForAnyArgs(x => x.CreateAsync(null))
            .Do(x => x.Arg <Account>().SetId(52));
            var principal = PrincipalHelper.Create(52, "arne");


            var actual = await _sut.AcceptInvitation(principal, request);

            await _messageBus.Received().SendAsync(principal, Arg.Any <AccountActivated>());

            var evt = _messageBus.Method("SendAsync").Arg <AccountActivated>();

            evt.AccountId.Should().Be(52);
        }
Beispiel #3
0
        public async Task should_delete_invitation_when_its_accepted_to_prevent_creating_multiple_accounts_with_the_same_invitation_key()
        {
            var invitation = new Invitation("*****@*****.**", "inviter");
            var request    = new AcceptInvitation(InvitedAccountId, invitation.InvitationKey)
            {
                AcceptedEmail = "*****@*****.**"
            };

            invitation.Add(1, "arne");
            _repository.GetByInvitationKeyAsync(request.InvitationKey).Returns(invitation);

            var actual = await _sut.ExecuteAsync(request);

            actual.Should().NotBeNull();
        }
Beispiel #4
0
        public async Task should_notify_system_of_the_accepted_invitation()
        {
            var invitation = new Invitation("*****@*****.**", "inviter");
            var request    = new AcceptInvitation(InvitedAccountId, invitation.InvitationKey)
            {
                AcceptedEmail = "*****@*****.**"
            };

            invitation.Add(1, "arne");
            _repository.GetByInvitationKeyAsync(request.InvitationKey).Returns(invitation);

            var actual = await _sut.ExecuteAsync(request);

            _eventBus.Received().PublishAsync(Arg.Any <InvitationAccepted>());
            var evt = _eventBus.Method("PublishAsync").Arg <InvitationAccepted>();

            evt.AcceptedEmailAddress.Should().Be(request.AcceptedEmail);
            evt.AccountId.Should().Be(InvitedAccountId);
            evt.ApplicationIds[0].Should().Be(1);
            evt.UserName.Should().Be(_invitedAccount.UserName);
        }
Beispiel #5
0
        public async Task should_publish_AccountRegistered_if_a_new_account_is_created_as_we_bypass_the_regular_account_registration_flow()
        {
            var invitation = new Invitation("*****@*****.**", "inviter");
            var request    = new AcceptInvitation("arne", "pass", invitation.InvitationKey)
            {
                AcceptedEmail = "*****@*****.**"
            };

            invitation.Add(1, "arne");
            _repository.GetByInvitationKeyAsync(request.InvitationKey).Returns(invitation);
            _accountRepository
            .WhenForAnyArgs(x => x.CreateAsync(null))
            .Do(x => x.Arg <Account>().SetId(52));


            await _sut.ExecuteAsync(request);

            _eventBus.Received().PublishAsync(Arg.Any <AccountRegistered>());
            var evt = _eventBus.Method("PublishAsync").Arg <AccountRegistered>();

            evt.AccountId.Should().Be(52);
        }
        public async Task Should_notify_system_of_the_accepted_invitation()
        {
            var invitation = new Invitation("*****@*****.**", "inviter");
            var request    =
                new AcceptInvitation(InvitedAccountId, invitation.InvitationKey)
            {
                AcceptedEmail = "*****@*****.**"
            };

            invitation.Add(1, "arne");
            _repository.GetByInvitationKeyAsync(request.InvitationKey).Returns(invitation);
            var principal = PrincipalHelper.Create(52, "arne");

            var actual = await _sut.AcceptInvitation(principal, request);

            await _messageBus.Received().SendAsync(principal, Arg.Any <InvitationAccepted>());

            var evt = _messageBus.Method("SendAsync").Arg <InvitationAccepted>();

            evt.AcceptedEmailAddress.Should().Be(request.AcceptedEmail);
            evt.AccountId.Should().Be(InvitedAccountId);
            evt.ApplicationIds[0].Should().Be(1);
            evt.UserName.Should().Be(_invitedAccount.UserName);
        }