From 2981b3dbdfa0b2c9956777a57a4efb9eb1b6f37b Mon Sep 17 00:00:00 2001 From: Kevin BEAUGRAND <9513635+kbeaugrand@users.noreply.github.com> Date: Fri, 22 Jul 2022 15:21:39 +0200 Subject: [PATCH] Fix #958 (#960) --- .../Services/DeviceModelsClientServiceTests.cs | 6 ++---- .../Services/LoRaWanDeviceModelsClientServiceTests.cs | 6 ++---- .../Client/Services/DeviceModelsClientService.cs | 6 ++++-- .../Client/Services/LoRaWanDeviceModelsClientService.cs | 6 ++++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/AzureIoTHub.Portal.Server.Tests.Unit/Services/DeviceModelsClientServiceTests.cs b/src/AzureIoTHub.Portal.Server.Tests.Unit/Services/DeviceModelsClientServiceTests.cs index 3e0e94cf3..8ba859a50 100644 --- a/src/AzureIoTHub.Portal.Server.Tests.Unit/Services/DeviceModelsClientServiceTests.cs +++ b/src/AzureIoTHub.Portal.Server.Tests.Unit/Services/DeviceModelsClientServiceTests.cs @@ -201,12 +201,10 @@ public async Task ChangeAvatarPropertiesShouldChangeAvatar() var deviceModel = Fixture.Create(); var content = new MultipartFormDataContent(); - _ = MockHttpClient.When(HttpMethod.Get, $"/api/models/{deviceModel.ModelId}/properties") + _ = MockHttpClient.When(HttpMethod.Post, $"/api/models/{deviceModel.ModelId}/avatar") .With(m => { - _ = m.Content.Should().BeAssignableTo>(); - var body = m.Content as ObjectContent; - _ = body.Value.Should().BeEquivalentTo(content); + _ = m.Content.Should().BeEquivalentTo(content); return true; }) .Respond(HttpStatusCode.Created); diff --git a/src/AzureIoTHub.Portal.Server.Tests.Unit/Services/LoRaWanDeviceModelsClientServiceTests.cs b/src/AzureIoTHub.Portal.Server.Tests.Unit/Services/LoRaWanDeviceModelsClientServiceTests.cs index 116870b65..8aeca28cd 100644 --- a/src/AzureIoTHub.Portal.Server.Tests.Unit/Services/LoRaWanDeviceModelsClientServiceTests.cs +++ b/src/AzureIoTHub.Portal.Server.Tests.Unit/Services/LoRaWanDeviceModelsClientServiceTests.cs @@ -190,12 +190,10 @@ public async Task ChangeAvatarPropertiesShouldChangeAvatar() }; var content = new MultipartFormDataContent(); - _ = MockHttpClient.When(HttpMethod.Get, $"/api/lorawan/models/{deviceModel.ModelId}/properties") + _ = MockHttpClient.When(HttpMethod.Post, $"/api/lorawan/models/{deviceModel.ModelId}/avatar") .With(m => { - _ = m.Content.Should().BeAssignableTo>(); - var body = m.Content as ObjectContent; - _ = body.Value.Should().BeEquivalentTo(content); + _ = m.Content.Should().BeEquivalentTo(content); return true; }) .Respond(HttpStatusCode.Created); diff --git a/src/AzureIoTHub.Portal/Client/Services/DeviceModelsClientService.cs b/src/AzureIoTHub.Portal/Client/Services/DeviceModelsClientService.cs index 1297af296..6731f837b 100644 --- a/src/AzureIoTHub.Portal/Client/Services/DeviceModelsClientService.cs +++ b/src/AzureIoTHub.Portal/Client/Services/DeviceModelsClientService.cs @@ -58,9 +58,11 @@ public Task GetAvatarUrl(string deviceModelId) return this.http.GetStringAsync($"api/models/{deviceModelId}/avatar"); } - public Task ChangeAvatar(string deviceModelId, MultipartFormDataContent avatar) + public async Task ChangeAvatar(string deviceModelId, MultipartFormDataContent avatar) { - return this.http.PostAsJsonAsync($"api/models/{deviceModelId}/avatar", avatar); + var result = await this.http.PostAsync($"api/models/{deviceModelId}/avatar", avatar); + + _ = result.EnsureSuccessStatusCode(); } } } diff --git a/src/AzureIoTHub.Portal/Client/Services/LoRaWanDeviceModelsClientService.cs b/src/AzureIoTHub.Portal/Client/Services/LoRaWanDeviceModelsClientService.cs index be2869b10..235efebc1 100644 --- a/src/AzureIoTHub.Portal/Client/Services/LoRaWanDeviceModelsClientService.cs +++ b/src/AzureIoTHub.Portal/Client/Services/LoRaWanDeviceModelsClientService.cs @@ -48,9 +48,11 @@ public Task GetAvatarUrl(string deviceModelId) return this.http.GetStringAsync($"api/lorawan/models/{deviceModelId}/avatar"); } - public Task ChangeAvatar(string deviceModelId, MultipartFormDataContent avatar) + public async Task ChangeAvatar(string deviceModelId, MultipartFormDataContent avatar) { - return this.http.PostAsJsonAsync($"api/lorawan/models/{deviceModelId}/avatar", avatar); + var result = await this.http.PostAsync($"api/lorawan/models/{deviceModelId}/avatar", avatar); + + _ = result.EnsureSuccessStatusCode(); } } }