Files
speckle-sharp-sdk/tests/Speckle.Sdk.Tests.Unit/Helpers/Path.cs
T
Adam Hathcock 14d959834f Convert to Xunit (#196)
* xunit unit tests

* most pass with formatting

* convert objects to xunit

* remove nunit

* format

* merge fixes

* switch objects to fluent assertions

* update to fluent assertions

* more FA

* convert all to FA

* Format

* Fix tests

* formatting

* hopefully made credential test better

* Catch more specific exception

* use another more specific exception

* Fix tests

* update to xunit

* update packages
2025-01-09 15:32:28 +00:00

83 lines
2.0 KiB
C#

using System.Runtime.InteropServices;
using FluentAssertions;
using Speckle.Sdk.Logging;
using Xunit;
namespace Speckle.Sdk.Tests.Unit.Helpers;
public class SpecklePathTests
{
[Fact]
public void TestUserApplicationDataPath()
{
var userPath = SpecklePathProvider.UserApplicationDataPath();
string pattern;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
pattern = @"C:\\Users\\.*\\AppData\\Roaming";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
pattern = @"\/Users\/.*\/\.config";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// if running under root user, the .config folder is in another location...
if (userPath.StartsWith("/root"))
{
pattern = @"\/root/\.config";
}
else
{
pattern = @"\/home/.*/\.config";
}
}
else
{
throw new NotImplementedException("Your OS platform is not supported");
}
userPath.Should().MatchRegex(pattern);
}
[Fact]
public void TestInstallApplicationDataPath()
{
var installPath = SpecklePathProvider.InstallApplicationDataPath;
string pattern;
if (string.IsNullOrEmpty(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)))
{
pattern = @"\/root";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// this will prob fail on windows
pattern = @"C:\\Users\\.*\\AppData\\Roaming";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
pattern = @"\/Users\/.*\/\.config";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// if running under root user, the .config folder is in another location...
if (installPath.StartsWith("/root"))
{
pattern = @"\/root/\.config";
}
else
{
pattern = @"\/home/.*/\.config";
}
}
else
{
throw new NotImplementedException("Your OS platform is not supported");
}
installPath.Should().MatchRegex(pattern);
}
}