-1

I am working on nUnit tests for .NET CORE 3.1 Azure function with Azure Storage. I need to mock Azure Storage and need help on that!

I get collection of Azure Storage Files Microsoft.WindowsAzure.Storage.File.CloudFile in object fileList and then I am looping through it. Then I am calling FetchAttributesAsync() How can I mock FetchAttributesAsync, SetMetadataAsync & ContentMD5

if (fileList.Any())
{
  foreach (var foundFile in fileList)
   {
     await foundFile .FetchAttributesAsync();

     foundFile .Metadata.Add("Discovered", "true");
     await discoveredFile.SetMetadataAsync();

     var md5Hash = foundFile .Properties.ContentMD5;
}
K.Z
  • 5,201
  • 25
  • 104
  • 240

1 Answers1

1

CloudFile doesn't seem to implement those methods from any interface. So, if you really want to mock it, you will need to wrap CloudFile. See below for the basic idea. Then you can mock ICloudFile.

public interface ICloudFile
{
   Task FetchAttributesAsync();
}

public class CloudFileWrapper : ICloudFile
{
   private readonly CloudFile _impl;
   
   public Task FetchAttributesAsync() => _impl.FetchAttributesAsync();
}

Magnus
  • 353
  • 3
  • 8