Extensions
Get informations
To obtain some sort of informations such as file name, content length, content type, md5, created and last modified,
you can use GetBlobInformationsAsync
extension on ITestFixture
and IApplicationFactory
where arguments are
container name and blob file name with extension.
Blob infos model
namespace FluentTesting.Azurite
{
public class BlobData
{
/// <summary>
/// File name
/// </summary>
public required string Name { get; set; }
/// <summary>
/// Content length
/// </summary>
public required long ContentLength { get; set; }
/// <summary>
/// Content type
/// </summary>
public required string ContentType { get; set; }
/// <summary>
/// Content MD5 hash for futher assertions
/// </summary>
public required string ContentMd5 { get; set; }
/// <summary>
/// Created
/// </summary>
public required DateTimeOffset Created { get; set; }
/// <summary>
/// Last modified
/// </summary>
public required DateTimeOffset LastModified { get; set; }
}
}
var blobInfos = await fixture.GetBlobInformationsAsync("photos", "asd.png");
blobInfos.LastModified.Should().BeLessThan(TimeSpan.FromTicks(DateTimeOffset.Now.Ticks));
Note
To assert MD5 hash you can use predefined Extension AssertFileResponseAgainstBlobMd5Async
Assert MD5
AssertFileResponseAgainstBlobMd5Async
extension on ITestFixture
validates HttpResponseMessage
representing FileContentResponse
or any other version of stream against blob file via MD5 hash.
Arguments are response, container name and file name with extension.
await fixture.AssertFileResponseAgainstBlobMd5Async(res, "photos", "asd.png");
Warning
If returns that blobInfo is null, you should double check that container name and file are filled correctly! Or that file really exists
If your response object is more complex and contains several files, you can assert stream via AssertFileResponseAgainstBlobMd5Async
extension on ITestFixture
that validates Stream
representing desired file against blob file via MD5 hash.
Arguments are stream, container name and file name with extension.
using var fileStream = await res.Content.ReadAsStreamAsync(); // Obtain specific part from multipart if needed
await fixture.AssertFileResponseAgainstBlobMd5Async(fileStream, "photos", "asd.png");