Reputation: 439
I am currently involved in upgrading from Azure 1.7 to 2.2 and am encountering breaking changes with Storage. All the storage calls in the libraries are covered by Unit Tests and I've ironed out most of the changes.
I am completely stuck on one of our core methods which gets a list of subdirectories in a directory. I know they are not actual directories, but parts of blob names, but the functionality existed before 2.0 and we make heavy use of it across nearly 30 different services.
The storage blob address is testdata/test/test1/blob.txt
And the test
/// Unit Test
[Test]
public void BuildDirectoryAndRetrieveUsingSubDirectory()
{
CloudBlobDirectory subDirectory = GetBlobDirectory("testdata/test/");
IEnumerable<CloudBlobDirectory> dirs =
subDirectory.ListBlobs().OfType<CloudBlobDirectory>();
Assert.AreEqual(1, dirs.Count());
}
The old 1.7 code for GetBlobDirectory returned a list of every directory blob in testdata/test/, so in this case would return test1
/// Azure Storage 1.7
public static CloudBlobDirectory GetBlobDirectory(string directoryReference)
{
return BlobClient.GetBlobDirectoryReference(directoryReference);
}
I have tried in vain to get the same results from using 2.0
/// Azure Storage 2.0
public static CloudBlobDirectory GetBlobDirectory(string directoryReference)
{
string containerName = GetContainerNameFromDirectoryName(directoryReference);
CloudBlobContainer container = BlobClient.GetContainerReference(containerName);
return container.GetBlobDirectoryReference(directoryReference);
}
However back in the test the dirs just returns "the enumeration yielded no results".
Can anyone help - I want very much to leave the test code alone, but return the same results from the method.
Thanks
Upvotes: 0
Views: 320
Reputation: 439
Found the answer, which was surprisingly simple.
In StorageClient 1.7, the prefix value that you passed in included the container name and had to end with a "/".
So basically the containerName becomes "testdata" and the directoryPrefix becomes "test".
In the latest version the prefix value is anything not including the container name, so the function has changed to be
public static CloudBlobDirectory GetBlobDirectory(string directoryReference)
{
string containerName = GetContainerNameFromDirectoryName(directoryReference);
string directoryPrefix = GetPrefixFormDirectoryName(directoryReference);
CloudBlobContainer container = BlobClient.GetContainerReference(containerName);
var blobs = container.ListBlobs(directoryPrefix, false);
return (CloudBlobDirectory)blobs.Where(b => b as CloudBlobDirectory !=null).First();
}
Upvotes: 2