[link sdk] Adjust the LinkSdkRegressionTest.SpecialFolder to handle uncertainty whether a directory exists or not on .NET. Fixes #xamarin/maccore@2379. (#10511)

The directory does not exist for me locally, but exists when running the tests on
the bots.

Fixes https://github.com/xamarin/maccore/issues/2379.
This commit is contained in:
Rolf Bjarne Kvinge 2021-01-27 17:56:43 +01:00 коммит произвёл GitHub
Родитель 2a61296464
Коммит df4388e8d1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 6 добавлений и 4 удалений

Просмотреть файл

@ -822,15 +822,17 @@ namespace LinkSdk {
#endif
}
string TestFolder (Environment.SpecialFolder folder, bool supported = true, bool exists = true, bool readOnly = false)
string TestFolder (Environment.SpecialFolder folder, bool supported = true, bool? exists = true, bool readOnly = false)
{
var path = Environment.GetFolderPath (folder);
Assert.That (path.Length > 0, Is.EqualTo (supported), folder.ToString ());
if (!supported)
return path;
Assert.That (Directory.Exists (path), Is.EqualTo (exists), path);
if (!exists)
var dirExists = Directory.Exists (path);
if (exists.HasValue)
Assert.That (dirExists, Is.EqualTo (exists), path);
if (!dirExists)
return path;
string file = Path.Combine (path, "temp.txt");
@ -954,7 +956,7 @@ namespace LinkSdk {
Assert.That (path, Is.EqualTo (docs), "path - MyDocuments");
#if NET
path = TestFolder (Environment.SpecialFolder.ApplicationData, exists: false);
path = TestFolder (Environment.SpecialFolder.ApplicationData, exists: null /* may or may not exist */);
#else
path = TestFolder (Environment.SpecialFolder.ApplicationData);
#endif