Skip to content

Commit

Permalink
TMS-432: Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Komissarov committed Apr 25, 2024
1 parent bdccdd3 commit 61e518e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Tms.Adapter.Core/Configurator/Configurator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Configuration;
using System.Text.Json;

namespace Tms.Adapter.Core.Configurator;
Expand Down Expand Up @@ -44,8 +45,10 @@ public static TmsSettings GetConfig()
Console.WriteLine($"Configuration file was not found at {defaultJsonConfigPath}");
}

ApplyEnv(config);
Validate(config);

return ApplyEnv(config);
return config;
}

private static string GetConfigFileName()
Expand Down Expand Up @@ -106,4 +109,37 @@ private static TmsSettings ApplyEnv(TmsSettings settings)

return settings;
}

private static void Validate(TmsSettings settings)
{

if (!Uri.IsWellFormedUriString(settings.Url, UriKind.Absolute))
{
throw new ConfigurationErrorsException("Url is invalid");
}

if (string.IsNullOrWhiteSpace(settings.PrivateToken))
{
throw new ConfigurationErrorsException("Private token is invalid");
}

if (!Guid.TryParse(settings.ProjectId, out var _))
{
throw new ConfigurationErrorsException("Project id is invalid");
}

if (!Guid.TryParse(settings.ConfigurationId, out var _))
{
throw new ConfigurationErrorsException("Configuration id is invalid");
}

if (!string.IsNullOrWhiteSpace(settings.TestRunId))
{
if (!Guid.TryParse(settings.TestRunId, out var _))
{
throw new ConfigurationErrorsException(
"Config contains not valid test run id.");
}
}
}
}
1 change: 1 addition & 0 deletions Tms.Adapter.Core/Tms.Adapter.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="TestIt.ApiClient" Version="2.6.0" />
</ItemGroup>
Expand Down

0 comments on commit 61e518e

Please sign in to comment.