Skip to content

Commit

Permalink
fix unit-tests after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Jun 14, 2023
1 parent c2ced8c commit e09c389
Showing 1 changed file with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!);

Expand Down Expand Up @@ -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<Guid>.That.Not.Matches(x => x == ValidServiceAccountId), _identity.CompanyId))
.Returns(((IEnumerable<Guid>, Guid?, string?, ConnectorStatusId))default);
A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(A<Guid>.That.Not.Matches(x => x == ValidServiceAccountId), A<Guid>._))
.Returns(((IEnumerable<Guid>, Guid?, string?, ConnectorStatusId?))default);

if (identity != null)
{
A.CallTo(() => _userRepository.AttachAndModifyIdentity(ValidServiceAccountId, null, A<Action<Identity>>._))
.Invokes((Guid _, Action<Identity>? _, Action<Identity> modify) =>
{
modify.Invoke(identity);
});
}

if (companyServiceAccount != null)
{
Expand All @@ -590,37 +598,18 @@ private void SetupDeleteOwnCompanyServiceAccount(bool withServiceAccount, bool w

A.CallTo(() => _portalRepositories.GetInstance<IServiceAccountRepository>()).Returns(_serviceAccountRepository);
A.CallTo(() => _portalRepositories.GetInstance<IConnectorsRepository>()).Returns(_connectorsRepository);
A.CallTo(() => _portalRepositories.GetInstance<IUserRepository>()).Returns(_userRepository);
A.CallTo(() => _portalRepositories.GetInstance<IUserRolesRepository>()).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<Guid>.That.Not.Matches(x => x == ValidServiceAccountId), _identity.CompanyId))
.Returns(((IEnumerable<Guid>, Guid?, string?, ConnectorStatusId))default);

if (identity != null)
{
A.CallTo(() => _userRepository.AttachAndModifyIdentity(ValidServiceAccountId, null, A<Action<Identity>>._))
.Invokes((Guid _, Action<Identity>? _, Action<Identity> modify) =>
{
modify.Invoke(identity);
});
}

if (connector != null)
{
A.CallTo(() => _connectorsRepository.AttachAndModifyConnector(ValidConnectorId, A<Action<Connector>>._, A<Action<Connector>>._))
.Invokes((Guid _, Action<Connector>? initialize, Action<Connector> modify) =>
{
initialize?.Invoke(connector);
modify.Invoke(connector);
});
}
.Returns((_userRoleIds, null, null, statusId: ConnectorStatusId.ACTIVE));
A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(A<Guid>.That.Not.Matches(x => x == ValidServiceAccountId), A<Guid>._))
.Returns(((IEnumerable<Guid>, Guid?, string?, ConnectorStatusId?))default);

A.CallTo(() => _portalRepositories.GetInstance<IServiceAccountRepository>()).Returns(_serviceAccountRepository);
A.CallTo(() => _portalRepositories.GetInstance<IConnectorsRepository>()).Returns(_connectorsRepository);
A.CallTo(() => _portalRepositories.GetInstance<IUserRepository>()).Returns(_userRepository);
A.CallTo(() => _portalRepositories.GetInstance<IUserRolesRepository>()).Returns(_userRolesRepository);
}

Expand Down

0 comments on commit e09c389

Please sign in to comment.