From 31666b4ba0758e484e297959cafb55df6f9a4a1f Mon Sep 17 00:00:00 2001 From: "Janus C. H. Knudsen" Date: Mon, 10 Mar 2025 15:56:22 +0100 Subject: [PATCH] wip --- .../ConnectionFactory/IDbConnectionFactory.cs | 2 +- .../PostgresConnectionFactory.cs | 7 +++-- Core/{Sql => Database}/DatabaseScope.cs | 8 ++--- Core/{Sql => Database}/IDatabaseOperations.cs | 2 +- Core/{Sql => Database}/SqlOperations.cs | 6 ++-- Core/ModuleRegistry/SeqLoggingModule.cs | 2 +- Core/ModuleRegistry/TelemetryModule.cs | 10 +++---- .../SeqBackgroundService.cs | 2 +- .../SeqConfiguration.cs | 2 +- Core/{Logging => SeqLogging}/SeqHttpClient.cs | 2 +- Core/{Logging => SeqLogging}/SeqLogger.cs | 22 +++++--------- .../SetupConfiguration.cs | 2 +- Database/Core/DCL/SetupApplicationUser.cs | 2 +- Database/Core/DCL/SetupDbAdmin.cs | 2 +- Database/Core/DCL/SetupOrganizationUser.cs | 2 +- Database/Core/DDL/SetupIdentitySystem.cs | 2 +- Database/Core/IDbConfigure.cs | 2 +- Database/ModuleRegistry/DbPostgreSqlModule.cs | 4 +-- .../ModuleRegistry/SeqLoggingModule.cs | 24 +++++++++++++++ .../Create/CreateOrganizationHandler.cs | 4 +-- .../Users/Create/CreateUserCommand.cs | 18 +++++++---- .../Users/Create/CreateUserHandler.cs | 17 +++++++++-- .../Create/CreateUserHandlerDecorator.cs | 25 ++++++++++++++++ .../EmailAlreadyRegistreredException.cs | 6 ++++ SetupInfrastructure/Program.cs | 2 +- SetupInfrastructure/Startup.cs | 3 +- .../SetupConfigurationTests.cs | 2 +- .../SmartConfigProviderTests.cs | 2 +- Tests/Logging/SeqBackgroundServiceTest.cs | 2 +- Tests/Logging/SeqLoggerTests.cs | 2 +- Tests/Logging/SeqTelemetryChannelTest.cs | 2 +- Tests/PlanTempus.X.TDD.csproj | 1 + Tests/PostgresTests.cs | 30 ++++++++----------- Tests/TestFixture.cs | 2 +- 34 files changed, 140 insertions(+), 83 deletions(-) rename Core/{Sql => Database}/ConnectionFactory/IDbConnectionFactory.cs (76%) rename Core/{Sql => Database}/ConnectionFactory/PostgresConnectionFactory.cs (95%) rename Core/{Sql => Database}/DatabaseScope.cs (91%) rename Core/{Sql => Database}/IDatabaseOperations.cs (88%) rename Core/{Sql => Database}/SqlOperations.cs (92%) rename Core/{Logging => SeqLogging}/SeqBackgroundService.cs (98%) rename Core/{Logging => SeqLogging}/SeqConfiguration.cs (72%) rename Core/{Logging => SeqLogging}/SeqHttpClient.cs (96%) rename Core/{Logging => SeqLogging}/SeqLogger.cs (93%) create mode 100644 PlanTempus.Components/ModuleRegistry/SeqLoggingModule.cs create mode 100644 PlanTempus.Components/Users/Create/CreateUserHandlerDecorator.cs create mode 100644 PlanTempus.Components/Users/Exceptions/EmailAlreadyRegistreredException.cs diff --git a/Core/Sql/ConnectionFactory/IDbConnectionFactory.cs b/Core/Database/ConnectionFactory/IDbConnectionFactory.cs similarity index 76% rename from Core/Sql/ConnectionFactory/IDbConnectionFactory.cs rename to Core/Database/ConnectionFactory/IDbConnectionFactory.cs index 2957a7d..f1b8bd3 100644 --- a/Core/Sql/ConnectionFactory/IDbConnectionFactory.cs +++ b/Core/Database/ConnectionFactory/IDbConnectionFactory.cs @@ -1,4 +1,4 @@ -namespace PlanTempus.Core.Sql.ConnectionFactory +namespace PlanTempus.Core.Database.ConnectionFactory { public interface IDbConnectionFactory { diff --git a/Core/Sql/ConnectionFactory/PostgresConnectionFactory.cs b/Core/Database/ConnectionFactory/PostgresConnectionFactory.cs similarity index 95% rename from Core/Sql/ConnectionFactory/PostgresConnectionFactory.cs rename to Core/Database/ConnectionFactory/PostgresConnectionFactory.cs index 9f2906d..b77b3df 100644 --- a/Core/Sql/ConnectionFactory/PostgresConnectionFactory.cs +++ b/Core/Database/ConnectionFactory/PostgresConnectionFactory.cs @@ -1,6 +1,7 @@ -using Npgsql; -using System.Data; -namespace PlanTempus.Core.Sql.ConnectionFactory +using System.Data; +using Npgsql; + +namespace PlanTempus.Core.Database.ConnectionFactory { public record ConnectionStringParameters(string User, string Pwd); diff --git a/Core/Sql/DatabaseScope.cs b/Core/Database/DatabaseScope.cs similarity index 91% rename from Core/Sql/DatabaseScope.cs rename to Core/Database/DatabaseScope.cs index 34cdf0c..7d61480 100644 --- a/Core/Sql/DatabaseScope.cs +++ b/Core/Database/DatabaseScope.cs @@ -2,7 +2,7 @@ using Microsoft.ApplicationInsights.DataContracts; using Microsoft.ApplicationInsights.Extensibility; -namespace PlanTempus.Core.Sql; +namespace PlanTempus.Core.Database; public class DatabaseScope : IDisposable { @@ -12,6 +12,7 @@ public class DatabaseScope : IDisposable { Connection = connection; _operation = operation; + _operation.Telemetry.Success = true; } public IDbConnection Connection { get; } @@ -22,11 +23,6 @@ public class DatabaseScope : IDisposable Connection.Dispose(); } - public void Success() - { - _operation.Telemetry.Success = true; - } - public void Error(Exception ex) { _operation.Telemetry.Success = false; diff --git a/Core/Sql/IDatabaseOperations.cs b/Core/Database/IDatabaseOperations.cs similarity index 88% rename from Core/Sql/IDatabaseOperations.cs rename to Core/Database/IDatabaseOperations.cs index 8d4031d..31148e1 100644 --- a/Core/Sql/IDatabaseOperations.cs +++ b/Core/Database/IDatabaseOperations.cs @@ -1,6 +1,6 @@ using System.Data; -namespace PlanTempus.Core.Sql; +namespace PlanTempus.Core.Database; public interface IDatabaseOperations { diff --git a/Core/Sql/SqlOperations.cs b/Core/Database/SqlOperations.cs similarity index 92% rename from Core/Sql/SqlOperations.cs rename to Core/Database/SqlOperations.cs index aa31522..5f38463 100644 --- a/Core/Sql/SqlOperations.cs +++ b/Core/Database/SqlOperations.cs @@ -1,9 +1,9 @@ using System.Data; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.DataContracts; -using PlanTempus.Core.Sql.ConnectionFactory; +using PlanTempus.Core.Database.ConnectionFactory; -namespace PlanTempus.Core.Sql; +namespace PlanTempus.Core.Database; public class SqlOperations : IDatabaseOperations { @@ -32,7 +32,6 @@ public class SqlOperations : IDatabaseOperations try { var result = await operation(scope.Connection); - scope.Success(); return result; } catch (Exception ex) @@ -48,7 +47,6 @@ public class SqlOperations : IDatabaseOperations try { await operation(scope.Connection); - scope.Success(); } catch (Exception ex) { diff --git a/Core/ModuleRegistry/SeqLoggingModule.cs b/Core/ModuleRegistry/SeqLoggingModule.cs index fae509c..cd4f244 100644 --- a/Core/ModuleRegistry/SeqLoggingModule.cs +++ b/Core/ModuleRegistry/SeqLoggingModule.cs @@ -1,5 +1,5 @@ using Autofac; -using PlanTempus.Core.Logging; +using PlanTempus.Core.SeqLogging; namespace PlanTempus.Core.ModuleRegistry { diff --git a/Core/ModuleRegistry/TelemetryModule.cs b/Core/ModuleRegistry/TelemetryModule.cs index b8849f4..cdef080 100644 --- a/Core/ModuleRegistry/TelemetryModule.cs +++ b/Core/ModuleRegistry/TelemetryModule.cs @@ -10,13 +10,12 @@ namespace PlanTempus.Core.ModuleRegistry protected override void Load(ContainerBuilder builder) { - var configuration = TelemetryConfiguration.CreateDefault(); configuration.ConnectionString = TelemetryConfig.ConnectionString; configuration.TelemetryChannel.DeveloperMode = true; var client = new Microsoft.ApplicationInsights.TelemetryClient(configuration); - client.Context.GlobalProperties["Application"] = GetType().Namespace.Split('.')[0]; + client.Context.GlobalProperties["Application"] = GetType().Namespace?.Split('.')[0]; client.Context.GlobalProperties["MachineName"] = Environment.MachineName; client.Context.GlobalProperties["Version"] = Environment.Version.ToString(); client.Context.GlobalProperties["ProcessorCount"] = Environment.ProcessorCount.ToString(); @@ -34,10 +33,11 @@ namespace PlanTempus.Core.ModuleRegistry configuration.TelemetryChannel = new Telemetry.SeqTelemetryChannel(messageChannel, client); } - var telemetryProcessorChain = new Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryProcessorChainBuilder(configuration); + var telemetryProcessorChain = + new Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryProcessorChainBuilder( + configuration); telemetryProcessorChain.Use(next => new Telemetry.Enrichers.EnrichWithMetaTelemetry(next)); telemetryProcessorChain.Build(); - } } @@ -46,4 +46,4 @@ namespace PlanTempus.Core.ModuleRegistry public string ConnectionString { get; set; } public bool UseSeqLoggingTelemetryChannel { get; set; } } -} +} \ No newline at end of file diff --git a/Core/Logging/SeqBackgroundService.cs b/Core/SeqLogging/SeqBackgroundService.cs similarity index 98% rename from Core/Logging/SeqBackgroundService.cs rename to Core/SeqLogging/SeqBackgroundService.cs index 07e8392..cef2cc1 100644 --- a/Core/Logging/SeqBackgroundService.cs +++ b/Core/SeqLogging/SeqBackgroundService.cs @@ -4,7 +4,7 @@ using Microsoft.ApplicationInsights.DataContracts; using Microsoft.Extensions.Hosting; using PlanTempus.Core.Telemetry; -namespace PlanTempus.Core.Logging +namespace PlanTempus.Core.SeqLogging { public class SeqBackgroundService : BackgroundService { diff --git a/Core/Logging/SeqConfiguration.cs b/Core/SeqLogging/SeqConfiguration.cs similarity index 72% rename from Core/Logging/SeqConfiguration.cs rename to Core/SeqLogging/SeqConfiguration.cs index 00e1e9b..09e8598 100644 --- a/Core/Logging/SeqConfiguration.cs +++ b/Core/SeqLogging/SeqConfiguration.cs @@ -1,4 +1,4 @@ -namespace PlanTempus.Core.Logging +namespace PlanTempus.Core.SeqLogging { public record SeqConfiguration(string IngestionEndpoint, string ApiKey, string Environment); } \ No newline at end of file diff --git a/Core/Logging/SeqHttpClient.cs b/Core/SeqLogging/SeqHttpClient.cs similarity index 96% rename from Core/Logging/SeqHttpClient.cs rename to Core/SeqLogging/SeqHttpClient.cs index 30c5384..9ce7a4d 100644 --- a/Core/Logging/SeqHttpClient.cs +++ b/Core/SeqLogging/SeqHttpClient.cs @@ -1,4 +1,4 @@ -namespace PlanTempus.Core.Logging +namespace PlanTempus.Core.SeqLogging { public class SeqHttpClient { diff --git a/Core/Logging/SeqLogger.cs b/Core/SeqLogging/SeqLogger.cs similarity index 93% rename from Core/Logging/SeqLogger.cs rename to Core/SeqLogging/SeqLogger.cs index 709f97a..ae34f4d 100644 --- a/Core/Logging/SeqLogger.cs +++ b/Core/SeqLogging/SeqLogger.cs @@ -1,13 +1,11 @@ -using Microsoft.ApplicationInsights.DataContracts; -using System.Text; +using System.Text; +using Microsoft.ApplicationInsights.DataContracts; -namespace PlanTempus.Core.Logging +namespace PlanTempus.Core.SeqLogging { public class SeqLogger { private readonly SeqHttpClient _httpClient; - private readonly string _environmentName; - private readonly string _machineName; private readonly SeqConfiguration _configuration; public SeqLogger(SeqHttpClient httpClient, SeqConfiguration configuration) @@ -23,8 +21,7 @@ namespace PlanTempus.Core.Logging { "@t", trace.Timestamp.UtcDateTime.ToString("o") }, { "@mt", trace.Message }, { "@l", MapSeverityToLevel(trace.SeverityLevel) }, - { "Environment", _environmentName }, - { "MachineName", _machineName } + { "Environment", _configuration.Environment }, }; foreach (var prop in trace.Properties) @@ -43,8 +40,7 @@ namespace PlanTempus.Core.Logging { "@t", evt.Timestamp.UtcDateTime.ToString("o") }, { "@mt", evt.Name }, { "@l", "Information" }, - { "Environment", _environmentName }, - { "MachineName", _machineName } + { "Environment", _configuration.Environment } }; foreach (var prop in evt.Properties) @@ -67,9 +63,8 @@ namespace PlanTempus.Core.Logging { "@mt", ex.Exception.Message }, { "@l", "Error" }, { "@x", FormatExceptionForSeq(ex.Exception) }, - { "Environment", _environmentName }, - { "MachineName", _machineName }, - { "ExceptionType", ex.Exception.GetType().Name }, + { "Environment", _configuration.Environment }, + { "ExceptionType", ex.Exception.GetType().Name } }; foreach (var prop in ex.Properties) @@ -88,8 +83,7 @@ namespace PlanTempus.Core.Logging { "@t", dep.Timestamp.UtcDateTime.ToString("o") }, { "@mt", $"Dependency: {dep.Name}" }, { "@l", dep.Success ?? true ? "Information" : "Error" }, - { "Environment", _environmentName }, - { "MachineName", _machineName }, + { "Environment", _configuration.Environment }, { "DependencyType", dep.Type }, { "Target", dep.Target }, { "Duration", dep.Duration.TotalMilliseconds } diff --git a/Database/ConfigurationManagementSystem/SetupConfiguration.cs b/Database/ConfigurationManagementSystem/SetupConfiguration.cs index ae0db21..382a94c 100644 --- a/Database/ConfigurationManagementSystem/SetupConfiguration.cs +++ b/Database/ConfigurationManagementSystem/SetupConfiguration.cs @@ -1,7 +1,7 @@ using Insight.Database; -using PlanTempus.Core.Sql.ConnectionFactory; using PlanTempus.Database.Core; using System.Data; +using PlanTempus.Core.Database.ConnectionFactory; namespace PlanTempus.Database.ConfigurationManagementSystem; diff --git a/Database/Core/DCL/SetupApplicationUser.cs b/Database/Core/DCL/SetupApplicationUser.cs index 9f14e66..2890127 100644 --- a/Database/Core/DCL/SetupApplicationUser.cs +++ b/Database/Core/DCL/SetupApplicationUser.cs @@ -1,6 +1,6 @@ using System.Data; using Insight.Database; -using PlanTempus.Core.Sql.ConnectionFactory; +using PlanTempus.Core.Database.ConnectionFactory; using PlanTempus.Database.Common; namespace PlanTempus.Database.Core.DCL diff --git a/Database/Core/DCL/SetupDbAdmin.cs b/Database/Core/DCL/SetupDbAdmin.cs index 1d5a948..af18bdb 100644 --- a/Database/Core/DCL/SetupDbAdmin.cs +++ b/Database/Core/DCL/SetupDbAdmin.cs @@ -1,6 +1,6 @@ using System.Data; using Insight.Database; -using PlanTempus.Core.Sql.ConnectionFactory; +using PlanTempus.Core.Database.ConnectionFactory; using PlanTempus.Database.Common; namespace PlanTempus.Database.Core.DCL diff --git a/Database/Core/DCL/SetupOrganizationUser.cs b/Database/Core/DCL/SetupOrganizationUser.cs index 7708888..e56294a 100644 --- a/Database/Core/DCL/SetupOrganizationUser.cs +++ b/Database/Core/DCL/SetupOrganizationUser.cs @@ -1,6 +1,6 @@ using System.Data; using Insight.Database; -using PlanTempus.Core.Sql.ConnectionFactory; +using PlanTempus.Core.Database.ConnectionFactory; using PlanTempus.Database.Common; using PlanTempus.Database.Core; diff --git a/Database/Core/DDL/SetupIdentitySystem.cs b/Database/Core/DDL/SetupIdentitySystem.cs index 18838d5..01a883f 100644 --- a/Database/Core/DDL/SetupIdentitySystem.cs +++ b/Database/Core/DDL/SetupIdentitySystem.cs @@ -1,6 +1,6 @@ using Insight.Database; -using PlanTempus.Core.Sql.ConnectionFactory; using System.Data; +using PlanTempus.Core.Database.ConnectionFactory; namespace PlanTempus.Database.Core.DDL { diff --git a/Database/Core/IDbConfigure.cs b/Database/Core/IDbConfigure.cs index c2bbf82..135fcf9 100644 --- a/Database/Core/IDbConfigure.cs +++ b/Database/Core/IDbConfigure.cs @@ -1,4 +1,4 @@ -using PlanTempus.Core.Sql.ConnectionFactory; +using PlanTempus.Core.Database.ConnectionFactory; namespace PlanTempus.Database.Core { diff --git a/Database/ModuleRegistry/DbPostgreSqlModule.cs b/Database/ModuleRegistry/DbPostgreSqlModule.cs index 9427dea..0a6b847 100644 --- a/Database/ModuleRegistry/DbPostgreSqlModule.cs +++ b/Database/ModuleRegistry/DbPostgreSqlModule.cs @@ -1,6 +1,6 @@ using Autofac; -using PlanTempus.Core.Sql; -using PlanTempus.Core.Sql.ConnectionFactory; +using PlanTempus.Core.Database; +using PlanTempus.Core.Database.ConnectionFactory; namespace PlanTempus.Database.ModuleRegistry { diff --git a/PlanTempus.Components/ModuleRegistry/SeqLoggingModule.cs b/PlanTempus.Components/ModuleRegistry/SeqLoggingModule.cs new file mode 100644 index 0000000..559a8fc --- /dev/null +++ b/PlanTempus.Components/ModuleRegistry/SeqLoggingModule.cs @@ -0,0 +1,24 @@ +using Autofac; +using PlanTempus.Core.SeqLogging; + +namespace PlanTempus.Components.ModuleRegistry +{ + public class CommandModule : Module + { + // public required SeqConfiguration SeqConfiguration { get; set; } + + protected override void Load(ContainerBuilder builder) + { + // Registrer alle handlers + builder.RegisterAssemblyTypes() + .AsClosedTypesOf(typeof(ICommandHandler<>)) + .InstancePerLifetimeScope(); + +// Registrer en decorator for alle ICommandHandler + builder.RegisterGenericDecorator( + typeof(LoggingCommandHandlerDecorator<>), // Din decorator-klasse + typeof(ICommandHandler<>)); // Interface, der skal dekoreres + + } + } +} \ No newline at end of file diff --git a/PlanTempus.Components/Organizations/Create/CreateOrganizationHandler.cs b/PlanTempus.Components/Organizations/Create/CreateOrganizationHandler.cs index 9c3172a..06517f2 100644 --- a/PlanTempus.Components/Organizations/Create/CreateOrganizationHandler.cs +++ b/PlanTempus.Components/Organizations/Create/CreateOrganizationHandler.cs @@ -1,6 +1,6 @@ using Insight.Database; using Microsoft.ApplicationInsights; -using PlanTempus.Core.Sql; +using PlanTempus.Core.Database; using PlanTempus.Core.Telemetry; namespace PlanTempus.Components.Organizations.Create @@ -32,8 +32,6 @@ namespace PlanTempus.Components.Organizations.Create transaction.Commit(); - db.Success(); - telemetryClient.TrackTrace(GetType().Name, orgResult.Format()); return orgResult; } diff --git a/PlanTempus.Components/Users/Create/CreateUserCommand.cs b/PlanTempus.Components/Users/Create/CreateUserCommand.cs index f07a6d5..32bbe58 100644 --- a/PlanTempus.Components/Users/Create/CreateUserCommand.cs +++ b/PlanTempus.Components/Users/Create/CreateUserCommand.cs @@ -1,9 +1,15 @@ namespace PlanTempus.Components.Users.Create { - public class CreateUserCommand - { - public string Email { get; set; } - public string Password { get; set; } - public bool IsActive { get; set; } = true; - } + public interface ICommand + { + Guid CorrelationId { get; set; } + } + + public class CreateUserCommand : ICommand + { + public string Email { get; set; } + public string Password { get; set; } + public bool IsActive { get; set; } = true; + public required Guid CorrelationId { get; set; } + } } \ No newline at end of file diff --git a/PlanTempus.Components/Users/Create/CreateUserHandler.cs b/PlanTempus.Components/Users/Create/CreateUserHandler.cs index f716409..8c72b69 100644 --- a/PlanTempus.Components/Users/Create/CreateUserHandler.cs +++ b/PlanTempus.Components/Users/Create/CreateUserHandler.cs @@ -1,15 +1,22 @@ using Insight.Database; using Microsoft.ApplicationInsights; +using Npgsql; +using PlanTempus.Components.Users.Exceptions; using PlanTempus.Core; -using PlanTempus.Core.Sql; +using PlanTempus.Core.Database; using PlanTempus.Core.Telemetry; namespace PlanTempus.Components.Users.Create { + public interface ICommandHandler + { + Task Handle(T input); + } + public class CreateUserHandler( TelemetryClient telemetryClient, IDatabaseOperations databaseOperations, - ISecureTokenizer secureTokenizer) + ISecureTokenizer secureTokenizer) : ICommandHandler { public async Task Handle(CreateUserCommand command) { @@ -36,13 +43,17 @@ namespace PlanTempus.Components.Users.Create }); - db.Success(); var result = data.First(); telemetryClient.TrackTrace(GetType().Name, result.Format()); return result; } + catch (PostgresException ex) when (ex.SqlState == "23505") + { + db.Error(ex); + throw new EmailAlreadyRegistreredException(); + } catch (Exception ex) { db.Error(ex); diff --git a/PlanTempus.Components/Users/Create/CreateUserHandlerDecorator.cs b/PlanTempus.Components/Users/Create/CreateUserHandlerDecorator.cs new file mode 100644 index 0000000..06445cf --- /dev/null +++ b/PlanTempus.Components/Users/Create/CreateUserHandlerDecorator.cs @@ -0,0 +1,25 @@ +using Microsoft.ApplicationInsights; + +namespace PlanTempus.Components.Users.Create; + +public class CreateUserHandlerDecorator : ICommandHandler +{ + private readonly ICommandHandler _decoratedHandler; + private readonly TelemetryClient _telemetryClient; + + public CreateUserHandlerDecorator( + ICommandHandler decoratedHandler, + TelemetryClient telemetryClient) + { + _decoratedHandler = decoratedHandler; + _telemetryClient = telemetryClient; + } + + public async Task Handle(CreateUserCommand command) + { + _telemetryClient.TrackTrace($"Before handling {nameof(CreateUserCommand)}"); + var result = await _decoratedHandler.Handle(command); + _telemetryClient.TrackTrace($"After handling {nameof(CreateUserCommand)}"); + return result; + } +} diff --git a/PlanTempus.Components/Users/Exceptions/EmailAlreadyRegistreredException.cs b/PlanTempus.Components/Users/Exceptions/EmailAlreadyRegistreredException.cs new file mode 100644 index 0000000..c098df4 --- /dev/null +++ b/PlanTempus.Components/Users/Exceptions/EmailAlreadyRegistreredException.cs @@ -0,0 +1,6 @@ +namespace PlanTempus.Components.Users.Exceptions; + +public class EmailAlreadyRegistreredException: Exception +{ + +} \ No newline at end of file diff --git a/SetupInfrastructure/Program.cs b/SetupInfrastructure/Program.cs index febc5bf..130caa2 100644 --- a/SetupInfrastructure/Program.cs +++ b/SetupInfrastructure/Program.cs @@ -3,12 +3,12 @@ using Insight.Database; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Npgsql; -using PlanTempus.Core.Sql.ConnectionFactory; using PlanTempus.Database.ConfigurationManagementSystem; using PlanTempus.Database.Core.DCL; using PlanTempus.Database.Core.DDL; using System.Data; using System.Diagnostics; +using PlanTempus.Core.Database.ConnectionFactory; namespace PlanTempus.SetupInfrastructure { diff --git a/SetupInfrastructure/Startup.cs b/SetupInfrastructure/Startup.cs index 0ffec4d..d6a3daf 100644 --- a/SetupInfrastructure/Startup.cs +++ b/SetupInfrastructure/Startup.cs @@ -2,6 +2,7 @@ using PlanTempus.Core.Configurations; using PlanTempus.Core.Configurations.JsonConfigProvider; using PlanTempus.Core.ModuleRegistry; +using PlanTempus.Core.SeqLogging; using PlanTempus.Database.Core; namespace PlanTempus.SetupInfrastructure @@ -34,7 +35,7 @@ namespace PlanTempus.SetupInfrastructure builder.RegisterModule(new SeqLoggingModule { - SeqConfiguration = configuration.GetSection("SeqConfiguration").ToObject() + SeqConfiguration = configuration.GetSection("SeqConfiguration").ToObject() }); diff --git a/Tests/ConfigurationSystem/SetupConfigurationTests.cs b/Tests/ConfigurationSystem/SetupConfigurationTests.cs index df1cfec..e3b013c 100644 --- a/Tests/ConfigurationSystem/SetupConfigurationTests.cs +++ b/Tests/ConfigurationSystem/SetupConfigurationTests.cs @@ -2,7 +2,7 @@ using Autofac; using Insight.Database; using Newtonsoft.Json; -using PlanTempus.Core.Sql.ConnectionFactory; +using PlanTempus.Core.Database.ConnectionFactory; using Shouldly; namespace PlanTempus.X.TDD.ConfigurationSystem; diff --git a/Tests/ConfigurationTests/SmartConfigProviderTests.cs b/Tests/ConfigurationTests/SmartConfigProviderTests.cs index 2a351cf..56e7286 100644 --- a/Tests/ConfigurationTests/SmartConfigProviderTests.cs +++ b/Tests/ConfigurationTests/SmartConfigProviderTests.cs @@ -3,7 +3,7 @@ using Insight.Database; using PlanTempus.Core.Configurations; using PlanTempus.Core.Configurations.JsonConfigProvider; using PlanTempus.Core.Configurations.SmartConfigProvider; -using PlanTempus.Core.Sql.ConnectionFactory; +using PlanTempus.Core.Database.ConnectionFactory; using Shouldly; namespace PlanTempus.X.TDD.ConfigurationTests; diff --git a/Tests/Logging/SeqBackgroundServiceTest.cs b/Tests/Logging/SeqBackgroundServiceTest.cs index 05cfe7c..66ed1e7 100644 --- a/Tests/Logging/SeqBackgroundServiceTest.cs +++ b/Tests/Logging/SeqBackgroundServiceTest.cs @@ -3,7 +3,7 @@ using Autofac; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.Channel; using Microsoft.ApplicationInsights.DataContracts; -using PlanTempus.Core.Logging; +using PlanTempus.Core.SeqLogging; using PlanTempus.Core.Telemetry; namespace PlanTempus.X.TDD.Logging; diff --git a/Tests/Logging/SeqLoggerTests.cs b/Tests/Logging/SeqLoggerTests.cs index 25b6c04..acf16f9 100644 --- a/Tests/Logging/SeqLoggerTests.cs +++ b/Tests/Logging/SeqLoggerTests.cs @@ -1,7 +1,7 @@ using Autofac; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.DataContracts; -using PlanTempus.Core.Logging; +using PlanTempus.Core.SeqLogging; namespace PlanTempus.X.TDD.Logging; diff --git a/Tests/Logging/SeqTelemetryChannelTest.cs b/Tests/Logging/SeqTelemetryChannelTest.cs index cd8ceec..301e946 100644 --- a/Tests/Logging/SeqTelemetryChannelTest.cs +++ b/Tests/Logging/SeqTelemetryChannelTest.cs @@ -2,7 +2,7 @@ using Autofac; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.Channel; using Microsoft.ApplicationInsights.DataContracts; -using PlanTempus.Core.Logging; +using PlanTempus.Core.SeqLogging; using PlanTempus.Core.Telemetry; namespace PlanTempus.X.TDD.Logging; diff --git a/Tests/PlanTempus.X.TDD.csproj b/Tests/PlanTempus.X.TDD.csproj index 0277cef..ec3d895 100644 --- a/Tests/PlanTempus.X.TDD.csproj +++ b/Tests/PlanTempus.X.TDD.csproj @@ -20,6 +20,7 @@ + diff --git a/Tests/PostgresTests.cs b/Tests/PostgresTests.cs index 7d40669..b451bdb 100644 --- a/Tests/PostgresTests.cs +++ b/Tests/PostgresTests.cs @@ -1,7 +1,8 @@ using Autofac; using Insight.Database; -using PlanTempus.Core.Sql; -using PlanTempus.Core.Sql.ConnectionFactory; +using PlanTempus.Components.Users.Exceptions; +using PlanTempus.Core.Database; +using PlanTempus.Core.Database.ConnectionFactory; using Shouldly; namespace PlanTempus.X.TDD; @@ -38,8 +39,6 @@ public class PostgresTests : TestFixture { var user = await db.Connection.QuerySqlAsync( "SELECT tablename FROM pg_tables limit 5"); - - db.Success(); } catch (Exception ex) { @@ -56,8 +55,6 @@ public class PostgresTests : TestFixture { var user = await db.Connection.QuerySqlAsync( "SELECT tablename FROM pg_tables limit 5"); - - db.Success(); } catch (Exception ex) { @@ -69,7 +66,7 @@ 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, @@ -81,7 +78,7 @@ public class PostgresTests : TestFixture var parameters = new { - Email = "elon.musk@mars.com", + Email = "jarjarbinks22233@mars.com", PasswordHash = "MartianRover2025", SecurityStamp = "MarsOrBust", EmailConfirmed = true, @@ -92,19 +89,18 @@ public class PostgresTests : TestFixture var user = await db.Connection.QuerySqlAsync(sql, parameters); - user.ShouldNotBeNull(); - // ((string)user.email).ShouldBe("elon.musk@mars.com"); - // ((bool)user.is_active).ShouldBeTrue(); + // user.ShouldNotBeNull(); - db.Success(); - } - catch (Exception ex) - { - db.Error(ex); + //try insert, to test exception + var ex = await Should.ThrowAsync(async () => + await db.Connection.ExecuteAsync(sql, parameters)); } + // catch (Exception ex) + // { + // db.Error(ex); + // } } - [TestMethod] public async Task TestSimpleDatabaseOperation() { diff --git a/Tests/TestFixture.cs b/Tests/TestFixture.cs index 53385ac..382279a 100644 --- a/Tests/TestFixture.cs +++ b/Tests/TestFixture.cs @@ -4,8 +4,8 @@ using Microsoft.ApplicationInsights; using Microsoft.Extensions.Logging; using PlanTempus.Core.Configurations; using PlanTempus.Core.Configurations.JsonConfigProvider; -using PlanTempus.Core.Logging; using PlanTempus.Core.ModuleRegistry; +using PlanTempus.Core.SeqLogging; using PlanTempus.Database.ModuleRegistry; namespace PlanTempus.X.TDD;