diff --git a/src/administration/Administration.Service/BusinessLogic/IServiceAccountBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/IServiceAccountBusinessLogic.cs index a09adbcee5..eb3030413b 100644 --- a/src/administration/Administration.Service/BusinessLogic/IServiceAccountBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/IServiceAccountBusinessLogic.cs @@ -29,7 +29,7 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLog public interface IServiceAccountBusinessLogic { Task> CreateOwnCompanyServiceAccountAsync(ServiceAccountCreationInfo serviceAccountCreationInfos); - Task DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId); + Task DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId); Task GetOwnCompanyServiceAccountDetailsAsync(Guid serviceAccountId); Task UpdateOwnCompanyServiceAccountDetailsAsync(Guid serviceAccountId, ServiceAccountEditableDetails serviceAccountDetails); Task ResetOwnCompanyServiceAccountSecretAsync(Guid serviceAccountId); diff --git a/src/administration/Administration.Service/BusinessLogic/ServiceAccountBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/ServiceAccountBusinessLogic.cs index 2ba65c4e25..0c216d6e40 100644 --- a/src/administration/Administration.Service/BusinessLogic/ServiceAccountBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/ServiceAccountBusinessLogic.cs @@ -95,7 +95,7 @@ public async Task> CreateOwnCompanyServiceAcc sa.ServiceAccountData?.AuthData.Secret)); } - public async Task DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId) + public async Task DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId) { var serviceAccountRepository = portalRepositories.GetInstance(); var companyId = _identityData.CompanyId; @@ -105,7 +105,17 @@ public async Task DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId ProcessStepTypeId.AWAIT_CREATE_DIM_TECHNICAL_USER_RESPONSE }; var result = await serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(serviceAccountId, companyId, technicalUserCreationSteps).ConfigureAwait(ConfigureAwaitOptions.None) - ?? throw NotFoundException.Create(AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NOT_FOUND, [new("serviceAccountId", serviceAccountId.ToString()), new(CompanyId, companyId.ToString())]); + ?? throw NotFoundException.Create(AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NOT_FOUND, [new("serviceAccountId", serviceAccountId.ToString())]); + + if (result.ServiceAccountStatus != UserStatusId.ACTIVE) + { + throw ConflictException.Create(AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NOT_ACTIVE, [new("serviceAccountId", serviceAccountId.ToString())]); + } + + if (!result.IsOwnerOrProvider) + { + throw ForbiddenException.Create(AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NO_PROVIDER_OR_OWNER); + } if (result.StatusId is ConnectorStatusId.ACTIVE or ConnectorStatusId.PENDING) { @@ -121,7 +131,7 @@ public async Task DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId await serviceAccountManagement.DeleteServiceAccount(serviceAccountId, new DeleteServiceAccountData(result.UserRoleIds, result.ClientClientId, result.IsDimServiceAccount, result.CreationProcessInProgress, result.ProcessId)).ConfigureAwait(ConfigureAwaitOptions.None); ModifyConnectorForDeleteServiceAccount(serviceAccountId, result); - return await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None); + await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None); } private void ModifyConnectorForDeleteServiceAccount(Guid serviceAccountId, OwnServiceAccountData result) diff --git a/src/administration/Administration.Service/ErrorHandling/AdministrationServiceAccountErrorMessageContainer.cs b/src/administration/Administration.Service/ErrorHandling/AdministrationServiceAccountErrorMessageContainer.cs index 6983f07645..939f9a3697 100644 --- a/src/administration/Administration.Service/ErrorHandling/AdministrationServiceAccountErrorMessageContainer.cs +++ b/src/administration/Administration.Service/ErrorHandling/AdministrationServiceAccountErrorMessageContainer.cs @@ -26,20 +26,22 @@ public class AdministrationServiceAccountErrorMessageContainer : IErrorMessageCo { private static readonly IReadOnlyDictionary _messageContainer = new Dictionary { { AdministrationServiceAccountErrors.SERVICE_AUTH_SECRET_ARGUMENT, "other authenticationType values than SECRET are not supported yet , {authenticationType}" }, - { AdministrationServiceAccountErrors.SERVICE_NAME_EMPTY_ARGUMENT, "name must not be empty, {name}"}, - { AdministrationServiceAccountErrors.SERVICE_COMPANY_NOT_EXIST_CONFLICT, "company {companyId} does not exist"}, - { AdministrationServiceAccountErrors.SERVICE_BPN_NOT_SET_CONFLICT, "bpn not set for company {companyId}"}, - { AdministrationServiceAccountErrors.SERVICE_ROLES_NOT_ASSIGN_ARGUMENT, "The roles {unassignable} are not assignable to a service account, {userRoleIds}"}, - { AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NOT_FOUND, "serviceAccount {serviceAccountId} not found for company {companyId}"}, - { AdministrationServiceAccountErrors.SERVICE_USERID_ACTIVATION_PENDING_CONFLICT, "Technical User is linked to an active connector. Change the link or deactivate the connector to delete the technical user."}, - { AdministrationServiceAccountErrors.SERVICE_USERID_ACTIVATION_ACTIVE_CONFLICT, "Technical User is linked to an active subscription. Deactivate the subscription to delete the technical user."}, - { AdministrationServiceAccountErrors.SERVICE_UNDEFINED_CLIENTID_CONFLICT, "undefined clientId for serviceAccount {serviceAccountId}"}, - { AdministrationServiceAccountErrors.SERVICE_ID_PATH_NOT_MATCH_ARGUMENT, "serviceAccountId {serviceAccountId} from path does not match the one in body {serviceAccountDetailsServiceAccountId}"}, - { AdministrationServiceAccountErrors.SERVICE_INACTIVE_CONFLICT, "serviceAccount {serviceAccountId} is already INACTIVE"}, - { AdministrationServiceAccountErrors.SERVICE_CLIENTID_NOT_NULL_CONFLICT, "clientClientId of serviceAccount {serviceAccountId} should not be null"}, + { AdministrationServiceAccountErrors.SERVICE_NAME_EMPTY_ARGUMENT, "name must not be empty, {name}" }, + { AdministrationServiceAccountErrors.SERVICE_COMPANY_NOT_EXIST_CONFLICT, "company {companyId} does not exist" }, + { AdministrationServiceAccountErrors.SERVICE_BPN_NOT_SET_CONFLICT, "bpn not set for company {companyId}" }, + { AdministrationServiceAccountErrors.SERVICE_ROLES_NOT_ASSIGN_ARGUMENT, "The roles {unassignable} are not assignable to a service account, {userRoleIds}" }, + { AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NOT_FOUND, "serviceAccount {serviceAccountId} does not exist" }, + { AdministrationServiceAccountErrors.SERVICE_USERID_ACTIVATION_PENDING_CONFLICT, "Technical User is linked to an active connector. Change the link or deactivate the connector to delete the technical user." }, + { AdministrationServiceAccountErrors.SERVICE_USERID_ACTIVATION_ACTIVE_CONFLICT, "Technical User is linked to an active subscription. Deactivate the subscription to delete the technical user." }, + { AdministrationServiceAccountErrors.SERVICE_UNDEFINED_CLIENTID_CONFLICT, "undefined clientId for serviceAccount {serviceAccountId}" }, + { AdministrationServiceAccountErrors.SERVICE_ID_PATH_NOT_MATCH_ARGUMENT, "serviceAccountId {serviceAccountId} from path does not match the one in body {serviceAccountDetailsServiceAccountId}" }, + { AdministrationServiceAccountErrors.SERVICE_INACTIVE_CONFLICT, "serviceAccount {serviceAccountId} is already INACTIVE" }, + { AdministrationServiceAccountErrors.SERVICE_CLIENTID_NOT_NULL_CONFLICT, "clientClientId of serviceAccount {serviceAccountId} should not be null" }, { AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NOT_LINKED_TO_PROCESS, "Service Account {serviceAccountId} is not linked to a process" }, - { AdministrationServiceAccountErrors.SERVICE_ACCOUNT_PENDING_PROCESS_STEPS, "Service Account {serviceAccountId} has pending process steps {processStepTypeIds}"}, - { AdministrationServiceAccountErrors.TECHNICAL_USER_CREATION_IN_PROGRESS, "Technical user can't be deleted because the creation progress is still running"} + { AdministrationServiceAccountErrors.SERVICE_ACCOUNT_PENDING_PROCESS_STEPS, "Service Account {serviceAccountId} has pending process steps {processStepTypeIds}" }, + { AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NOT_ACTIVE, "Service Account {serviceAccountId} is not status active" }, + { AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NO_PROVIDER_OR_OWNER, "Only provider or owner of the service account are allowed to delete it" }, + { AdministrationServiceAccountErrors.TECHNICAL_USER_CREATION_IN_PROGRESS, "Technical user can't be deleted because the creation progress is still running" } }.ToImmutableDictionary(x => (int)x.Key, x => x.Value); public Type Type { get => typeof(AdministrationServiceAccountErrors); } @@ -62,5 +64,7 @@ public enum AdministrationServiceAccountErrors SERVICE_CLIENTID_NOT_NULL_CONFLICT, SERVICE_ACCOUNT_NOT_LINKED_TO_PROCESS, SERVICE_ACCOUNT_PENDING_PROCESS_STEPS, - TECHNICAL_USER_CREATION_IN_PROGRESS + TECHNICAL_USER_CREATION_IN_PROGRESS, + SERVICE_ACCOUNT_NOT_ACTIVE, + SERVICE_ACCOUNT_NO_PROVIDER_OR_OWNER } diff --git a/src/portalbackend/PortalBackend.DBAccess/Models/OwnServiceAccountData.cs b/src/portalbackend/PortalBackend.DBAccess/Models/OwnServiceAccountData.cs index 07df725b72..b7ba9b2d86 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Models/OwnServiceAccountData.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Models/OwnServiceAccountData.cs @@ -24,6 +24,8 @@ namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; public record OwnServiceAccountData( IEnumerable UserRoleIds, Guid ServiceAccountId, + UserStatusId ServiceAccountStatus, + bool IsOwnerOrProvider, Guid ServiceAccountVersion, Guid? ConnectorId, string? ClientClientId, diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/ServiceAccountRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/ServiceAccountRepository.cs index 15862fa27a..834073a7b6 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/ServiceAccountRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/ServiceAccountRepository.cs @@ -97,12 +97,12 @@ public void AttachAndModifyCompanyServiceAccount( public Task GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(Guid serviceAccountId, Guid companyId, IEnumerable processStepsToFilter) => portalDbContext.CompanyServiceAccounts .Where(serviceAccount => - serviceAccount.Id == serviceAccountId && - serviceAccount.Identity!.UserStatusId == UserStatusId.ACTIVE && - (serviceAccount.CompaniesLinkedServiceAccount!.Owners == companyId || serviceAccount.CompaniesLinkedServiceAccount!.Provider == companyId)) + serviceAccount.Id == serviceAccountId) .Select(sa => new OwnServiceAccountData( sa.Identity!.IdentityAssignedRoles.Select(r => r.UserRoleId), sa.Id, + sa.Identity!.UserStatusId, + sa.CompaniesLinkedServiceAccount!.Owners == companyId || sa.CompaniesLinkedServiceAccount!.Provider == companyId, sa.Version, sa.Connector!.Id, sa.ClientClientId, diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs index bba213511e..46a761a1ef 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs @@ -86,6 +86,8 @@ public ServiceAccountBusinessLogicTests() _processStepRepository = A.Fake(); _portalRepositories = A.Fake(); A.CallTo(() => _portalRepositories.GetInstance()).Returns(_processStepRepository); + A.CallTo(() => _portalRepositories.GetInstance()).Returns(_serviceAccountRepository); + A.CallTo(() => _portalRepositories.GetInstance()).Returns(_userRolesRepository); _identity = A.Fake(); _identityService = A.Fake(); @@ -523,7 +525,11 @@ public async Task DeleteOwnCompanyServiceAccountAsync_WithNotExistingServiceAcco public async Task DeleteOwnCompanyServiceAccountAsync_WithExistingOfferSubscriptiom_ThrowsNotFoundException() { // Arrange - SetupDeleteOwnCompanyServiceAccountForValidOfferSubscription(); + var serviceAccount = new CompanyServiceAccount(Guid.NewGuid(), Guid.NewGuid(), "test-sa", "test", CompanyServiceAccountTypeId.OWN, CompanyServiceAccountKindId.INTERNAL); + A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(ValidServiceAccountId, ValidCompanyId, A>._)) + .Returns(new OwnServiceAccountData(_userRoleIds, serviceAccount.Id, UserStatusId.ACTIVE, true, serviceAccount.Version, null, null, ConnectorStatusId.INACTIVE, OfferSubscriptionStatusId.ACTIVE, false, false, null)); + A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(A.That.Not.Matches(x => x == ValidServiceAccountId), A._, A>._)) + .Returns(null); var sut = new ServiceAccountBusinessLogic(_provisioningManager, _portalRepositories, _options, null!, _identityService, _serviceAccountManagement); @@ -539,7 +545,11 @@ public async Task DeleteOwnCompanyServiceAccountAsync_WithExistingOfferSubscript public async Task DeleteOwnCompanyServiceAccountAsync_WithInvalidConnectorStatus_ThrowsConflictException() { // Arrange - SetupDeleteOwnCompanyServiceAccountForInvalidConnectorStatus(); + var serviceAccount = new CompanyServiceAccount(Guid.NewGuid(), Guid.NewGuid(), "test-sa", "test", CompanyServiceAccountTypeId.OWN, CompanyServiceAccountKindId.INTERNAL); + A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(ValidServiceAccountId, ValidCompanyId, A>._)) + .Returns(new OwnServiceAccountData(_userRoleIds, serviceAccount.Id, UserStatusId.ACTIVE, true, serviceAccount.Version, null, null, ConnectorStatusId.ACTIVE, OfferSubscriptionStatusId.PENDING, false, false, null)); + A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(A.That.Not.Matches(x => x == ValidServiceAccountId), A._, A>._)) + .Returns(null); var sut = new ServiceAccountBusinessLogic(_provisioningManager, _portalRepositories, _options, null!, _identityService, _serviceAccountManagement); @@ -551,6 +561,44 @@ public async Task DeleteOwnCompanyServiceAccountAsync_WithInvalidConnectorStatus ex.Message.Should().Be(AdministrationServiceAccountErrors.SERVICE_USERID_ACTIVATION_PENDING_CONFLICT.ToString()); } + [Theory] + [InlineData(UserStatusId.PENDING_DELETION)] + [InlineData(UserStatusId.PENDING)] + [InlineData(UserStatusId.DELETED)] + [InlineData(UserStatusId.INACTIVE)] + public async Task DeleteOwnCompanyServiceAccountAsync_WithServiceAccountNotActive_ThrowsConflictException(UserStatusId userStatusId) + { + // Arrange + A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(ValidServiceAccountId, ValidCompanyId, A>._)) + .Returns(new OwnServiceAccountData(_userRoleIds, ValidServiceAccountId, userStatusId, true, Guid.NewGuid(), null, null, ConnectorStatusId.ACTIVE, OfferSubscriptionStatusId.PENDING, false, false, null)); + + var sut = new ServiceAccountBusinessLogic(_provisioningManager, _portalRepositories, _options, null!, _identityService, _serviceAccountManagement); + + // Act + async Task Act() => await sut.DeleteOwnCompanyServiceAccountAsync(ValidServiceAccountId); + + // Assert + var ex = await Assert.ThrowsAsync(Act); + ex.Message.Should().Be(AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NOT_ACTIVE.ToString()); + } + + [Fact] + public async Task DeleteOwnCompanyServiceAccountAsync_WithUserNotOwnerOrProvider_ThrowsForbiddenException() + { + // Arrange + A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(ValidServiceAccountId, ValidCompanyId, A>._)) + .Returns(new OwnServiceAccountData(_userRoleIds, ValidServiceAccountId, UserStatusId.ACTIVE, false, Guid.NewGuid(), null, null, ConnectorStatusId.ACTIVE, OfferSubscriptionStatusId.PENDING, false, false, null)); + + var sut = new ServiceAccountBusinessLogic(_provisioningManager, _portalRepositories, _options, null!, _identityService, _serviceAccountManagement); + + // Act + async Task Act() => await sut.DeleteOwnCompanyServiceAccountAsync(ValidServiceAccountId); + + // Assert + var ex = await Assert.ThrowsAsync(Act); + ex.Message.Should().Be(AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NO_PROVIDER_OR_OWNER.ToString()); + } + [Fact] public async Task DeleteOwnCompanyServiceAccountAsync_WithoutClient_CallsExpected() { @@ -569,28 +617,10 @@ public async Task DeleteOwnCompanyServiceAccountAsync_WithoutClient_CallsExpecte // Act await sut.DeleteOwnCompanyServiceAccountAsync(ValidServiceAccountId); - // Assert - // if (isDimServiceAccount) - // { - // // A.CallTo(() => _processStepRepository.CreateProcessStepRange(A>.That.Matches(x => x.Count() == 1 && x.First().ProcessStepTypeId == ProcessStepTypeId.DELETE_DIM_TECHNICAL_USER && x.First().ProcessStepStatusId == ProcessStepStatusId.TODO && x.First().ProcessId == processId))).MustHaveHappenedOnceExactly(); - // // A.CallTo(() => _userRepository.AttachAndModifyIdentity(A._, A>._, A>._)).MustHaveHappenedOnceExactly(); - // // A.CallTo(() => _provisioningManager.DeleteCentralClientAsync(A._)).MustNotHaveHappened(); - // // identity.UserStatusId.Should().Be(UserStatusId.PENDING_DELETION); - // } - // else if (withClient) - // { - // A.CallTo(() => _userRepository.AttachAndModifyIdentity(A._, A>._, A>._)).MustHaveHappenedOnceExactly(); - // A.CallTo(() => _processStepRepository.CreateProcessStepRange(A>._)).MustNotHaveHappened(); - // A.CallTo(() => _provisioningManager.DeleteCentralClientAsync(ClientId)).MustHaveHappenedOnceExactly(); - // identity.UserStatusId.Should().Be(UserStatusId.DELETED); - // } - A.CallTo(() => _connectorsRepository.AttachAndModifyConnector(ValidConnectorId, A>._, A>._)).MustHaveHappenedOnceExactly(); connector.CompanyServiceAccountId.Should().BeNull(); A.CallTo(() => _serviceAccountManagement.DeleteServiceAccount(ValidServiceAccountId, A._)) .MustHaveHappenedOnceExactly(); - // var validServiceAccountUserRoleIds = _userRoleIds.Select(userRoleId => (ValidServiceAccountId, userRoleId)); - // A.CallTo(() => _userRolesRepository.DeleteCompanyUserAssignedRoles(A>.That.IsSameSequenceAs(validServiceAccountUserRoleIds))).MustHaveHappenedOnceExactly(); } #endregion @@ -726,8 +756,6 @@ private void SetupGetOwnCompanyServiceAccountDetails() A.CallTo(() => _provisioningManager.GetCentralClientAuthDataAsync(A._)) .Returns(authData); - - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_serviceAccountRepository); } private void SetupResetOwnCompanyServiceAccountSecret() @@ -737,8 +765,6 @@ private void SetupResetOwnCompanyServiceAccountSecret() A.CallTo(() => _provisioningManager.ResetCentralClientAuthDataAsync(A._)) .Returns(authData); - - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_serviceAccountRepository); } private void SetupUpdateOwnCompanyServiceAccountDetails() @@ -760,8 +786,6 @@ private void SetupUpdateOwnCompanyServiceAccountDetails() A.CallTo(() => _provisioningManager.ResetCentralClientAuthDataAsync(A._)) .Returns(authData); - - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_serviceAccountRepository); } private void SetupGetOwnCompanyServiceAccount() @@ -794,7 +818,7 @@ private void SetupDeleteOwnCompanyServiceAccount(Connector? connector = null, Id { var serviceAccount = new CompanyServiceAccount(Guid.NewGuid(), Guid.NewGuid(), "test-sa", "test", CompanyServiceAccountTypeId.OWN, CompanyServiceAccountKindId.INTERNAL); A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(ValidServiceAccountId, ValidCompanyId, A>._)) - .Returns(new OwnServiceAccountData(_userRoleIds, serviceAccount.Id, serviceAccount.Version, ValidConnectorId, ClientId, ConnectorStatusId.INACTIVE, OfferSubscriptionStatusId.PENDING, false, false, processId)); + .Returns(new OwnServiceAccountData(_userRoleIds, serviceAccount.Id, UserStatusId.ACTIVE, true, serviceAccount.Version, ValidConnectorId, ClientId, ConnectorStatusId.INACTIVE, OfferSubscriptionStatusId.PENDING, false, false, processId)); A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(A.That.Not.Matches(x => x == ValidServiceAccountId), A._, A>._)) .Returns(null); @@ -817,36 +841,10 @@ private void SetupDeleteOwnCompanyServiceAccount(Connector? connector = null, Id }); } - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_serviceAccountRepository); A.CallTo(() => _portalRepositories.GetInstance()).Returns(_connectorsRepository); A.CallTo(() => _portalRepositories.GetInstance()).Returns(_userRepository); - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_userRolesRepository); A.CallTo(() => _portalRepositories.GetInstance()).Returns(_processStepRepository); } - private void SetupDeleteOwnCompanyServiceAccountForInvalidConnectorStatus() - { - var serviceAccount = new CompanyServiceAccount(Guid.NewGuid(), Guid.NewGuid(), "test-sa", "test", CompanyServiceAccountTypeId.OWN, CompanyServiceAccountKindId.INTERNAL); - A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(ValidServiceAccountId, ValidCompanyId, A>._)) - .Returns(new OwnServiceAccountData(_userRoleIds, serviceAccount.Id, serviceAccount.Version, null, null, ConnectorStatusId.ACTIVE, OfferSubscriptionStatusId.PENDING, false, false, null)); - A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(A.That.Not.Matches(x => x == ValidServiceAccountId), A._, A>._)) - .Returns(null); - - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_serviceAccountRepository); - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_userRolesRepository); - } - - private void SetupDeleteOwnCompanyServiceAccountForValidOfferSubscription() - { - var serviceAccount = new CompanyServiceAccount(Guid.NewGuid(), Guid.NewGuid(), "test-sa", "test", CompanyServiceAccountTypeId.OWN, CompanyServiceAccountKindId.INTERNAL); - A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(ValidServiceAccountId, ValidCompanyId, A>._)) - .Returns(new OwnServiceAccountData(_userRoleIds, serviceAccount.Id, serviceAccount.Version, null, null, ConnectorStatusId.INACTIVE, OfferSubscriptionStatusId.ACTIVE, false, false, null)); - A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(A.That.Not.Matches(x => x == ValidServiceAccountId), A._, A>._)) - .Returns(null); - - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_serviceAccountRepository); - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_userRolesRepository); - } - #endregion }