Skip to content

Commit

Permalink
Add HasContent util
Browse files Browse the repository at this point in the history
  • Loading branch information
FriggaHel committed Mar 18, 2024
1 parent 419f846 commit 8a6fdd6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
13 changes: 13 additions & 0 deletions visual-dotnet/SauceLabs.Visual/Utils/StringUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Linq;
using GraphQL;

namespace SauceLabs.Visual.Utils
{
public static class StringUtils
{
public static bool HasContent(string? value)
{
return value != null && value.Trim().Length > 0;
}
}
}
2 changes: 1 addition & 1 deletion visual-dotnet/SauceLabs.Visual/VisualApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class VisualApi<T> : IDisposable where T : IHasCapabilities, IHasSessio
public VisualApi(T webdriver, Region region, string username, string accessKey, HttpClient? httpClient = null)
{

if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(accessKey))
if (!StringUtils.HasContent(username) || !StringUtils.HasContent(accessKey))
{
throw new VisualClientException(
"Invalid SauceLabs credentials. Please check your SauceLabs username and access key at https://app.saucelabs.com/user-setting");
Expand Down
6 changes: 3 additions & 3 deletions visual-dotnet/SauceLabs.Visual/VisualClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public VisualClient(WebDriver wd, Region region, CreateBuildOptions buildOptions
/// <param name="buildOptions">the options of the build creation</param>
public VisualClient(WebDriver wd, Region region, string? username, string? accessKey, CreateBuildOptions buildOptions)
{
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(accessKey))
if (!StringUtils.HasContent(username) || !StringUtils.HasContent(accessKey))
{
throw new VisualClientException("Username or Access Key not set");
}
Expand Down Expand Up @@ -155,12 +155,12 @@ private async Task<VisualBuild> FindBuildById(string buildId)
/// <returns></returns>
private async Task<VisualBuild?> GetEffectiveBuild(string? buildId, string? customId)
{
if (!string.IsNullOrEmpty(buildId))
if (StringUtils.HasContent(buildId))
{
return await FindBuildById(buildId!);
}

if (!string.IsNullOrEmpty(customId))
if (StringUtils.HasContent(customId))
{
return await TryFindBuildByCustomId(customId!);
}
Expand Down

0 comments on commit 8a6fdd6

Please sign in to comment.