Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config refactoring #52

Merged
2 commits merged into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions Tms.Adapter.Core/Configurator/Configurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public static class Configurator
private const string TmsAutomaticCreationTestCases = "TMS_AUTOMATIC_CREATION_TEST_CASES";
private const string TmsCertValidation = "TMS_CERT_VALIDATION";
private const string ConfigFile = "TMS_CONFIG_FILE";

private static readonly JsonSerializerOptions SerializerOptions = new() { PropertyNameCaseInsensitive = true };

public static TmsSettings GetConfig()
{
var config = new TmsSettings
Expand All @@ -28,12 +29,7 @@ public static TmsSettings GetConfig()

if (File.Exists(defaultJsonConfigPath))
{
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};

var fileConfig = JsonSerializer.Deserialize<TmsSettings>(File.ReadAllText(defaultJsonConfigPath), options);
var fileConfig = JsonSerializer.Deserialize<TmsSettings>(File.ReadAllText(defaultJsonConfigPath), SerializerOptions);

if (fileConfig != null)
{
Expand All @@ -58,10 +54,10 @@ private static string GetConfigFileName()
return envConfigFileName ?? DefaultFileName;
}

private static TmsSettings ApplyEnv(TmsSettings settings)
private static void ApplyEnv(TmsSettings settings)
{
var url = Environment.GetEnvironmentVariable(TmsUrl);
if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
if (!string.IsNullOrWhiteSpace(url) && Uri.IsWellFormedUriString(url, UriKind.Absolute))
{
settings.Url = url;
}
Expand All @@ -73,19 +69,19 @@ private static TmsSettings ApplyEnv(TmsSettings settings)
}

var projectId = Environment.GetEnvironmentVariable(TmsProjectId);
if (Guid.TryParse(projectId, out var _))
if (!string.IsNullOrWhiteSpace(projectId) && Guid.TryParse(projectId, out _))
{
settings.ProjectId = projectId;
}

var configurationId = Environment.GetEnvironmentVariable(TmsConfigurationId);
if (Guid.TryParse(configurationId, out var _))
if (!string.IsNullOrWhiteSpace(configurationId) && Guid.TryParse(configurationId, out _))
{
settings.ConfigurationId = configurationId;
}

var testRunId = Environment.GetEnvironmentVariable(TmsTestRunId);
if (Guid.TryParse(testRunId, out var _))
if (!string.IsNullOrWhiteSpace(testRunId) && Guid.TryParse(testRunId, out _))
{
settings.TestRunId = testRunId;
}
Expand All @@ -106,8 +102,6 @@ private static TmsSettings ApplyEnv(TmsSettings settings)
{
settings.CertValidation = false;
}

return settings;
}

private static void Validate(TmsSettings settings)
Expand All @@ -123,23 +117,25 @@ private static void Validate(TmsSettings settings)
throw new ConfigurationErrorsException("Private token is invalid");
}

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

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

if (!string.IsNullOrWhiteSpace(settings.TestRunId))
if (string.IsNullOrWhiteSpace(settings.TestRunId))
{
if (!Guid.TryParse(settings.TestRunId, out var _))
{
throw new ConfigurationErrorsException(
"Config contains not valid test run id.");
}
return;
}

if (!Guid.TryParse(settings.TestRunId, out _))
{
throw new ConfigurationErrorsException(
"Config contains not valid test run id.");
}
}
}
1 change: 0 additions & 1 deletion Tms.Adapter.Core/Models/FixtureResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ namespace Tms.Adapter.Core.Models;

public class FixtureResult : ExecutableItem
{

}
1 change: 0 additions & 1 deletion Tms.Adapter.Core/Models/StepResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ namespace Tms.Adapter.Core.Models;

public class StepResult: ExecutableItem
{

}
4 changes: 4 additions & 0 deletions Tms.Adapter.CoreTests/Tms.Adapter.CoreTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@
<ProjectReference Include="..\Tms.Adapter.Core\Tms.Adapter.Core.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion Tms.Adapter.CoreTests/Usings.cs

This file was deleted.

15 changes: 7 additions & 8 deletions Tms.Adapter.SpecFlowPlugin/LinkItem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace Tms.Adapter.SpecFlowPlugin
namespace Tms.Adapter.SpecFlowPlugin;

internal class LinkItem
{
internal class LinkItem
{
public string? Title { get; set; }
public string Url { get; set; }
public string? Description { get; set; }
public string? Type { get; set; }
}
public string? Title { get; set; }
public string Url { get; set; }
public string? Description { get; set; }
public string? Type { get; set; }
}
Loading
Loading