Updates configuration and refactors code structure
Migrates connection strings to new database host Removes unnecessary code and improves configuration handling Enhances test coverage and adds random word generation Updates telemetry and command handling patterns
This commit is contained in:
parent
dc98178095
commit
a991dcdb97
18 changed files with 481 additions and 63 deletions
|
|
@ -6,7 +6,7 @@ internal class TestPostgresLISTENNOTIFY
|
|||
{
|
||||
private static async Task Main(string[] args)
|
||||
{
|
||||
var connectionString = "Host=192.168.1.57;Database=ptdb01;Username=postgres;Password=3911";
|
||||
var connectionString = "Host=192.168.1.63;Database=ptdb01;Username=postgres;Password=3911";
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using PlanTempus.Core.CommandQueries;
|
|||
using PlanTempus.Core.Database;
|
||||
using PlanTempus.Core.Database.ConnectionFactory;
|
||||
using Shouldly;
|
||||
|
||||
namespace PlanTempus.X.TDD.CommandQueryHandlerTests;
|
||||
|
||||
[TestClass]
|
||||
|
|
@ -25,7 +24,7 @@ public class HandlerTest : TestFixture
|
|||
|
||||
var command = new CreateUserCommand
|
||||
{
|
||||
Email = "lloyd@dumbanddumber.com5", // Lloyd Christmas
|
||||
Email = $"{GetRandomWord()}@dumbanddumber.com5", // Lloyd Christmas
|
||||
Password = "1234AceVentura#LOL", // Ace Ventura
|
||||
IsActive = true,
|
||||
CorrelationId = Guid.NewGuid()
|
||||
|
|
|
|||
|
|
@ -48,6 +48,6 @@ public class ProblemDetailsTests
|
|||
}
|
||||
""";
|
||||
|
||||
json.ShouldBe(expectedJson);
|
||||
JsonConvert.DeserializeObject(json).ShouldBeSameAs(JsonConvert.DeserializeObject(expectedJson));
|
||||
}
|
||||
}
|
||||
|
|
@ -118,18 +118,17 @@ public class JsonConfigurationProviderTests : TestFixture
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Get_ShouldReturnCorrectValueAsBool()
|
||||
public void Get_ShouldReturnCorrectValueAsNullBool()
|
||||
{
|
||||
// Arrange
|
||||
var expectedFeature = true;
|
||||
bool? expectedFeature = null;
|
||||
|
||||
var configRoot = new ConfigurationBuilder()
|
||||
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
|
||||
.AddSmartConfig()
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var actualFeature = configRoot.Get<bool>("Database:UseSSL");
|
||||
var actualFeature = configRoot.Get<bool?>("MissingKey:WhatThen");
|
||||
|
||||
// Assert
|
||||
actualFeature.ShouldBe(expectedFeature);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=sandbox;User Id=sathumper;Password=3911;"
|
||||
"DefaultConnection": "Host=192.168.1.63;Port=5432;Database=sandbox;User Id=sathumper;Password=3911;"
|
||||
},
|
||||
"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",
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1"/>
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1"/>
|
||||
<PackageReference Include="Shouldly" Version="4.3.0"/>
|
||||
<PackageReference Include="CrypticWizard.RandomWordGenerator" Version="0.9.5"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -66,19 +66,15 @@ public class PostgresTests : TestFixture
|
|||
public async Task TestForUniqueUserEmail()
|
||||
{
|
||||
using var db = _databaseOperations.CreateScope(nameof(TestForUniqueUserEmail));
|
||||
// try
|
||||
try
|
||||
{
|
||||
var sql = @"
|
||||
INSERT INTO system.users(email, password_hash, security_stamp, email_confirmed,
|
||||
access_failed_count, lockout_enabled,
|
||||
is_active)
|
||||
VALUES(@Email, @PasswordHash, @SecurityStamp, @EmailConfirmed,
|
||||
@AccessFailedCount, @LockoutEnabled, @IsActive)
|
||||
var sql = @"INSERT INTO system.users(email, password_hash, security_stamp, email_confirmed, access_failed_count, lockout_enabled, is_active)
|
||||
VALUES(@Email, @PasswordHash, @SecurityStamp, @EmailConfirmed, @AccessFailedCount, @LockoutEnabled, @IsActive)
|
||||
RETURNING id, created_at, email, is_active";
|
||||
|
||||
var parameters = new
|
||||
{
|
||||
Email = "jarjarbinks22233@mars.com",
|
||||
Email = $"{GetRandomWord()}@mars.com",
|
||||
PasswordHash = "MartianRover2025",
|
||||
SecurityStamp = "MarsOrBust",
|
||||
EmailConfirmed = true,
|
||||
|
|
@ -89,16 +85,17 @@ public class PostgresTests : TestFixture
|
|||
|
||||
var user = await db.Connection.QuerySqlAsync<dynamic>(sql, parameters);
|
||||
|
||||
// user.ShouldNotBeNull();
|
||||
|
||||
//EmailAlreadyRegistreredException
|
||||
//try insert, to test exception
|
||||
var ex = await Should.ThrowAsync<EmailAlreadyRegistreredException>(async () =>
|
||||
await db.Connection.ExecuteAsync(sql, parameters));
|
||||
var ex = await Should.ThrowAsync<Npgsql.PostgresException>(async () =>
|
||||
await db.Connection.QuerySqlAsync<dynamic>(sql, parameters));
|
||||
ex.ConstraintName.ShouldBe("users_email_key");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
db.Error(ex);
|
||||
|
||||
}
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// db.Error(ex);
|
||||
// }
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using PlanTempus.Core.Configurations.JsonConfigProvider;
|
|||
using PlanTempus.Core.ModuleRegistry;
|
||||
using PlanTempus.Core.SeqLogging;
|
||||
using PlanTempus.Database.ModuleRegistry;
|
||||
using CrypticWizard.RandomWordGenerator;
|
||||
|
||||
namespace PlanTempus.X.TDD;
|
||||
|
||||
|
|
@ -22,7 +23,11 @@ public abstract class TestFixture
|
|||
protected TestFixture() : this(null)
|
||||
{
|
||||
}
|
||||
|
||||
public string GetRandomWord()
|
||||
{
|
||||
var myWordGenerator = new WordGenerator();
|
||||
return myWordGenerator.GetWord(WordGenerator.PartOfSpeech.verb);
|
||||
}
|
||||
public TestFixture(string configurationFilePath)
|
||||
{
|
||||
if (configurationFilePath is not null)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id=sathumper;Password=3911;"
|
||||
"DefaultConnection": "Host=192.168.1.63;Port=5432;Database=ptmain;User Id=sathumper;Password=3911;"
|
||||
},
|
||||
"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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue