diff --git a/src/EndUsersApplication/EndUsersApplication.cs b/src/EndUsersApplication/EndUsersApplication.cs index df72e6ef..2228d578 100644 --- a/src/EndUsersApplication/EndUsersApplication.cs +++ b/src/EndUsersApplication/EndUsersApplication.cs @@ -258,10 +258,8 @@ public async Task> RegisterPersonAsync(ICallerC } var notified = await _notificationsService.NotifyReRegistrationCourtesyAsync(context, - unregisteredUser.Id, - unregisteredUserProfile.EmailAddress, unregisteredUserProfile.DisplayName, - unregisteredUserProfile.Timezone, unregisteredUserProfile.Address.CountryCode, - cancellationToken); + unregisteredUser.Id, unregisteredUserProfile.EmailAddress, unregisteredUserProfile.DisplayName, + unregisteredUserProfile.Timezone, unregisteredUserProfile.Address.CountryCode, cancellationToken); if (!notified.IsSuccessful) { return notified.Error; diff --git a/src/IdentityApplication.UnitTests/PasswordCredentialsApplicationSpec.cs b/src/IdentityApplication.UnitTests/PasswordCredentialsApplicationSpec.cs index 1a278cff..032c5c8f 100644 --- a/src/IdentityApplication.UnitTests/PasswordCredentialsApplicationSpec.cs +++ b/src/IdentityApplication.UnitTests/PasswordCredentialsApplicationSpec.cs @@ -312,6 +312,53 @@ public async Task WhenRegisterPersonAsyncAndAlreadyExists_ThenDoesNothing() It.IsAny())); } + [Fact] + public async Task WhenAuthenticateAsyncAndSendingEmailFails_ThenReturnsError() + { + var registeredAccount = new RegisteredEndUser + { + Id = "auserid", + Profile = new UserProfileWithDefaultMembership + { + Id = "anid", + UserId = "auserid", + Classification = UserProfileClassification.Person, + Name = new PersonName + { + FirstName = "aname" + }, + DisplayName = "adisplayname", + EmailAddress = "auser@company.com" + } + }; + _endUsersService.Setup(uas => uas.RegisterPersonPrivateAsync(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), + It.IsAny(), It.IsAny())) + .Returns(Task.FromResult>(registeredAccount)); + _repository.Setup(s => s.FindCredentialsByUserIdAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult, Error>>(Optional + .None)); + _notificationsService.Setup(ns => + ns.NotifyPasswordRegistrationConfirmationAsync(It.IsAny(), It.IsAny(), + It.IsAny(), + It.IsAny(), It.IsAny())) + .ReturnsAsync(Error.Unexpected()); + + var result = await _application.RegisterPersonAsync(_caller.Object, "aninvitationtoken", "afirstname", + "alastname", "auser@company.com", "apassword", "atimezone", "acountrycode", true, CancellationToken.None); + + result.Should().BeError(ErrorCode.Unexpected); + _repository.Verify(s => s.SaveAsync(It.IsAny(), It.IsAny()), + Times.Never); + _notificationsService.Verify(ns => + ns.NotifyPasswordRegistrationConfirmationAsync(_caller.Object, "auser@company.com", "adisplayname", + "averificationtoken", It.IsAny())); + _endUsersService.Verify(eus => eus.RegisterPersonPrivateAsync(_caller.Object, "aninvitationtoken", + "auser@company.com", "afirstname", "alastname", "atimezone", "acountrycode", true, + It.IsAny())); + } + [Fact] public async Task WhenRegisterPersonAsyncAndNotExists_ThenCreatesAndSendsConfirmation() { diff --git a/src/IdentityApplication/PasswordCredentialsApplication.cs b/src/IdentityApplication/PasswordCredentialsApplication.cs index 88afad8f..014f96e9 100644 --- a/src/IdentityApplication/PasswordCredentialsApplication.cs +++ b/src/IdentityApplication/PasswordCredentialsApplication.cs @@ -321,19 +321,24 @@ private async Task> RegisterPersonInternalAsyn return initiated.Error; } - var updated = await _repository.SaveAsync(credentials, cancellationToken); - if (!updated.IsSuccessful) + var notified = await _notificationsService.NotifyPasswordRegistrationConfirmationAsync(context, + credentials.Registration.Value.EmailAddress, + credentials.Registration.Value.Name, credentials.Verification.Token, cancellationToken); + if (!notified.IsSuccessful) { - return updated.Error; + return notified.Error; } - await _notificationsService.NotifyPasswordRegistrationConfirmationAsync(context, - updated.Value.Registration.Value.EmailAddress, - updated.Value.Registration.Value.Name, updated.Value.Verification.Token, cancellationToken); + var saved = await _repository.SaveAsync(credentials, cancellationToken); + if (!saved.IsSuccessful) + { + return saved.Error; + } - _recorder.TraceInformation(context.ToCall(), "Password credentials created for {UserId}", updated.Value.UserId); + credentials = saved.Value; + _recorder.TraceInformation(context.ToCall(), "Password credentials created for {UserId}", credentials.UserId); - return updated.Value.ToCredential(user); + return credentials.ToCredential(user); } /// diff --git a/src/SaaStack.sln.DotSettings b/src/SaaStack.sln.DotSettings index a7730733..fa56eec9 100644 --- a/src/SaaStack.sln.DotSettings +++ b/src/SaaStack.sln.DotSettings @@ -330,6 +330,11 @@ <Policy Inspect="True" Prefix="When" Suffix="" Style="AaBb_AaBb"><ExtraRule Prefix="" Suffix="" Style="AaBb" /><ExtraRule Prefix="Setup" Suffix="" Style="AaBb" /><ExtraRule Prefix="Configure" Suffix="" Style="AaBb" /></Policy> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="Configure" Suffix="" Style="AaBb" /></Policy> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Any" Description="Local functions"><ElementKinds><Kind Name="LOCAL_FUNCTION" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="Configure" Suffix="" Style="AaBb" /></Policy></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Any" Description="Methods"><ElementKinds><Kind Name="METHOD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="When" Suffix="" Style="AaBb_AaBb"><ExtraRule Prefix="" Suffix="" Style="AaBb" /><ExtraRule Prefix="Setup" Suffix="" Style="AaBb" /><ExtraRule Prefix="Configure" Suffix="" Style="AaBb" /></Policy></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Any" Description="Enum members"><ElementKinds><Kind Name="ENUM_MEMBER" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="" Style="AaBb_AaBb" /></Policy></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Any" Description="Types and namespaces"><ElementKinds><Kind Name="NAMESPACE" /><Kind Name="CLASS" /><Kind Name="STRUCT" /><Kind Name="ENUM" /><Kind Name="DELEGATE" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Any" Description="Properties"><ElementKinds><Kind Name="PROPERTY" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="Configure" Suffix="" Style="AaBb" /></Policy></Policy> True True True @@ -337,6 +342,7 @@ True True True + True 10 True True