From 2da124402d13c8d733d1f96fc176086e10fcb007 Mon Sep 17 00:00:00 2001 From: Md Majid Akhter <101315579+qxz2mqe@users.noreply.github.com> Date: Mon, 24 Jul 2023 23:42:08 +0530 Subject: [PATCH] feat(apps & services): enhance offer endpoints with DateLastChanged update (#152) add DateLastChanged update to offer endpoints ------ Refs: CPLP-2886 Reviewed-By: Phil Schneider --- .../BusinessLogic/AppChangeBusinessLogic.cs | 10 +++ .../BusinessLogic/AppReleaseBusinessLogic.cs | 5 ++ .../OfferDocumentService.cs | 4 ++ .../Offers.Library/Service/OfferService.cs | 13 +++- .../ServiceReleaseBusinessLogic.cs | 1 + .../BusinessLogic/AppBusinessLogicTests.cs | 1 - .../AppChangeBusinessLogicTest.cs | 64 ++++++++++++++++--- .../AppReleaseBusinessLogicTest.cs | 11 +++- .../OfferDocumentServiceTests.cs | 10 ++- .../Service/OfferServiceTests.cs | 20 +++++- 10 files changed, 123 insertions(+), 16 deletions(-) diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppChangeBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppChangeBusinessLogic.cs index 58f725f1c8..3c492d56d9 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppChangeBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppChangeBusinessLogic.cs @@ -97,6 +97,9 @@ private async Task> InsertActiveAppUserRoleAsync(Guid a await _provisioningManager.AddRolesToClientAsync(clientId, userRoles.Select(x => x.Role)).ConfigureAwait(false); } + _portalRepositories.GetInstance().AttachAndModifyOffer(appId, offer => + offer.DateLastChanged = DateTimeOffset.UtcNow); + var notificationContent = new { AppName = result.AppName, @@ -125,6 +128,8 @@ public async Task CreateOrUpdateAppDescriptionByIdAsync(Guid appId, Guid company await ValidateAndGetAppDescription(appId, companyId, offerRepository), offerDescriptionDatas.Select(od => new ValueTuple(od.LanguageCode, od.LongDescription, od.ShortDescription))); + offerRepository.AttachAndModifyOffer(appId, offer => + offer.DateLastChanged = DateTimeOffset.UtcNow); await _portalRepositories.SaveAsync().ConfigureAwait(false); } @@ -189,6 +194,8 @@ public async Task UploadOfferAssignedAppLeadImageDocumentByIdAsync(Guid appId, ( offerRepository.RemoveOfferAssignedDocuments(result.documentStatusDatas.Select(data => (appId, data.DocumentId))); documentRepository.RemoveDocuments(result.documentStatusDatas.Select(data => data.DocumentId)); + offerRepository.AttachAndModifyOffer(appId, offer => + offer.DateLastChanged = DateTimeOffset.UtcNow); await _portalRepositories.SaveAsync().ConfigureAwait(false); } @@ -246,6 +253,9 @@ private async Task UpdateTenantUrlAsyncInternal(Guid offerId, Guid subscriptionI os.AppSubscriptionUrl = url; }); + _portalRepositories.GetInstance().AttachAndModifyOffer(offerId, offer => + offer.DateLastChanged = DateTimeOffset.UtcNow); + if (!string.IsNullOrEmpty(detailData.ClientClientId)) { await _provisioningManager.UpdateClient(detailData.ClientClientId, url, url.AppendToPathEncoded("*")).ConfigureAwait(false); diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs index 0dc28ae02d..19066207ac 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs @@ -140,6 +140,9 @@ private async Task> InsertAppUserRoleAsync(Guid appId, throw new ForbiddenException($"Company {companyId} is not the provider company of app {appId}"); } var roleData = AppExtensions.CreateUserRolesWithDescriptions(_portalRepositories.GetInstance(), appId, userRoles); + + _portalRepositories.GetInstance().AttachAndModifyOffer(appId, offer => + offer.DateLastChanged = DateTimeOffset.UtcNow); await _portalRepositories.SaveAsync().ConfigureAwait(false); return roleData; } @@ -259,6 +262,7 @@ private async Task CreateAppAsync(AppRequestModel appRequestModel, Guid co app.ContactNumber = appRequestModel.ContactNumber; app.MarketingUrl = appRequestModel.ProviderUri; app.LicenseTypeId = LicenseTypeId.COTS; + app.DateLastChanged = DateTimeOffset.UtcNow; }).Id; appRepository.AddOfferDescriptions(appRequestModel.Descriptions.Select(d => (appId, d.LanguageCode, d.LongDescription, d.ShortDescription))); @@ -339,6 +343,7 @@ public async Task UpdateAppReleaseAsync(Guid appId, AppRequestModel appRequestMo app.ContactEmail = appData.ContactEmail; app.ContactNumber = appData.ContactNumber; app.MarketingUrl = appData.MarketingUrl; + app.DateLastChanged = DateTimeOffset.UtcNow; }); _offerService.UpsertRemoveOfferDescription(appId, appRequestModel.Descriptions, appData.OfferDescriptions); diff --git a/src/marketplace/Offers.Library.Web/OfferDocumentService.cs b/src/marketplace/Offers.Library.Web/OfferDocumentService.cs index 9a22ca3829..519af98cc6 100644 --- a/src/marketplace/Offers.Library.Web/OfferDocumentService.cs +++ b/src/marketplace/Offers.Library.Web/OfferDocumentService.cs @@ -97,6 +97,10 @@ public async Task UploadDocumentAsync(Guid id, DocumentTypeId documentTypeId, IF x.CompanyUserId = identity.UserId; }); _portalRepositories.GetInstance().CreateOfferAssignedDocument(id, doc.Id); + + offerRepository.AttachAndModifyOffer(id, offer => + offer.DateLastChanged = DateTimeOffset.UtcNow); + await _portalRepositories.SaveAsync().ConfigureAwait(false); } } diff --git a/src/marketplace/Offers.Library/Service/OfferService.cs b/src/marketplace/Offers.Library/Service/OfferService.cs index 13c527cae3..28835f48f5 100644 --- a/src/marketplace/Offers.Library/Service/OfferService.cs +++ b/src/marketplace/Offers.Library/Service/OfferService.cs @@ -181,6 +181,10 @@ public async Task> CreateOrUpdateProviderOfferAgr companyUserId, DateTimeOffset.UtcNow) .Select(consent => new ConsentStatusData(consent.AgreementId, consent.ConsentStatusId)); + + _portalRepositories.GetInstance().AttachAndModifyOffer(offerId, offer => + offer.DateLastChanged = DateTimeOffset.UtcNow); + await _portalRepositories.SaveAsync().ConfigureAwait(false); return ConsentStatusdata; } @@ -233,6 +237,7 @@ public async Task CreateServiceOfferingAsync(ServiceOfferingData data, (Gu service.ProviderCompanyId = identity.CompanyId; service.MarketingUrl = data.ProviderUri; service.LicenseTypeId = LicenseTypeId.COTS; + service.DateLastChanged = DateTimeOffset.UtcNow; }); var licenseId = offerRepository.CreateOfferLicenses(data.Price).Id; offerRepository.CreateOfferAssignedLicense(service.Id, licenseId); @@ -629,7 +634,10 @@ public async Task DeactivateOfferIdAsync(Guid offerId, Guid companyId, OfferType throw new ConflictException($"offerStatus is in Incorrect State"); } offerRepository.AttachAndModifyOffer(offerId, offer => - offer.OfferStatusId = OfferStatusId.INACTIVE); + { + offer.OfferStatusId = OfferStatusId.INACTIVE; + offer.DateReleased = DateTime.UtcNow; + }); await _portalRepositories.SaveAsync().ConfigureAwait(false); } @@ -784,6 +792,9 @@ public async Task UpdateTechnicalUserProfiles(Guid offerId, OfferTypeId offerTyp x => x.TechnicalUserProfileId) .Select(x => x.TechnicalUserProfileId)); + _portalRepositories.GetInstance().AttachAndModifyOffer(offerId, offer => + offer.DateLastChanged = DateTimeOffset.UtcNow); + await _portalRepositories.SaveAsync().ConfigureAwait(false); } diff --git a/src/marketplace/Services.Service/BusinessLogic/ServiceReleaseBusinessLogic.cs b/src/marketplace/Services.Service/BusinessLogic/ServiceReleaseBusinessLogic.cs index 6d490ce2d0..091ff0a0a7 100644 --- a/src/marketplace/Services.Service/BusinessLogic/ServiceReleaseBusinessLogic.cs +++ b/src/marketplace/Services.Service/BusinessLogic/ServiceReleaseBusinessLogic.cs @@ -202,6 +202,7 @@ public async Task UpdateServiceAsync(Guid serviceId, ServiceUpdateRequestData da offer => { offer.SalesManagerId = serviceData.SalesManagerId; + offer.DateLastChanged = DateTimeOffset.UtcNow; }); _offerService.UpsertRemoveOfferDescription(serviceId, data.Descriptions, serviceData.Descriptions); diff --git a/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppBusinessLogicTests.cs b/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppBusinessLogicTests.cs index 4102b98d0e..3569d7f4a0 100644 --- a/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppBusinessLogicTests.cs +++ b/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppBusinessLogicTests.cs @@ -76,7 +76,6 @@ public async Task AddFavouriteAppForUser_ExecutesSuccessfully() { // Arrange var appId = _fixture.Create(); - var sut = new AppsBusinessLogic(_portalRepositories, null!, null!, null!, Options.Create(new AppsSettings()), null!); // Act diff --git a/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppChangeBusinessLogicTest.cs b/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppChangeBusinessLogicTest.cs index a764edfa91..6438061a64 100644 --- a/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppChangeBusinessLogicTest.cs +++ b/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppChangeBusinessLogicTest.cs @@ -132,7 +132,14 @@ public async Task AddActiveAppUserRoleAsync_ExecutesSuccessfully() userRoleDescriptions.Add(createdUserRoleDescriptions); return createdUserRoleDescriptions; }); - + var existingOffer = _fixture.Create(); + existingOffer.DateLastChanged = DateTimeOffset.UtcNow; + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)) + .Invokes((Guid _, Action setOptionalParameters, Action? initializeParemeters) => + { + initializeParemeters?.Invoke(existingOffer); + setOptionalParameters(existingOffer); + }); A.CallTo(() => _notificationService.CreateNotifications(A>._, A._, A>._, A._, A._)) .Returns(_fixture.CreateMany(4).AsFakeIAsyncEnumerable(out var createNotificationsResultAsyncEnumerator)); @@ -169,7 +176,7 @@ public async Task AddActiveAppUserRoleAsync_ExecutesSuccessfully() x => x.Should().HaveCount(2).And.Satisfy( x => x.UserRoleId == userRoles!.ElementAt(2).Id && x.LanguageShortName == appAssignedRoleDesc[2].Descriptions.ElementAt(0).LanguageCode && x.Description == appAssignedRoleDesc[2].Descriptions.ElementAt(0).Description, x => x.UserRoleId == userRoles!.ElementAt(2).Id && x.LanguageShortName == appAssignedRoleDesc[2].Descriptions.ElementAt(1).LanguageCode && x.Description == appAssignedRoleDesc[2].Descriptions.ElementAt(1).Description)); - + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)).MustHaveHappenedOnceExactly(); A.CallTo(() => _notificationService.CreateNotifications(A>._, A._, A>._, A._, A._)) .MustHaveHappenedOnceExactly(); A.CallTo(() => createNotificationsResultAsyncEnumerator.MoveNextAsync()) @@ -201,7 +208,7 @@ public async Task AddActiveAppUserRoleAsync_WithCompanyUserIdNotSet_ThrowsForbid var clientIds = new[] { "client" }; A.CallTo(() => _offerRepository.GetInsertActiveAppUserRoleDataAsync(appId, OfferTypeId.APP)) .Returns((true, appName, Guid.NewGuid(), clientIds)); - + var existingOffer = _fixture.Create(); //Act async Task Act() => await _sut.AddActiveAppUserRoleAsync(appId, appAssignedRoleDesc, (_identity.UserId, _identity.CompanyId)).ConfigureAwait(false); @@ -347,13 +354,21 @@ public async Task CreateOrUpdateAppDescriptionByIdAsync_withEmptyExistingDescrip A.CallTo(() => _offerRepository.GetActiveOfferDescriptionDataByIdAsync(appId, OfferTypeId.APP, _identity.CompanyId)) .Returns(appDescriptionData); - + var existingOffer = _fixture.Create(); + existingOffer.DateLastChanged = DateTimeOffset.UtcNow; + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)) + .Invokes((Guid _, Action setOptionalParameters, Action? initializeParemeters) => + { + initializeParemeters?.Invoke(existingOffer); + setOptionalParameters(existingOffer); + }); // Act await _sut.CreateOrUpdateAppDescriptionByIdAsync(appId, _identity.CompanyId, updateDescriptionData).ConfigureAwait(false); // Assert A.CallTo(() => _offerRepository.CreateUpdateDeleteOfferDescriptions(appId, A>._, A>.That.IsSameSequenceAs(updateDescriptionData.Select(x => new ValueTuple(x.LanguageCode, x.LongDescription, x.ShortDescription))))) .MustHaveHappenedOnceExactly(); + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)).MustHaveHappenedOnceExactly(); } [Fact] @@ -480,7 +495,14 @@ public async Task UploadOfferAssignedAppLeadImageDocumentById_ExpectedCalls() var offerAssignedDocument = new OfferAssignedDocument(offerId, docId); offerAssignedDocuments.Add(offerAssignedDocument); }); - + var existingOffer = _fixture.Create(); + existingOffer.DateLastChanged = DateTimeOffset.UtcNow; + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)) + .Invokes((Guid _, Action setOptionalParameters, Action? initializeParemeters) => + { + initializeParemeters?.Invoke(existingOffer); + setOptionalParameters(existingOffer); + }); // Act await _sut.UploadOfferAssignedAppLeadImageDocumentByIdAsync(appId, (_identity.UserId, _identity.CompanyId), file, CancellationToken.None); @@ -490,6 +512,7 @@ public async Task UploadOfferAssignedAppLeadImageDocumentById_ExpectedCalls() A.CallTo(() => _offerRepository.CreateOfferAssignedDocument(A._, A._)).MustHaveHappenedOnceExactly(); A.CallTo(() => _offerRepository.RemoveOfferAssignedDocuments(A>.That.IsSameSequenceAs(documentStatusData.Select(data => new ValueTuple(appId, data.DocumentId))))).MustHaveHappenedOnceExactly(); A.CallTo(() => _documentRepository.RemoveDocuments(A>.That.IsSameSequenceAs(documentStatusData.Select(data => data.DocumentId)))).MustHaveHappenedOnceExactly(); + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)).MustHaveHappenedOnceExactly(); A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappenedOnceExactly(); documents.Should().ContainSingle().Which.Should().Match(x => x.Id == documentId && x.MediaTypeId == MediaTypeId.JPEG && x.DocumentTypeId == DocumentTypeId.APP_LEADIMAGE && x.DocumentStatusId == DocumentStatusId.LOCKED); offerAssignedDocuments.Should().ContainSingle().Which.Should().Match(x => x.DocumentId == documentId && x.OfferId == appId); @@ -622,13 +645,21 @@ public async Task UpdateTenantUrlAsync_WithValidData_CallsExpected() initialize?.Invoke(details); setParameters.Invoke(details); }); - + var existingOffer = _fixture.Create(); + existingOffer.DateLastChanged = DateTimeOffset.UtcNow; + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)) + .Invokes((Guid _, Action setOptionalParameters, Action? initializeParemeters) => + { + initializeParemeters?.Invoke(existingOffer); + setOptionalParameters(existingOffer); + }); // Act await _sut.UpdateTenantUrlAsync(appId, subscriptionId, data, _identity.CompanyId).ConfigureAwait(false); // Assert A.CallTo(() => _provisioningManager.UpdateClient(clientClientId, data.Url, A._)).MustHaveHappenedOnceExactly(); A.CallTo(() => _notificationService.CreateNotifications(A>._, A._, A>._, A._, A._)).MustNotHaveHappened(); + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)).MustHaveHappenedOnceExactly(); notifications.Should().ContainSingle().Which .NotificationTypeId.Should().Be(NotificationTypeId.SUBSCRIPTION_URL_UPDATE); details.AppSubscriptionUrl.Should().Be(data.Url); @@ -668,7 +699,14 @@ public async Task UpdateTenantUrlAsync_WithoutRequesterButValidData_CallsExpecte initialize?.Invoke(details); setParameters.Invoke(details); }); - + var existingOffer = _fixture.Create(); + existingOffer.DateLastChanged = DateTimeOffset.UtcNow; + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)) + .Invokes((Guid _, Action setOptionalParameters, Action? initializeParemeters) => + { + initializeParemeters?.Invoke(existingOffer); + setOptionalParameters(existingOffer); + }); // Act await _sut.UpdateTenantUrlAsync(appId, subscriptionId, data, _identity.CompanyId).ConfigureAwait(false); @@ -676,6 +714,7 @@ public async Task UpdateTenantUrlAsync_WithoutRequesterButValidData_CallsExpecte A.CallTo(() => _provisioningManager.UpdateClient(clientClientId, data.Url, A._)).MustHaveHappenedOnceExactly(); A.CallTo(() => createNotificationsResultAsyncEnumerator.MoveNextAsync()) .MustHaveHappened(5, Times.Exactly); + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)).MustHaveHappenedOnceExactly(); notifications.Should().BeEmpty(); details.AppSubscriptionUrl.Should().Be(data.Url); } @@ -711,13 +750,21 @@ public async Task UpdateTenantUrlAsync_WithoutClientId_CallsExpected() initialize?.Invoke(details); setParameters.Invoke(details); }); - + var existingOffer = _fixture.Create(); + existingOffer.DateLastChanged = DateTimeOffset.UtcNow; + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)) + .Invokes((Guid _, Action setOptionalParameters, Action? initializeParemeters) => + { + initializeParemeters?.Invoke(existingOffer); + setOptionalParameters(existingOffer); + }); // Act await _sut.UpdateTenantUrlAsync(appId, subscriptionId, data, _identity.CompanyId).ConfigureAwait(false); // Assert A.CallTo(() => _provisioningManager.UpdateClient(clientClientId, data.Url, A._)).MustNotHaveHappened(); A.CallTo(() => _notificationService.CreateNotifications(A>._, A._, A>._, A._, A._)).MustHaveHappenedOnceExactly(); + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)).MustHaveHappenedOnceExactly(); notifications.Should().BeEmpty(); details.AppSubscriptionUrl.Should().Be(data.Url); } @@ -735,7 +782,6 @@ public async Task UpdateTenantUrlAsync_WithSameUrl_CallsNothing() var detailId = _fixture.Create(); A.CallTo(() => _offerSubscriptionsRepository.GetUpdateUrlDataAsync(appId, subscriptionId, _identity.CompanyId)) .Returns(new OfferUpdateUrlData("testApp", false, true, Guid.Empty, subscribingCompany, OfferSubscriptionStatusId.ACTIVE, new OfferUpdateUrlSubscriptionDetailData(detailId, clientClientId, oldUrl))); - // Act await _sut.UpdateTenantUrlAsync(appId, subscriptionId, data, _identity.CompanyId).ConfigureAwait(false); diff --git a/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppReleaseBusinessLogicTest.cs b/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppReleaseBusinessLogicTest.cs index d20a8f9009..30349a18b4 100644 --- a/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppReleaseBusinessLogicTest.cs +++ b/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppReleaseBusinessLogicTest.cs @@ -156,7 +156,14 @@ public async Task CreateServiceOffering_WithValidDataAndEmptyDescriptions_Return userRoleDescriptions.Add(createdUserRoleDescriptions); return createdUserRoleDescriptions; }); - + var existingOffer = _fixture.Create(); + existingOffer.DateLastChanged = DateTimeOffset.UtcNow; + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)) + .Invokes((Guid _, Action setOptionalParameters, Action? initializeParemeters) => + { + initializeParemeters?.Invoke(existingOffer); + setOptionalParameters(existingOffer); + }); // Act var result = await _sut.AddAppUserRoleAsync(appId, appUserRoles, _identity.CompanyId).ConfigureAwait(false); @@ -176,7 +183,7 @@ public async Task CreateServiceOffering_WithValidDataAndEmptyDescriptions_Return x => x.UserRoleText == appUserRoles[1].Role, x => x.UserRoleText == appUserRoles[2].Role ); - + A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A>._, A?>._)).MustHaveHappenedOnceExactly(); A.CallTo(() => _userRolesRepository.CreateAppUserRoleDescriptions(A>._)).MustHaveHappened(appUserRoles.Length, Times.Exactly); userRoleDescriptions.Should() .HaveSameCount(appUserRoles) diff --git a/tests/marketplace/Offer.Library.Web.Tests/OfferDocumentServiceTests.cs b/tests/marketplace/Offer.Library.Web.Tests/OfferDocumentServiceTests.cs index db34616032..5830097738 100644 --- a/tests/marketplace/Offer.Library.Web.Tests/OfferDocumentServiceTests.cs +++ b/tests/marketplace/Offer.Library.Web.Tests/OfferDocumentServiceTests.cs @@ -85,11 +85,19 @@ public async Task UploadDocumentAsync_WithValidData_CallsExpected(OfferTypeId of var offerAssignedDocument = new OfferAssignedDocument(offerId, docId); offerAssignedDocuments.Add(offerAssignedDocument); }); - + var existingOffer = _fixture.Create(); + existingOffer.DateLastChanged = DateTimeOffset.UtcNow; + A.CallTo(() => _offerRepository.AttachAndModifyOffer(_validAppId, A>._, A?>._)) + .Invokes((Guid _, Action setOptionalParameters, Action? initializeParemeters) => + { + initializeParemeters?.Invoke(existingOffer); + setOptionalParameters(existingOffer); + }); // Act await _sut.UploadDocumentAsync(_validAppId, documentTypeId, file, (_identity.UserId, _identity.CompanyId), offerTypeId, uploadDocumentTypeIdSettings, CancellationToken.None).ConfigureAwait(false); // Assert + A.CallTo(() => _offerRepository.AttachAndModifyOffer(_validAppId, A>._, A?>._)).MustHaveHappenedOnceExactly(); A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappenedOnceExactly(); documents.Should().HaveCount(1); offerAssignedDocuments.Should().HaveCount(1); diff --git a/tests/marketplace/Offers.Library.Tests/Service/OfferServiceTests.cs b/tests/marketplace/Offers.Library.Tests/Service/OfferServiceTests.cs index cd8f31e524..b0c5b29805 100644 --- a/tests/marketplace/Offers.Library.Tests/Service/OfferServiceTests.cs +++ b/tests/marketplace/Offers.Library.Tests/Service/OfferServiceTests.cs @@ -1419,7 +1419,14 @@ public async Task CreateOrUpdateProviderOfferAgreementConsent_WithValidData_Retu new(consentId, agreementId, CompanyUserCompanyId, _companyUser.Id, ConsentStatusId.ACTIVE, utcNow), new(newCreatedConsentId, additionalAgreementId, CompanyUserCompanyId, _companyUser.Id, ConsentStatusId.ACTIVE, utcNow) }); - + var existingOffer = _fixture.Create(); + existingOffer.DateLastChanged = DateTimeOffset.UtcNow; + A.CallTo(() => _offerRepository.AttachAndModifyOffer(offerId, A>._, A?>._)) + .Invokes((Guid _, Action setOptionalParameters, Action? initializeParemeters) => + { + initializeParemeters?.Invoke(existingOffer); + setOptionalParameters(existingOffer); + }); // Act var result = await _sut.CreateOrUpdateProviderOfferAgreementConsent(offerId, consentData, _identity.CompanyId, offerTypeId).ConfigureAwait(false); @@ -1432,6 +1439,7 @@ public async Task CreateOrUpdateProviderOfferAgreementConsent_WithValidData_Retu x => x.AgreementId == agreementId && x.ConsentStatus == ConsentStatusId.ACTIVE, x => x.AgreementId == additionalAgreementId && x.ConsentStatus == ConsentStatusId.ACTIVE ); + A.CallTo(() => _offerRepository.AttachAndModifyOffer(offerId, A>._, A?>._)).MustHaveHappenedOnceExactly(); } #endregion @@ -1875,7 +1883,14 @@ public async Task UpdateTechnicalUserProfiles_ReturnsExpectedResult(OfferTypeId .Returns(new Guid[] { userRole1Id, userRole2Id }.ToAsyncEnumerable()); A.CallTo(() => _technicalUserProfileRepository.CreateTechnicalUserProfile(A._, offerId)) .Returns(new TechnicalUserProfile(newProfileId, offerId)); - + var existingOffer = _fixture.Create(); + existingOffer.DateLastChanged = DateTimeOffset.UtcNow; + A.CallTo(() => _offerRepository.AttachAndModifyOffer(offerId, A>._, A?>._)) + .Invokes((Guid _, Action setOptionalParameters, Action? initializeParemeters) => + { + initializeParemeters?.Invoke(existingOffer); + setOptionalParameters(existingOffer); + }); // Act await _sut.UpdateTechnicalUserProfiles(offerId, offerTypeId, data, _identity.CompanyId, "cl1").ConfigureAwait(false); @@ -1896,6 +1911,7 @@ public async Task UpdateTechnicalUserProfiles_ReturnsExpectedResult(OfferTypeId .MustHaveHappenedOnceExactly(); A.CallTo(() => _technicalUserProfileRepository.RemoveTechnicalUserProfiles(A>.That.Matches(x => x.Count() == 2 && x.Contains(technicalUserProfile2) && x.Contains(technicalUserProfile3)))) .MustHaveHappenedOnceExactly(); + A.CallTo(() => _offerRepository.AttachAndModifyOffer(offerId, A>._, A?>._)).MustHaveHappenedOnceExactly(); A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappenedOnceExactly(); }