Skip to content

Commit 45933c2

Browse files
committed
Replace 'App.config' with 'appsettings.json'
1 parent d0fea6e commit 45933c2

File tree

6 files changed

+36
-30
lines changed

6 files changed

+36
-30
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ jobs:
3131
with:
3232
dotnet-version: ${{ matrix.dotnet-version }}
3333

34-
- name: Find And Replace Values (App Config)
34+
- name: Find And Replace Values (App Settings)
3535
uses: abhinavminhas/replace-tokens@main
3636
with:
37-
files: '${{ github.workspace }}/QueryDB.Core.Tests/App.config'
37+
files: '${{ github.workspace }}/QueryDB.Core.Tests/appsettings.json'
3838
replacements: '__DB_PASSWORD__=${{ secrets.DB_PASSWORD }},__DB_PASSWORD__=${{ secrets.DB_PASSWORD }},__DB_PASSWORD__=${{ secrets.DB_PASSWORD }},__DB_PASSWORD__=${{ secrets.DB_PASSWORD }}'
3939

4040
- name: Build
@@ -86,10 +86,10 @@ jobs:
8686
with:
8787
dotnet-version: ${{ matrix.dotnet-version }}
8888

89-
- name: Find And Replace Values (App Config)
89+
- name: Find And Replace Values (App Settings)
9090
uses: abhinavminhas/replace-tokens@main
9191
with:
92-
files: '${{ github.workspace }}/QueryDB.Core.Tests/App.config'
92+
files: '${{ github.workspace }}/QueryDB.Core.Tests/appsettings.json'
9393
replacements: '__DB_PASSWORD__=${{ secrets.DB_PASSWORD }},__DB_PASSWORD__=${{ secrets.DB_PASSWORD }},__DB_PASSWORD__=${{ secrets.DB_PASSWORD }},__DB_PASSWORD__=${{ secrets.DB_PASSWORD }}'
9494

9595
- name: Build

.github/workflows/coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
with:
2323
dotnet-version: ${{ matrix.dotnet-version }}
2424

25-
- name: Find And Replace Values (App Config)
25+
- name: Find And Replace Values (App Settings)
2626
uses: abhinavminhas/replace-tokens@main
2727
with:
28-
files: '${{ github.workspace }}/QueryDB.Core.Tests/App.config'
28+
files: '${{ github.workspace }}/QueryDB.Core.Tests/appsettings.json'
2929
replacements: '__DB_PASSWORD__=${{ secrets.DB_PASSWORD }},__DB_PASSWORD__=${{ secrets.DB_PASSWORD }},__DB_PASSWORD__=${{ secrets.DB_PASSWORD }},__DB_PASSWORD__=${{ secrets.DB_PASSWORD }}'
3030

3131
- name: Build

QueryDB.Core.Tests/App.config

Lines changed: 0 additions & 9 deletions
This file was deleted.

QueryDB.Core.Tests/QueryDB.Core.Tests.csproj

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,23 @@
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1313
</PackageReference>
14+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
1415
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
1516
<PackageReference Include="MSTest.TestAdapter" Version="3.8.0" />
1617
<PackageReference Include="MSTest.TestFramework" Version="3.8.0" />
17-
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
1818
</ItemGroup>
1919

2020
<ItemGroup>
2121
<ProjectReference Include="..\QueryDB\QueryDB.csproj" />
2222
</ItemGroup>
2323

2424
<ItemGroup>
25+
<None Update="appsettings.json">
26+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
27+
</None>
2528
<None Update="SeedData\oracle.sql">
2629
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2730
</None>
2831
</ItemGroup>
2932

30-
<!-- Creates and copies required App.config to output folder. -->
31-
<Target Name="CopyAppConfig" AfterTargets="Build" DependsOnTargets="Build">
32-
<CreateItem Include="$(OutputPath)$(AssemblyName).dll.config">
33-
<Output TaskParameter="Include" ItemName="FilesToCopy" />
34-
</CreateItem>
35-
<Copy SourceFiles="@(FilesToCopy)" DestinationFiles="$(OutputPath)testhost.dll.config" />
36-
</Target>
37-
3833
</Project>

QueryDB.Core.Tests/TestBase.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
using System;
2-
using System.Configuration;
1+
using Microsoft.Extensions.Configuration;
2+
using System;
33
using System.Globalization;
44
using System.IO;
55

66
namespace QueryDB.Core.Tests
77
{
88
public class TestBase
99
{
10-
protected readonly string MSSQLConnectionString = ConfigurationManager.AppSettings["MSSQLConnection"];
11-
protected readonly string MySQLConnectionString = ConfigurationManager.AppSettings["MySQLConnection"];
12-
protected readonly string OracleConnectionString = ConfigurationManager.AppSettings["OracleConnection"];
13-
protected readonly string PostgreSQLConnectionString = ConfigurationManager.AppSettings["PostgreSQLConnection"];
10+
private readonly IConfiguration _configuration;
11+
protected readonly string MSSQLConnectionString;
12+
protected readonly string MySQLConnectionString;
13+
protected readonly string OracleConnectionString;
14+
protected readonly string PostgreSQLConnectionString;
1415
protected const string DB_TESTS = "DB-TESTS";
1516
protected const string SMOKE_TESTS = "SMOKE-TESTS";
1617
protected const string MSSQL_TESTS = "MSSQL-TESTS";
@@ -20,6 +21,19 @@ public class TestBase
2021
protected const string QUERY_DB_EXCEPTION_TESTS = "QUERY-DB-EXCEPTION-TESTS";
2122
protected const string UNKNOW_DB_TESTS = "UNKNOW-DB-TESTS";
2223

24+
public TestBase()
25+
{
26+
_configuration = new ConfigurationBuilder()
27+
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
28+
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
29+
.Build();
30+
31+
MSSQLConnectionString = _configuration["MSSQLConnection"];
32+
MySQLConnectionString = _configuration["MySQLConnection"];
33+
OracleConnectionString = _configuration["OracleConnection"];
34+
PostgreSQLConnectionString = _configuration["PostgreSQLConnection"];
35+
}
36+
2337
protected string ConvertToUTCInUSFormat(string dateString)
2438
{
2539
DateTimeOffset date;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"MSSQLConnection": "Data Source=(local);Initial Catalog=master;User Id=SA;Password=__DB_PASSWORD__;Encrypt=False;",
3+
"MySQLConnection": "server=localhost;database=mysql;uid=root;pwd=__DB_PASSWORD__",
4+
"OracleConnection": "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SID = XE))); User Id = sys;Password=__DB_PASSWORD__;DBA Privilege=SYSDBA",
5+
"PostgreSQLConnection": "Host=localhost;Port=5432;Database=postgres;Username=sys;Password=__DB_PASSWORD__;"
6+
}

0 commit comments

Comments
 (0)