New way of reading configurations from file and deserializing
This commit is contained in:
@ -1,20 +1,39 @@
|
||||
using EATestFramework.Driver;
|
||||
using EATestFramework.Settings;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace EATestFramework.Extensions;
|
||||
public static class WebDriverInitializerExtension
|
||||
{
|
||||
public static IServiceCollection UseWebDriverInitializer(
|
||||
this IServiceCollection services,
|
||||
BrowserType browserType)
|
||||
this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton(new TestSettings
|
||||
{
|
||||
BrowserType = browserType
|
||||
});
|
||||
services.AddSingleton(ReadConfig());
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
private static TestSettings ReadConfig()
|
||||
{
|
||||
var configFile = File
|
||||
.ReadAllText(Path.GetDirectoryName(
|
||||
Assembly.GetExecutingAssembly().Location)
|
||||
+ "/appsettings.json");
|
||||
|
||||
var jsonSerializeOptions = new JsonSerializerOptions()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
jsonSerializeOptions.Converters.Add(new JsonStringEnumConverter());
|
||||
|
||||
var testSettings = JsonSerializer.Deserialize<TestSettings>(configFile, jsonSerializeOptions);
|
||||
|
||||
return testSettings;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user