From 8da43808b8eb558ec98ecceaf146cd7489e8c428 Mon Sep 17 00:00:00 2001 From: ssgueye2 <127868584+ssgueye2@users.noreply.github.com> Date: Tue, 6 Jun 2023 11:48:45 +0200 Subject: [PATCH] #2161 fix edge model update (#2170) * Hide certificates when getting the magic ommand * fix edge model update * fix failed test --------- Co-authored-by: Kevin BEAUGRAND --- .../EdgeModels/EdgeModelDetailPage.razor | 2 +- .../Services/EdgeModelService.cs | 19 ++++++++++--------- .../Server/Services/EdgeModelServiceTest.cs | 4 ++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/AzureIoTHub.Portal.Client/Pages/EdgeModels/EdgeModelDetailPage.razor b/src/AzureIoTHub.Portal.Client/Pages/EdgeModels/EdgeModelDetailPage.razor index 7a30e343c..747e2b4b8 100644 --- a/src/AzureIoTHub.Portal.Client/Pages/EdgeModels/EdgeModelDetailPage.razor +++ b/src/AzureIoTHub.Portal.Client/Pages/EdgeModels/EdgeModelDetailPage.razor @@ -64,7 +64,7 @@ - + diff --git a/src/AzureIoTHub.Portal.Infrastructure/Services/EdgeModelService.cs b/src/AzureIoTHub.Portal.Infrastructure/Services/EdgeModelService.cs index 427f1ae63..2c84c222d 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Services/EdgeModelService.cs +++ b/src/AzureIoTHub.Portal.Infrastructure/Services/EdgeModelService.cs @@ -253,20 +253,21 @@ public async Task UpdateEdgeModel(IoTEdgeModel edgeModel) foreach (var labelEntity in edgeModelEntity.Labels) { this.labelRepository.Delete(labelEntity.Id); - } - + } + + edgeModel.ExternalIdentifier = await this.configService.RollOutEdgeModelConfiguration(edgeModel); + + _ = this.mapper.Map(edgeModel, edgeModelEntity); + + this.edgeModelRepository.Update(edgeModelEntity); + // For AWS, we do the update in the AwsConfiguration if (this.config.CloudProvider.Equals(CloudProviders.Azure, StringComparison.Ordinal)) { - _ = this.mapper.Map(edgeModel, edgeModelEntity); - - this.edgeModelRepository.Update(edgeModelEntity); - - await SaveModuleCommands(edgeModel); + await SaveModuleCommands(edgeModel); + } - - edgeModel.ExternalIdentifier = await this.configService.RollOutEdgeModelConfiguration(edgeModel); await this.unitOfWork.SaveAsync(); } diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Server/Services/EdgeModelServiceTest.cs b/src/AzureIoTHub.Portal.Tests.Unit/Server/Services/EdgeModelServiceTest.cs index 1e6aeb8b8..3738e5e99 100644 --- a/src/AzureIoTHub.Portal.Tests.Unit/Server/Services/EdgeModelServiceTest.cs +++ b/src/AzureIoTHub.Portal.Tests.Unit/Server/Services/EdgeModelServiceTest.cs @@ -404,6 +404,10 @@ public async Task UpdateEdgeModelForAWSShouldUpdateEdgeModel() this.mockLabelRepository.Setup(repository => repository.Delete(It.IsAny())) .Verifiable(); + _ = this.mockEdgeDeviceModelRepository.Setup(repository => repository.Update(It.IsAny())); + _ = this.mockUnitOfWork.Setup(work => work.SaveAsync()) + .Returns(Task.CompletedTask); + _ = this.mockConfigService.Setup(x => x.RollOutEdgeModelConfiguration(It.IsAny())) .Returns(Task.FromResult(Fixture.Create()));