From 5325ee397a2c82c1835fde44f980485292547f92 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 29 Dec 2023 16:08:25 +0500 Subject: [PATCH] IntegrationTests move connection string to appsettings.json --- .../WebAppFactoryFixture.cs | 13 ++++++++----- AsbCloudWebApi/appsettings.json | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/AsbCloudWebApi.IntegrationTests/WebAppFactoryFixture.cs b/AsbCloudWebApi.IntegrationTests/WebAppFactoryFixture.cs index a6116e5d..a3f578ac 100644 --- a/AsbCloudWebApi.IntegrationTests/WebAppFactoryFixture.cs +++ b/AsbCloudWebApi.IntegrationTests/WebAppFactoryFixture.cs @@ -4,6 +4,7 @@ using AsbCloudWebApi.IntegrationTests.TestFakers; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Xunit; @@ -12,12 +13,14 @@ namespace AsbCloudWebApi.IntegrationTests; public class WebAppFactoryFixture : WebApplicationFactory, IAsyncLifetime { - private const string connectionString = - "Host=localhost;Database=test;Port=5433;Username=postgres;Password=root;Persist Security Info=True;Include Error Detail=True;"; - - protected override void ConfigureWebHost(IWebHostBuilder builder) + protected override void ConfigureWebHost(IWebHostBuilder builder) { - builder.ConfigureServices(services => + var configuration = new ConfigurationBuilder() + .AddJsonFile("appsettings.json") + .Build(); + var connectionString = configuration.GetConnectionString("TestConnection"); + + builder.ConfigureServices(services => { var descriptor = services.FirstOrDefault(d => d.ServiceType == typeof(DbContextOptions)); diff --git a/AsbCloudWebApi/appsettings.json b/AsbCloudWebApi/appsettings.json index 6801ff38..96a3f3bf 100644 --- a/AsbCloudWebApi/appsettings.json +++ b/AsbCloudWebApi/appsettings.json @@ -9,7 +9,7 @@ "ConnectionStrings": { "DefaultConnection": "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True", "DebugConnection": "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True;Include Error Detail=True", - "ServerConnection": "Host=192.168.1.70;Database=postgres;Username=postgres;Password=q;Persist Security Info=True", + "TestConnection": "Host=localhost;Database=test;Username=postgres;Password=q;Persist Security Info=True;Include Error Detail=True", "LocalConnection": "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True" }, "AllowedHosts": "*",