I am trying to test an activity function which has the following definition:
[FunctionName(nameof(LoadReferenceFromBlobStorage))]
public static async Task<string> Run([ActivityTrigger] string blobName,
IBinder binder,
ILogger log)
{
StorageAccountAttribute storageAccountAtt = new StorageAccountAttribute("AzureWebJobsStorage");
CloudStorageAccount storageAccount = await binder.BindAsync<CloudStorageAccount>(storageAccountAtt, CancellationToken.None);
CloudBlobClient client = storageAccount.CreateCloudBlobClient();
//...
}
I mock the IBinder
in the unit test as:
[TestMethod]
public async Task GetReference()
{
var attribute = new StorageAccountAttribute("UseDevelopmentStorage=true;");
var mock = new Mock<IBinder>();
CloudStorageAccount mockedResult = null;
CloudStorageAccount.TryParse("UseDevelopmentStorage=true;", out mockedResult);
mock.Setup(x => x.BindAsync<CloudStorageAccount>(attribute, CancellationToken.None))
.ReturnsAsync(mockedResult);
ILogger logger = NullLoggerFactory.Instance.CreateLogger("log");
var res = await LoadReferenceFromBlobStorage.Run("name", mock.Object, logger);
//...
}
The test calls the activity successfully but the result of binder.BindAsync
is always null.
Am I missing something?