From 8562a95144bb9e2ddfca58adef364573a8d3d010 Mon Sep 17 00:00:00 2001 From: Hocine Hacherouf Date: Tue, 9 Aug 2022 12:16:19 +0200 Subject: [PATCH] Add unit test on SyncImagesCacheControl #763 --- .../Managers/DeviceModelImageManagerTest.cs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/AzureIoTHub.Portal.Server.Tests.Unit/Managers/DeviceModelImageManagerTest.cs b/src/AzureIoTHub.Portal.Server.Tests.Unit/Managers/DeviceModelImageManagerTest.cs index 69ef72b81..78c1123f0 100644 --- a/src/AzureIoTHub.Portal.Server.Tests.Unit/Managers/DeviceModelImageManagerTest.cs +++ b/src/AzureIoTHub.Portal.Server.Tests.Unit/Managers/DeviceModelImageManagerTest.cs @@ -66,6 +66,7 @@ public async Task ChangeDeviceModelImageShouldUploadImageAndReturnItsUri() // Arrange var deviceModelId = Fixture.Create(); var expectedImageUri = Fixture.Create(); + using var imageAsMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(Fixture.Create())); _ = this.mockBlobServiceClient .Setup(x => x.GetBlobContainerClient(It.IsAny())) @@ -91,7 +92,6 @@ public async Task ChangeDeviceModelImageShouldUploadImageAndReturnItsUri() .Returns(expectedImageUri); // Act - using var imageAsMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(Fixture.Create())); var result = await this.deviceModelImageManager.ChangeDeviceModelImageAsync(deviceModelId, imageAsMemoryStream); // Assert @@ -129,5 +129,39 @@ public async Task WhenDeleteAsyncFailedDeleteDeviceModelImageAsyncShouldThrowAnI _ = await act.Should().ThrowAsync(); MockRepository.VerifyAll(); } + + [Test] + public async Task SyncImagesCacheControlShouldUpdateBlobsCacheControls() + { + // Arrange + var deviceModelId = Fixture.Create(); + + var blob = BlobsModelFactory.BlobItem(name:deviceModelId); + var blobsPage = Page.FromValues(new[] { blob }, default, new Mock().Object); + var blobsPageable = AsyncPageable.FromPages(new[] { blobsPage }); + + _ = this.mockBlobServiceClient + .Setup(x => x.GetBlobContainerClient(It.IsAny())) + .Returns(this.mockBlobContainerClient.Object); + + _ = this.mockBlobContainerClient + .Setup(x => x.GetBlobsAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Returns(blobsPageable); + + _ = this.mockBlobContainerClient + .Setup(x => x.GetBlobClient(deviceModelId)) + .Returns(this.mockBlobClient.Object); + + _ = this.mockBlobClient + .Setup(client => + client.SetHttpHeadersAsync(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(Response.FromValue(BlobsModelFactory.BlobInfo(ETag.All, DateTimeOffset.Now), Mock.Of())); + + // Act + await this.deviceModelImageManager.SyncImagesCacheControl(); + + // Assert + MockRepository.VerifyAll(); + } } }