Skip to content

Commit

Permalink
Add unit test on SyncImagesCacheControl #763
Browse files Browse the repository at this point in the history
  • Loading branch information
hocinehacherouf committed Aug 9, 2022
1 parent 1c94725 commit 8562a95
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public async Task ChangeDeviceModelImageShouldUploadImageAndReturnItsUri()
// Arrange
var deviceModelId = Fixture.Create<string>();
var expectedImageUri = Fixture.Create<Uri>();
using var imageAsMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(Fixture.Create<string>()));

_ = this.mockBlobServiceClient
.Setup(x => x.GetBlobContainerClient(It.IsAny<string>()))
Expand All @@ -91,7 +92,6 @@ public async Task ChangeDeviceModelImageShouldUploadImageAndReturnItsUri()
.Returns(expectedImageUri);

// Act
using var imageAsMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(Fixture.Create<string>()));
var result = await this.deviceModelImageManager.ChangeDeviceModelImageAsync(deviceModelId, imageAsMemoryStream);

// Assert
Expand Down Expand Up @@ -129,5 +129,39 @@ public async Task WhenDeleteAsyncFailedDeleteDeviceModelImageAsyncShouldThrowAnI
_ = await act.Should().ThrowAsync<InternalServerErrorException>();
MockRepository.VerifyAll();
}

[Test]
public async Task SyncImagesCacheControlShouldUpdateBlobsCacheControls()
{
// Arrange
var deviceModelId = Fixture.Create<string>();

var blob = BlobsModelFactory.BlobItem(name:deviceModelId);
var blobsPage = Page<BlobItem>.FromValues(new[] { blob }, default, new Mock<Response>().Object);
var blobsPageable = AsyncPageable<BlobItem>.FromPages(new[] { blobsPage });

_ = this.mockBlobServiceClient
.Setup(x => x.GetBlobContainerClient(It.IsAny<string>()))
.Returns(this.mockBlobContainerClient.Object);

_ = this.mockBlobContainerClient
.Setup(x => x.GetBlobsAsync(It.IsAny<BlobTraits>(), It.IsAny<BlobStates>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
.Returns(blobsPageable);

_ = this.mockBlobContainerClient
.Setup(x => x.GetBlobClient(deviceModelId))
.Returns(this.mockBlobClient.Object);

_ = this.mockBlobClient
.Setup(client =>
client.SetHttpHeadersAsync(It.IsAny<BlobHttpHeaders>(), It.IsAny<BlobRequestConditions>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Response.FromValue(BlobsModelFactory.BlobInfo(ETag.All, DateTimeOffset.Now), Mock.Of<Response>()));

// Act
await this.deviceModelImageManager.SyncImagesCacheControl();

// Assert
MockRepository.VerifyAll();
}
}
}

0 comments on commit 8562a95

Please sign in to comment.