Skip to content

Commit b6f5239

Browse files
author
Warren Buckley
committed
This uses CloudBlobDirectory Prefix property to return a path rather than just the folder name, so it's more inline with the Umbraco Core Physical File Provider.
So rather than returning 1001 we now return 1001/ or querying a path with subfolders we now get back forms/form_123/ an forms/form_456/ as two subfolders inside forms which we query for. Adding in tests for this change to the directories & paths. Along for querying subfolders. Tests not fully passing yet - investigating further
1 parent f575fe1 commit b6f5239

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

src/UmbracoFileSystemProviders.Azure.Tests/AzureBlobFileSystemTestsBase.cs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public void TestGetDirectories()
294294
IEnumerable<string> actual = provider.GetDirectories("/");
295295

296296
// Assert
297-
string[] expected = { "1010", "1011", "1012" };
297+
string[] expected = { "1010/", "1011/", "1012/", "forms/", "testvalid/" };
298298
Assert.IsTrue(expected.SequenceEqual(actual));
299299
}
300300

@@ -315,10 +315,10 @@ public void TestGetDirectoriesPrefixed()
315315
IEnumerable<string> actual = provider.GetDirectories("/");
316316

317317
// Assert
318-
string[] expected = { "1010", "1011", "1012" };
318+
string[] expected = { "1010/", "1011/", "1012/", "testvalid/" };
319319
Assert.IsTrue(expected.SequenceEqual(actual));
320320
}
321-
321+
322322
/// <summary>
323323
/// Asserts that the file system correctly returns a sequence of files from the root
324324
/// container in the correct format.
@@ -513,5 +513,56 @@ public void TestDeleteDirectoryRelative()
513513
Assert.IsFalse(provider.DirectoryExists("media/1010/"));
514514
Assert.IsFalse(provider.FileExists("media/1010/media.jpg"));
515515
}
516+
517+
/// <summary>
518+
/// Asserts that the file system correctly returns a sequence of sub-directories in the
519+
/// correct format.
520+
/// </summary>
521+
[Test]
522+
public void TestGetSubDirectories()
523+
{
524+
// Arrange
525+
AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();
526+
provider.AddFile("forms/form_123/kitty.jpg", Stream.Null);
527+
provider.AddFile("forms/form_123/dog.jpg", Stream.Null);
528+
provider.AddFile("forms/form_456/panda.jpg", Stream.Null);
529+
530+
// Act
531+
IEnumerable<string> actual = provider.GetDirectories("forms");
532+
533+
// Assert
534+
string[] expected = { "forms/form_123/", "forms/form_456/" };
535+
Assert.IsTrue(expected.SequenceEqual(actual));
536+
}
537+
538+
/// <summary>
539+
/// Asserts that the file system correctly returns a sequence of sub-directories in the
540+
/// correct format.
541+
/// </summary>
542+
[Test]
543+
public void TestGetSubDirectoriesAndFiles()
544+
{
545+
// Arrange
546+
AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();
547+
provider.AddFile("forms/form_123/kitty.jpg", Stream.Null);
548+
provider.AddFile("forms/form_123/dog.jpg", Stream.Null);
549+
provider.AddFile("forms/form_456/panda.jpg", Stream.Null);
550+
551+
// Act
552+
var subfolders = provider.GetDirectories("forms");
553+
var actual = new List<string>();
554+
555+
foreach (var folder in subfolders)
556+
{
557+
// Get files in subfolder and add to a single collection
558+
actual.AddRange(provider.GetFiles(folder));
559+
}
560+
561+
// Assert
562+
string[] expected = { "forms/form_123/kitty.jpg", "forms/form_123/dog.jpg", "forms/form_456/panda.jpg" };
563+
Assert.IsTrue(expected.SequenceEqual(actual));
564+
}
565+
566+
516567
}
517568
}

src/UmbracoFileSystemProviders.Azure/AzureFileSystem.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,10 @@ public IEnumerable<string> GetDirectories(string path)
388388
{
389389
CloudBlobDirectory directory = this.GetDirectoryReference(path);
390390

391-
IEnumerable<IListBlobItem> blobs = directory.ListBlobs().Where(blob => blob is CloudBlobDirectory);
391+
IEnumerable<IListBlobItem> blobs = directory.ListBlobs().Where(blob => blob is CloudBlobDirectory).ToList();
392392

393393
// Always get last segment for media sub folder simulation. E.g 1001, 1002
394-
return blobs.Select(cd =>
395-
cd.Uri.Segments[cd.Uri.Segments.Length - 1].Split(Delimiter.ToCharArray())[0]);
396-
394+
return blobs.Cast<CloudBlobDirectory>().Select(cd => cd.Prefix);
397395
}
398396

399397
/// <summary>

0 commit comments

Comments
 (0)