Hi,
Want to unit test below code:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("connString");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("containerName");
CloudBlockBlob cloudBlobInstance = container.GetBlockBlobReference(container, "imageName");
cloudBlobInstance.UploadFromByteArrayAsync(ImageBytes, 0, ImageByt
and to do this I move below code to a wrapper like:
public class AzureServiceWrapper : IAzureServiceWrapper
{
public CloudStorageAccount GetCloudStorageAccount(string connString)
{
CloudStorageAccount cloudStorageAccountClient = CloudStorageAccount.Parse(connString);
return cloudStorageAccountClient;
}
public CloudBlockBlob GetBlockBlobReference(CloudBlobContainer storageContainer, string fileName)
{
return storageContainer.GetBlockBlobReference(fileName);
}
public CloudBlobClient GetBlobClient(CloudStorageAccount cloudStorageAccountClient)
{
CloudBlobClient cloudBlobClient = cloudStorageAccountClient.CreateCloudBlobClient();
return cloudBlobClient;
}
public CloudBlobContainer GetBlobContainer(CloudBlobClient cloudBlobClient, string containerName)
{ CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
return cloudBlobContainer;
}
}
}
And then using this interface I can Inject it and modify my repo code like:
CloudStorageAccount cloudStorageAccountClient = _azureSeriveWrapper.GetStorageAccount("connString");
CloudBlobClient cloudBlobClient = _azureSeriveWrapper.GetBlobClient(cloudStorageAccountClient);
CloudBlobContainer cloudBlobContainer= _azureSeriveWrapper.GetBlobContainer(cloudBlobClient,"containerName");
CloudBlockBlob cloudBlobInstance = _azureSeriveWrapper.GetBlockBlobReference(cloudBlobContainer, AssetImageName);
cloudBlobInstance.UploadFromByteArrayAsync(ImageBytes, 0, ImageBytes.Length);
mediaUrl = cloudBlobInstance.Uri.AbsoluteUri;
But how to mock this in unit test method if above is correct or please help me with the sample code for the same.
Thanks in advance,