diff --git a/DEPENDENCIES b/DEPENDENCIES index 7d4e102772..8f0b34a960 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -18,7 +18,7 @@ nuget/nuget/-/Laraue.EfCoreTriggers.Common/8.0.3, MIT, approved, #13968 nuget/nuget/-/Laraue.EfCoreTriggers.PostgreSql/8.0.3, MIT, approved, #13984 nuget/nuget/-/MailKit/4.3.0, MIT AND LicenseRef-scancode-ietf AND LicenseRef-scancode-ietf-trust AND (BSD-3-Clause AND LicenseRef-scancode-ietf-trust), approved, #13986 nuget/nuget/-/MimeKit/4.3.0, MIT AND FSFULLRWD AND LicenseRef-scancode-ietf AND LicenseRef-scancode-ietf-trust AND (BSD-3-Clause AND LicenseRef-scancode-ietf-trust) AND BSD-3-Clause AND MS-PL AND CC-BY-SA-4.0 AND LicenseRef-MIT-style AND CC-PDDC AND GPL-2.0-only, approved, #13987 -nuget/nuget/-/Mono.TextTemplating/2.2.1, MIT, approved, clearlydefined +nuget/nuget/-/Mono.TextTemplating/2.2.1, MIT, approved, #15073 nuget/nuget/-/NHamcrest/3.4.0, MIT, approved, #13964 nuget/nuget/-/NJsonSchema/10.9.0, MIT, approved, #9300 nuget/nuget/-/Namotion.Reflection/2.1.2, MIT, approved, #9320 diff --git a/src/administration/Administration.Service/BusinessLogic/SubscriptionConfigurationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/SubscriptionConfigurationBusinessLogic.cs index 7c044fa24f..5d72954488 100644 --- a/src/administration/Administration.Service/BusinessLogic/SubscriptionConfigurationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/SubscriptionConfigurationBusinessLogic.cs @@ -82,11 +82,13 @@ private async Task SetOfferProviderCompanyDetailsInternalAsync(ProviderDetailDat var providerDetailData = await companyRepository .GetProviderCompanyDetailsExistsForUser(companyId) .ConfigureAwait(ConfigureAwaitOptions.None); + var hasChanges = false; if (providerDetailData == default && data.Url != null) { await HandleCreateProviderCompanyDetails(data, companyId, companyRepository); + hasChanges = true; } - else if (data.Url != null) + else if (providerDetailData != default && data.Url != null) { companyRepository.AttachAndModifyProviderCompanyDetails( providerDetailData.ProviderCompanyDetailId, @@ -96,13 +98,18 @@ private async Task SetOfferProviderCompanyDetailsInternalAsync(ProviderDetailDat details.AutoSetupUrl = data.Url; details.DateLastChanged = DateTimeOffset.UtcNow; }); + hasChanges = true; } - else + else if (providerDetailData != default && data.Url == null) { companyRepository.RemoveProviderCompanyDetails(providerDetailData.ProviderCompanyDetailId); + hasChanges = true; } - await _portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None); + if (hasChanges) + { + await _portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None); + } } private static async Task HandleCreateProviderCompanyDetails(ProviderDetailData data, Guid companyId, ICompanyRepository companyRepository) diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/SubscriptionConfigurationBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/SubscriptionConfigurationBusinessLogicTests.cs index c9b0b58de5..7fc154b5d1 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/SubscriptionConfigurationBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/SubscriptionConfigurationBusinessLogicTests.cs @@ -199,10 +199,30 @@ public async Task SetProviderCompanyDetailsAsync_EmptyProviderDetailsId_ReturnsE // Assert A.CallTo(() => _companyRepository.CreateProviderCompanyDetail(A._, A._, A>._)).MustHaveHappened(); A.CallTo(() => _companyRepository.AttachAndModifyProviderCompanyDetails(A._, A>._, A>._)).MustNotHaveHappened(); - A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappened(1, Times.OrMore); + A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappenedOnceExactly(); _serviceProviderDetails.Should().ContainSingle(); } + [Fact] + public async Task SetProviderCompanyDetailsAsync_WithNotExistingAndUrlNull_DoesNothing() + { + // Arrange + SetupProviderCompanyDetails(); + var providerDetailData = new ProviderDetailData(null, null); + A.CallTo(() => _companyRepository.GetProviderCompanyDetailsExistsForUser(ExistingCompanyId)) + .Returns((Guid.Empty, null!)); + + // Act + await _sut.SetProviderCompanyDetailsAsync(providerDetailData); + + // Assert + A.CallTo(() => _companyRepository.CreateProviderCompanyDetail(A._, A._, A>._)).MustNotHaveHappened(); + A.CallTo(() => _companyRepository.RemoveProviderCompanyDetails(A._)).MustNotHaveHappened(); + A.CallTo(() => _companyRepository.AttachAndModifyProviderCompanyDetails(A._, A>._, A>._)).MustNotHaveHappened(); + A.CallTo(() => _portalRepositories.SaveAsync()).MustNotHaveHappened(); + _serviceProviderDetails.Should().BeEmpty(); + } + [Fact] public async Task SetProviderCompanyDetailsAsync_WithProviderDetailsAndNoUrl_RemovesProviderDetails() { @@ -255,7 +275,7 @@ public async Task SetProviderCompanyDetailsAsync_WithServiceProviderDetailsId_Re //Assert A.CallTo(() => _companyRepository.CreateProviderCompanyDetail(A._, A._, null)).MustNotHaveHappened(); A.CallTo(() => _companyRepository.AttachAndModifyProviderCompanyDetails(detailsId, A>._, A>._)).MustHaveHappenedOnceExactly(); - A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappened(1, Times.OrMore); + A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappenedOnceExactly(); initialDetail.Should().NotBeNull(); initialDetail!.AutoSetupUrl.Should().Be(existingUrl); modifyDetail.Should().NotBeNull();