Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlm committed Nov 25, 2024
2 parents 3672beb + 2024c0e commit da46975
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Task<IStorageFolder> TryGetWellKnownFolderAsync(WellKnownFolder wellKnown
WellKnownFolder.Videos => Environment.GetFolderPath(Environment.SpecialFolder.MyVideos),
_ => null
};
if (dir == null)
if (String.IsNullOrEmpty(dir))
return Task.FromResult<IStorageFolder>(null);
return Task.FromResult<IStorageFolder>(new SystemStorageFolder(dir));
}
Expand Down
24 changes: 15 additions & 9 deletions src/Tests/Consolonia.Core.Tests/StorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,39 @@ public async Task TestWellKnownFolder()
{
var storageProvider = new ConsoloniaStorageProvider();
var folder = await storageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Pictures);
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), folder.Path.LocalPath);
if (folder != null)
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), folder.Path.LocalPath);

folder = await storageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Documents);
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), folder.Path.LocalPath);
if (folder != null)
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), folder.Path.LocalPath);

folder = await storageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Music);
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), folder.Path.LocalPath);
if (folder != null)
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), folder.Path.LocalPath);

folder = await storageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Videos);
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), folder.Path.LocalPath);
if (folder != null)
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), folder.Path.LocalPath);

folder = await storageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Downloads);
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), folder.Path.LocalPath);
if (folder != null)
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), folder.Path.LocalPath);

folder = await storageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Desktop);
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), folder.Path.LocalPath);
if (folder != null)
Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), folder.Path.LocalPath);
}


[Test]
public async Task TestFolderSemantics()
{
var storageProvider = new ConsoloniaStorageProvider();
var tempPath = Path.GetTempPath();
var tempPath = Path.GetTempPath();
var tempFolder = await storageProvider.TryGetFolderFromPathAsync(new Uri($"file://{tempPath}"));
var testPath = Path.Combine(tempPath, nameof(TestFolderSemantics))!;
var testFolder = await tempFolder.CreateFolderAsync(nameof(TestFolderSemantics));
var testFolder = await tempFolder.CreateFolderAsync(nameof(TestFolderSemantics));

Assert.IsNotNull(testFolder);
Assert.AreEqual(testPath, testFolder.Path.LocalPath);
Expand All @@ -126,7 +132,7 @@ public async Task TestFolderSemantics()

var props = await testFolder.GetBasicPropertiesAsync();
Assert.AreEqual((DateTimeOffset)Directory.GetCreationTime(testPath), props.DateCreated);
Assert.AreEqual((DateTimeOffset)Directory.GetLastWriteTime(testPath), props.DateModified);
Assert.AreEqual(((DateTimeOffset)Directory.GetLastWriteTime(testPath)).ToString(), props.DateModified.ToString());

Check failure on line 135 in src/Tests/Consolonia.Core.Tests/StorageTests.cs

View workflow job for this annotation

GitHub Actions / build

The behavior of 'DateTimeOffset.ToString()' could vary based on the current user's locale settings. Replace this call in 'StorageTests.TestFolderSemantics()' with a call to 'DateTimeOffset.ToString(IFormatProvider)'.

Check failure on line 135 in src/Tests/Consolonia.Core.Tests/StorageTests.cs

View workflow job for this annotation

GitHub Actions / build

The behavior of 'DateTimeOffset.ToString()' could vary based on the current user's locale settings. Replace this call in 'StorageTests.TestFolderSemantics()' with a call to 'DateTimeOffset.ToString(IFormatProvider)'.

await file.DeleteAsync();
Assert.IsFalse(File.Exists(file.Path.LocalPath));
Expand Down

0 comments on commit da46975

Please sign in to comment.