From e09c38956482e49c0cb4982a02d1c1f7b0e35729 Mon Sep 17 00:00:00 2001 From: Norbert Truchsess Date: Wed, 14 Jun 2023 02:14:48 +0200 Subject: [PATCH] fix unit-tests after rebase --- .../ServiceAccountBusinessLogicTests.cs | 47 +++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs index d9bee25dcf..35df6979e9 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs @@ -410,8 +410,7 @@ public async Task DeleteOwnCompanyServiceAccountAsync_WithNotExistingServiceAcco public async Task DeleteOwnCompanyServiceAccountAsync_WithInvalidConnectorStatus_ThrowsConflictException() { // Arrange - //var serviceAccountId = Guid.NewGuid(); - SetupDeleteOwnCompanyServiceAccountForInvalidConnectorStatus(false, false); + SetupDeleteOwnCompanyServiceAccountForInvalidConnectorStatus(); var sut = new ServiceAccountBusinessLogic(_provisioningManager, _portalRepositories, _options, null!); @@ -566,8 +565,17 @@ private void SetupDeleteOwnCompanyServiceAccount(bool withServiceAccount, bool w { A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(ValidServiceAccountId, _identity.CompanyId)) .Returns((_userRoleIds, withServiceAccount ? ValidConnectorId : null, withClient ? ClientId : null, statusId: ConnectorStatusId.INACTIVE)); - A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(A.That.Not.Matches(x => x == ValidServiceAccountId), _identity.CompanyId)) - .Returns(((IEnumerable, Guid?, string?, ConnectorStatusId))default); + A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(A.That.Not.Matches(x => x == ValidServiceAccountId), A._)) + .Returns(((IEnumerable, Guid?, string?, ConnectorStatusId?))default); + + if (identity != null) + { + A.CallTo(() => _userRepository.AttachAndModifyIdentity(ValidServiceAccountId, null, A>._)) + .Invokes((Guid _, Action? _, Action modify) => + { + modify.Invoke(identity); + }); + } if (companyServiceAccount != null) { @@ -590,37 +598,18 @@ private void SetupDeleteOwnCompanyServiceAccount(bool withServiceAccount, bool w A.CallTo(() => _portalRepositories.GetInstance()).Returns(_serviceAccountRepository); A.CallTo(() => _portalRepositories.GetInstance()).Returns(_connectorsRepository); + A.CallTo(() => _portalRepositories.GetInstance()).Returns(_userRepository); + A.CallTo(() => _portalRepositories.GetInstance()).Returns(_userRolesRepository); } - private void SetupDeleteOwnCompanyServiceAccountForInvalidConnectorStatus(bool withServiceAccount, bool withClient, Connector? connector = null, Identity? identity = null, CompanyServiceAccount? companyServiceAccount = null) + private void SetupDeleteOwnCompanyServiceAccountForInvalidConnectorStatus() { A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(ValidServiceAccountId, _identity.CompanyId)) - .Returns((_userRoleIds, withServiceAccount ? ValidConnectorId : null, withClient ? ClientId : null, statusId: ConnectorStatusId.ACTIVE)); - A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(A.That.Not.Matches(x => x == ValidServiceAccountId), _identity.CompanyId)) - .Returns(((IEnumerable, Guid?, string?, ConnectorStatusId))default); - - if (identity != null) - { - A.CallTo(() => _userRepository.AttachAndModifyIdentity(ValidServiceAccountId, null, A>._)) - .Invokes((Guid _, Action? _, Action modify) => - { - modify.Invoke(identity); - }); - } - - if (connector != null) - { - A.CallTo(() => _connectorsRepository.AttachAndModifyConnector(ValidConnectorId, A>._, A>._)) - .Invokes((Guid _, Action? initialize, Action modify) => - { - initialize?.Invoke(connector); - modify.Invoke(connector); - }); - } + .Returns((_userRoleIds, null, null, statusId: ConnectorStatusId.ACTIVE)); + A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(A.That.Not.Matches(x => x == ValidServiceAccountId), A._)) + .Returns(((IEnumerable, Guid?, string?, ConnectorStatusId?))default); A.CallTo(() => _portalRepositories.GetInstance()).Returns(_serviceAccountRepository); - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_connectorsRepository); - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_userRepository); A.CallTo(() => _portalRepositories.GetInstance()).Returns(_userRolesRepository); }