Adds LightBDD

This commit is contained in:
Janus Knudsen 2025-02-27 17:24:58 +01:00
parent 099f6467d2
commit 104187fcac
16 changed files with 344 additions and 158 deletions

View file

@ -81,35 +81,10 @@ namespace PlanTempus.Database.Core.DCL
private void GrantSchemaRights(IDbConnection db) private void GrantSchemaRights(IDbConnection db)
{ {
// Grant USAGE og alle CREATE rettigheder på schema niveau
//GRANT USAGE ON SCHEMA {_command.Schema} TO {_command.User};
var sql = $@"GRANT CREATE ON SCHEMA {_command.Schema} TO {_command.User};"; var sql = $@"GRANT CREATE ON SCHEMA {_command.Schema} TO {_command.User};";
db.ExecuteSql(sql); db.ExecuteSql(sql);
// Grant rettigheder på eksisterende og fremtidige tabeller }
//var sql1 = $"GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA {_command.Schema} TO {_command.User};";
//ExecuteSql(sql1);
//var sql2 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} GRANT ALL PRIVILEGES ON TABLES TO {_command.User};";
//ExecuteSql(sql2);
//// Grant sequence rettigheder
//var sql3 = $"GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA {_command.Schema} TO {_command.User};";
//ExecuteSql(sql3);
//// Grant execute på functions
//var sql4 = $"GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA {_command.Schema} TO {_command.User};";
//ExecuteSql(sql4);
//// Grant for fremtidige functions
//var sql5 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} GRANT EXECUTE ON FUNCTIONS TO {_command.User};";
//ExecuteSql(sql5);
//// Grant for fremtidige sequences
//var sql6 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} GRANT USAGE ON SEQUENCES TO {_command.User};";
//ExecuteSql(sql6);
}
} }
} }

View file

@ -0,0 +1,73 @@
using LightBDD.Framework;
using LightBDD.Framework.Scenarios;
using LightBDD.MsTest3;
using Shouldly;
namespace PlanTempus.X.BDD.FeatureFixtures;
[TestClass]
public partial class UserRegistrationSpecs : FeatureFixture
{
//private CalculatorContext _context;
public UserRegistrationSpecs()
{
//_context = new CalculatorContext();
}
//[Scenario]
//[TestMethod]
//public void Successful_user_registration_with_valid_email()
//{
// // Runner.RunScenario(
// // _ => Given_no_user_exists_with_email("test@example.com")
// //);
// //await Runner.RunScenarioAsync(
// // _ => Given_no_user_exists_with_email("test@example.com"),
// // _ => When_I_submit_registration_with_name_and_email("Test User", "test@example.com"),
// // _ => Then_a_new_user_should_be_created_with_email_and_confirmation_status("test@example.com", false),
// // _ => Then_a_confirmation_email_should_be_sent()
// //);
//}
protected async Task Given_no_user_exists_with_email(string email)
{
await Task.Run(() =>
{
});
//Assert.IsFalse(await _context.UserExistsAsync(email), $"User with email {email} should not exist");
true.ShouldBe(true);
}
protected async Task When_I_submit_registration_with_name_and_email(string name, string email)
{
//await _context.RegisterUserAsync(name, email);
await Task.Run(() =>
{
});
true.ShouldBe(true);
}
protected async Task Then_a_new_user_should_be_created_with_email_and_confirmation_status(string email, bool emailConfirmed)
{
//var user = await _context.GetUserByEmailAsync(email);
//Assert.IsNotNull(user);
//Assert.AreEqual(email, user.Email);
//Assert.AreEqual(emailConfirmed, user.EmailConfirmed);
await Task.Run(() =>
{
});
true.ShouldBe(true);
}
protected async Task Then_a_confirmation_email_should_be_sent()
{
//Assert.IsTrue(await _context.WasConfirmationEmailSentAsync(), "Confirmation email should be sent");
await Task.Run(() =>
{
});
true.ShouldBe(true);
}
}

View file

@ -0,0 +1,29 @@
using LightBDD.Core.Configuration;
using LightBDD.Framework.Configuration;
using LightBDD.Framework.Reporting.Formatters;
using LightBDD.MsTest3;
namespace PlanTempus.X.BDD
{
[TestClass]
public class LightBddIntegration
{
[AssemblyInitialize]
public static void Setup(TestContext testContext) { LightBddScope.Initialize(OnConfigure); }
[AssemblyCleanup]
public static void Cleanup() { LightBddScope.Cleanup(); }
/// <summary>
/// This method allows to customize LightBDD behavior.
/// The code below configures LightBDD to produce also a plain text report after all tests are done.
/// More information on what can be customized can be found on wiki: https://github.com/LightBDD/LightBDD/wiki/LightBDD-Configuration#configurable-lightbdd-features
/// </summary>
private static void OnConfigure(LightBddConfiguration configuration)
{
configuration
.ReportWritersConfiguration()
.AddFileWriter<HtmlReportFormatter>("~\\Reports\\FeaturesReport.html");
}
}
}

View file

@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="LightBDD.Core" Version="3.10.0" />
<PackageReference Include="LightBDD.MSTest3" Version="3.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="moq" Version="4.20.72" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="Shouldly" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Application\PlanTempus.Application.csproj" />
<ProjectReference Include="..\Database\PlanTempus.Database.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
<ItemGroup>
<None Update="appconfiguration.dev.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ConfigurationTests\appconfiguration.dev.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ConfigurationTests\appconfiguration.dev.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View file

@ -0,0 +1,21 @@
using LightBDD.Framework;
using LightBDD.Framework.Scenarios;
using LightBDD.MsTest3;
namespace PlanTempus.X.BDD.Scenarios;
[TestClass]
public partial class UserRegistrationSpecs : FeatureFixtures.UserRegistrationSpecs
{
[Scenario]
[TestMethod]
public async Task Successful_user_registration_with_valid_email()
{
await Runner.RunScenarioAsync(
_ => Given_no_user_exists_with_email("test@example.com"),
_ => When_I_submit_registration_with_name_and_email("Test User", "test@example.com"),
_ => Then_a_new_user_should_be_created_with_email_and_confirmation_status("test@example.com", false),
_ => Then_a_confirmation_email_should_be_sent()
);
}
}

View file

@ -4,7 +4,7 @@ VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.Core", "Core\PlanTempus.Core.csproj", "{7B554252-1CE4-44BD-B108-B0BDCCB24742}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.Core", "Core\PlanTempus.Core.csproj", "{7B554252-1CE4-44BD-B108-B0BDCCB24742}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.Tests", "Tests\PlanTempus.Tests.csproj", "{85614050-CFB0-4E39-81D3-7D99946449D9}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.X.TDD", "Tests\PlanTempus.X.TDD.csproj", "{85614050-CFB0-4E39-81D3-7D99946449D9}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.Application", "Application\PlanTempus.Application.csproj", "{111CE8AE-E637-4376-A5A3-88D33E77EA88}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.Application", "Application\PlanTempus.Application.csproj", "{111CE8AE-E637-4376-A5A3-88D33E77EA88}"
EndProject EndProject
@ -12,6 +12,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.Database", "Data
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.SetupInfrastructure", "SetupInfrastructure\PlanTempus.SetupInfrastructure.csproj", "{48300227-BCBB-45A3-8359-9064DA85B1F9}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.SetupInfrastructure", "SetupInfrastructure\PlanTempus.SetupInfrastructure.csproj", "{48300227-BCBB-45A3-8359-9064DA85B1F9}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlanTempus.X.BDD", "PlanTempus.X.BDD\PlanTempus.X.BDD.csproj", "{8CA2246B-7D8C-40DA-9042-CA17A7A7672B}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -30,6 +32,10 @@ Global
{111CE8AE-E637-4376-A5A3-88D33E77EA88}.Debug|Any CPU.Build.0 = Debug|Any CPU {111CE8AE-E637-4376-A5A3-88D33E77EA88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{111CE8AE-E637-4376-A5A3-88D33E77EA88}.Release|Any CPU.ActiveCfg = Release|Any CPU {111CE8AE-E637-4376-A5A3-88D33E77EA88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{111CE8AE-E637-4376-A5A3-88D33E77EA88}.Release|Any CPU.Build.0 = Release|Any CPU {111CE8AE-E637-4376-A5A3-88D33E77EA88}.Release|Any CPU.Build.0 = Release|Any CPU
{8CA2246B-7D8C-40DA-9042-CA17A7A7672B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8CA2246B-7D8C-40DA-9042-CA17A7A7672B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CA2246B-7D8C-40DA-9042-CA17A7A7672B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CA2246B-7D8C-40DA-9042-CA17A7A7672B}.Release|Any CPU.Build.0 = Release|Any CPU
{D5096A7F-E6D4-4C87-874E-2D9A6BEAD57F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D5096A7F-E6D4-4C87-874E-2D9A6BEAD57F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5096A7F-E6D4-4C87-874E-2D9A6BEAD57F}.Debug|Any CPU.Build.0 = Debug|Any CPU {D5096A7F-E6D4-4C87-874E-2D9A6BEAD57F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5096A7F-E6D4-4C87-874E-2D9A6BEAD57F}.Release|Any CPU.ActiveCfg = Release|Any CPU {D5096A7F-E6D4-4C87-874E-2D9A6BEAD57F}.Release|Any CPU.ActiveCfg = Release|Any CPU

View file

@ -33,9 +33,40 @@
"postgresql.dd.tag.string": "false" "postgresql.dd.tag.string": "false"
}, },
"auth-model": "native" "auth-model": "native"
}
}, },
"custom-properties": { "postgres-jdbc-195383ce5c3-68a4eee43daef302": {
"SQLEditor.outputPanel.autoShow": "false" "provider": "postgresql",
"driver": "postgres-jdbc",
"name": "UB-KK01-postgres 1",
"save-password": true,
"configuration": {
"host": "192.168.1.57",
"port": "5432",
"database": "ptmain",
"url": "jdbc:postgresql://192.168.1.57:5432/ptmain",
"configurationType": "MANUAL",
"home": "postgresql_client",
"type": "dev",
"closeIdleConnection": true,
"properties": {
"connectTimeout": "20",
"loginTimeout": "20",
"escapeSyntaxCallMode": "callIfNoReturn"
},
"provider-properties": {
"@dbeaver-show-non-default-db@": "true",
"@dbeaver-chosen-role@": "",
"@dbeaver-show-template-db@": "false",
"@dbeaver-show-unavailable-db@": "false",
"show-database-statistics": "false",
"@dbeaver-read-all-data-types-db@": "false",
"read-keys-with-columns": "false",
"@dbeaver-use-prepared-statements-db@": "false",
"postgresql.dd.plain.string": "false",
"postgresql.dd.tag.string": "false"
},
"auth-model": "native"
} }
} }
}, },

View file

@ -33,12 +33,9 @@
"postgresql.dd.tag.string": "false" "postgresql.dd.tag.string": "false"
}, },
"auth-model": "native" "auth-model": "native"
},
"custom-properties": {
"SQLEditor.outputPanel.autoShow": "false"
} }
}, },
"postgres-jdbc-1950174dc2f-6bd6c7100db1cc5c": { "postgres-jdbc-195383ce5c3-68a4eee43daef302": {
"provider": "postgresql", "provider": "postgresql",
"driver": "postgres-jdbc", "driver": "postgres-jdbc",
"name": "UB-KK01-sathumper", "name": "UB-KK01-sathumper",

View file

@ -1 +1 @@
{"resources":{"Scripts/Script-1.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"},"Scripts/Script.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"},"Scripts/SmartConfigSystem.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptdb01"},"Scripts/grant-privileges.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"}}} {"resources":{"Scripts/Script-1.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"},"Scripts/Script.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"},"Scripts/SmartConfigSystem.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptdb01"},"Scripts/grant-privileges.sql":{"default-schema":"system","default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"sandbox"}}}

View file

@ -0,0 +1,11 @@
INSERT INTO "system".app_configuration ("key",value,"label",content_type,valid_from,expires_at,created_at,modified_at,etag) VALUES
('Email:Templates:Welcome','{"subject":"Velkommen til vores platform","template":"welcome-dk.html","sender":"velkommen@firma.dk"}','test','application/json','2024-01-01 01:00:00+01',NULL,'2025-02-03 16:46:36.665888+01','2025-02-03 16:47:30.528326+01','c48949c4-c02f-4c77-b81c-e281a810def1'::uuid),
('Email:Templates:Password','{"subject":"Nulstil dit kodeord","template":"reset-password-dk.html","sender":"support@firma.dk"}','Email Templates','application/json','2024-01-01 01:00:00+01',NULL,'2025-02-03 16:47:56.537775+01','2025-02-03 16:47:56.537775+01','26500738-4f5b-4cc8-a0e4-2a6a5fd57675'::uuid),
('Debug','true',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','f1348731-9396-4f1d-b40a-7fbd23a897d2'::uuid),
('Database:ConnectionString','"Server=db.example.com;Port=5432"',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','2aa0bc3e-fa24-449a-8f25-a76d9b4d535e'::uuid),
('Database:Timeout','30',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','d25ebb14-49f6-4e33-9ac7-a3253705d0fb'::uuid),
('Database:UseSSL','true',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','f4d52ec4-b723-4561-9b18-0e7a68b89a17'::uuid),
('Logging:FileOptions','{"Path": "/var/logs/app.log", "MaxSizeMB": 100, "RetentionDays": 7}',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','06c0891d-a860-4acc-917a-d0877f511c1b'::uuid),
('Features:Experimental','{"Enabled": true, "RolloutPercentage": 25, "AllowedUserGroups": ["beta"]}',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','0136fdef-51d9-4909-82ef-f72053ce6d6d'::uuid),
('API:Endpoints','"/api/users"',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','fe362b69-a486-48ad-9165-2e623e2e6f70'::uuid),
('API:Endpoints','"/api/products"',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','c087e2d4-1f38-4814-b4dd-f30c463dc6d1'::uuid);

View file

@ -1,5 +1,5 @@
using FluentAssertions;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Shouldly;
using PlanTempus.Tests; using PlanTempus.Tests;
using PlanTempus.Core.Configurations; using PlanTempus.Core.Configurations;
using PlanTempus.Core.Configurations.JsonConfigProvider; using PlanTempus.Core.Configurations.JsonConfigProvider;
@ -33,8 +33,8 @@ namespace PlanTempus.Tests.ConfigurationTests
var section = builder.GetSection("Feature"); var section = builder.GetSection("Feature");
// Assert // Assert
section.Should().NotBeNull(); section.ShouldNotBeNull();
section.Value.Should().BeEquivalentTo(expectedJObject); section.Value.ShouldBeEquivalentTo(expectedJObject);
} }
[TestMethod] [TestMethod]
@ -58,8 +58,8 @@ namespace PlanTempus.Tests.ConfigurationTests
var actualFeatureObsoleted = builder.GetSection("Feature").Get<Feature>(); var actualFeatureObsoleted = builder.GetSection("Feature").Get<Feature>();
#pragma warning restore CS0618 // Type or member is obsolete #pragma warning restore CS0618 // Type or member is obsolete
// Assert // Assert
actualFeature.Should().BeEquivalentTo(expectedFeature); actualFeature.ShouldBeEquivalentTo(expectedFeature);
actualFeatureObsoleted.Should().BeEquivalentTo(expectedFeature); actualFeatureObsoleted.ShouldBeEquivalentTo(expectedFeature);
} }
[TestMethod] [TestMethod]
@ -76,7 +76,7 @@ namespace PlanTempus.Tests.ConfigurationTests
var actualFeature = builder.GetSection("AnotherSetting").Get<string>("Thresholds:High"); var actualFeature = builder.GetSection("AnotherSetting").Get<string>("Thresholds:High");
// Assert // Assert
actualFeature.Should().BeEquivalentTo(expectedFeature); actualFeature.ShouldBeEquivalentTo(expectedFeature);
} }
/// <summary> /// <summary>
/// Testing a stupid indexer for compability with Microsoft ConfigurationBuilder /// Testing a stupid indexer for compability with Microsoft ConfigurationBuilder
@ -95,7 +95,7 @@ namespace PlanTempus.Tests.ConfigurationTests
var actual = builder["Authentication"]; var actual = builder["Authentication"];
// Assert // Assert
actual.Should().BeEquivalentTo(expected); actual.ShouldBeEquivalentTo(expected);
} }
[TestMethod] [TestMethod]
public void Get_ShouldReturnCorrectValueAsInt() public void Get_ShouldReturnCorrectValueAsInt()
@ -111,7 +111,7 @@ namespace PlanTempus.Tests.ConfigurationTests
var actualFeature = builder.GetSection("AnotherSetting:Temperature").Get<int>("Indoor:Max:Limit"); var actualFeature = builder.GetSection("AnotherSetting:Temperature").Get<int>("Indoor:Max:Limit");
// Assert // Assert
actualFeature.Should().Be(expectedFeature); actualFeature.ShouldBe(expectedFeature);
} }
[TestMethod] [TestMethod]
public void Get_ShouldReturnCorrectValueAsBool() public void Get_ShouldReturnCorrectValueAsBool()
@ -128,7 +128,7 @@ namespace PlanTempus.Tests.ConfigurationTests
var actualFeature = configRoot.Get<bool>("Database:UseSSL"); var actualFeature = configRoot.Get<bool>("Database:UseSSL");
// Assert // Assert
actualFeature.Should().Be(expectedFeature); actualFeature.ShouldBe(expectedFeature);
} }
} }

View file

@ -1,5 +1,5 @@
using FluentAssertions; using Autofac;
using Autofac; using Shouldly;
using System.Data; using System.Data;
using Insight.Database; using Insight.Database;
using Npgsql; using Npgsql;
@ -13,12 +13,13 @@ namespace PlanTempus.Tests.ConfigurationTests
[TestClass] [TestClass]
public class SmartConfigProviderTests : TestFixture public class SmartConfigProviderTests : TestFixture
{ {
const string _testFolder = "ConfigurationTests/";
[TestMethod] [TestMethod]
public void TrySmartConfigWithOptionsForPostgres() public void TrySmartConfigWithOptionsForPostgres()
{ {
var config = new ConfigurationBuilder() var config = new ConfigurationBuilder()
.AddJsonFile("appconfiguration.dev.json") .AddJsonFile($"{_testFolder}appconfiguration.dev.json")
.AddSmartConfig(options => options.UsePostgres("DefaultConnection")) .AddSmartConfig(options => options.UsePostgres("DefaultConnection"))
.Build(); .Build();
@ -33,15 +34,15 @@ namespace PlanTempus.Tests.ConfigurationTests
var expectedFeature = true; var expectedFeature = true;
var config = new ConfigurationBuilder() var config = new ConfigurationBuilder()
.AddJsonFile("appconfiguration.dev.json") .AddJsonFile($"{_testFolder}appconfiguration.dev.json")
.AddSmartConfig() .AddSmartConfig(options => options.UsePostgres("DefaultConnection"))
.Build(); .Build();
// Act // Act
var actualFeature = config.Get<bool>("Database:UseSSL"); var actualFeature = config.Get<bool>("Database:UseSSL");
// Assert // Assert
actualFeature.Should().Be(expectedFeature); actualFeature.ShouldBe(expectedFeature);
} }
[TestMethod] [TestMethod]
public void Get_ShouldReturnCorrectValueWhenSelectingIntoValueRowInConfigTable() public void Get_ShouldReturnCorrectValueWhenSelectingIntoValueRowInConfigTable()
@ -50,8 +51,8 @@ namespace PlanTempus.Tests.ConfigurationTests
var expectedFeature = 100; var expectedFeature = 100;
var builder = new ConfigurationBuilder() var builder = new ConfigurationBuilder()
.AddJsonFile("appconfiguration.dev.json") .AddJsonFile($"{_testFolder}appconfiguration.dev.json")
.AddSmartConfig() .AddSmartConfig(options => options.UsePostgres("DefaultConnection"))
.Build(); .Build();
// Act // Act
@ -59,14 +60,15 @@ namespace PlanTempus.Tests.ConfigurationTests
var withoutSectionThisAlsoWorks = builder.Get<int>("Logging:FileOptions:MaxSizeMB"); var withoutSectionThisAlsoWorks = builder.Get<int>("Logging:FileOptions:MaxSizeMB");
// Assert // Assert
actualFeature.Should().Be(expectedFeature); actualFeature.ShouldBe(expectedFeature);
actualFeature.Should().Be(withoutSectionThisAlsoWorks); actualFeature.ShouldBe(withoutSectionThisAlsoWorks);
} }
[TestMethod] [TestMethod]
public void TryGetActiveConfigurations() public void TryGetActiveConfigurations()
{ {
var connFactory = Container.Resolve<Database.Core.ConnectionFactory.IDbConnectionFactory>();
const string sql = @" const string sql = @"
SELECT id, ""key"", value, label, content_type, SELECT id, ""key"", value, label, content_type,
@ -75,13 +77,11 @@ namespace PlanTempus.Tests.ConfigurationTests
WHERE CURRENT_TIMESTAMP BETWEEN valid_from AND expires_at WHERE CURRENT_TIMESTAMP BETWEEN valid_from AND expires_at
OR (valid_from IS NULL AND expires_at IS NULL)"; OR (valid_from IS NULL AND expires_at IS NULL)";
var conn = Container.Resolve<IDbConnection>(); using (var conn = connFactory.Create())
{
var result = conn.QuerySql(sql); var result = conn.QuerySql(sql);
} }
} }
}
} }

View file

@ -1,7 +1,7 @@
{ {
"AllowedHosts": "*", "AllowedHosts": "*",
"ConnectionStrings": { "ConnectionStrings": {
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id=sathumper;Password=3911;" "DefaultConnection": "Host=192.168.1.57;Port=5432;Database=sandbox;User Id=sathumper;Password=3911;"
}, },
"ApplicationInsights": { "ApplicationInsights": {
"ConnectionString": "InstrumentationKey=07d2a2b9-5e8e-4924-836e-264f8438f6c5;IngestionEndpoint=https://northeurope-2.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/;ApplicationId=56748c39-2fa3-4880-a1e2-24068e791548", "ConnectionString": "InstrumentationKey=07d2a2b9-5e8e-4924-836e-264f8438f6c5;IngestionEndpoint=https://northeurope-2.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/;ApplicationId=56748c39-2fa3-4880-a1e2-24068e791548",

View file

@ -10,11 +10,11 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" /> <PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="FluentAssertions" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="moq" Version="4.20.72" /> <PackageReference Include="moq" Version="4.20.72" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" /> <PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" /> <PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="Shouldly" Version="4.3.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>