wip
This commit is contained in:
parent
f3ab94eff1
commit
31666b4ba0
34 changed files with 140 additions and 83 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
namespace PlanTempus.Core.Sql.ConnectionFactory
|
namespace PlanTempus.Core.Database.ConnectionFactory
|
||||||
{
|
{
|
||||||
public interface IDbConnectionFactory
|
public interface IDbConnectionFactory
|
||||||
{
|
{
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using Npgsql;
|
using System.Data;
|
||||||
using System.Data;
|
using Npgsql;
|
||||||
namespace PlanTempus.Core.Sql.ConnectionFactory
|
|
||||||
|
namespace PlanTempus.Core.Database.ConnectionFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
public record ConnectionStringParameters(string User, string Pwd);
|
public record ConnectionStringParameters(string User, string Pwd);
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
using Microsoft.ApplicationInsights.DataContracts;
|
using Microsoft.ApplicationInsights.DataContracts;
|
||||||
using Microsoft.ApplicationInsights.Extensibility;
|
using Microsoft.ApplicationInsights.Extensibility;
|
||||||
|
|
||||||
namespace PlanTempus.Core.Sql;
|
namespace PlanTempus.Core.Database;
|
||||||
|
|
||||||
public class DatabaseScope : IDisposable
|
public class DatabaseScope : IDisposable
|
||||||
{
|
{
|
||||||
|
|
@ -12,6 +12,7 @@ public class DatabaseScope : IDisposable
|
||||||
{
|
{
|
||||||
Connection = connection;
|
Connection = connection;
|
||||||
_operation = operation;
|
_operation = operation;
|
||||||
|
_operation.Telemetry.Success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDbConnection Connection { get; }
|
public IDbConnection Connection { get; }
|
||||||
|
|
@ -22,11 +23,6 @@ public class DatabaseScope : IDisposable
|
||||||
Connection.Dispose();
|
Connection.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Success()
|
|
||||||
{
|
|
||||||
_operation.Telemetry.Success = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Error(Exception ex)
|
public void Error(Exception ex)
|
||||||
{
|
{
|
||||||
_operation.Telemetry.Success = false;
|
_operation.Telemetry.Success = false;
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
|
||||||
namespace PlanTempus.Core.Sql;
|
namespace PlanTempus.Core.Database;
|
||||||
|
|
||||||
public interface IDatabaseOperations
|
public interface IDatabaseOperations
|
||||||
{
|
{
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using Microsoft.ApplicationInsights;
|
using Microsoft.ApplicationInsights;
|
||||||
using Microsoft.ApplicationInsights.DataContracts;
|
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
|
public class SqlOperations : IDatabaseOperations
|
||||||
{
|
{
|
||||||
|
|
@ -32,7 +32,6 @@ public class SqlOperations : IDatabaseOperations
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await operation(scope.Connection);
|
var result = await operation(scope.Connection);
|
||||||
scope.Success();
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -48,7 +47,6 @@ public class SqlOperations : IDatabaseOperations
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await operation(scope.Connection);
|
await operation(scope.Connection);
|
||||||
scope.Success();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using PlanTempus.Core.Logging;
|
using PlanTempus.Core.SeqLogging;
|
||||||
|
|
||||||
namespace PlanTempus.Core.ModuleRegistry
|
namespace PlanTempus.Core.ModuleRegistry
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,12 @@ namespace PlanTempus.Core.ModuleRegistry
|
||||||
|
|
||||||
protected override void Load(ContainerBuilder builder)
|
protected override void Load(ContainerBuilder builder)
|
||||||
{
|
{
|
||||||
|
|
||||||
var configuration = TelemetryConfiguration.CreateDefault();
|
var configuration = TelemetryConfiguration.CreateDefault();
|
||||||
configuration.ConnectionString = TelemetryConfig.ConnectionString;
|
configuration.ConnectionString = TelemetryConfig.ConnectionString;
|
||||||
configuration.TelemetryChannel.DeveloperMode = true;
|
configuration.TelemetryChannel.DeveloperMode = true;
|
||||||
|
|
||||||
var client = new Microsoft.ApplicationInsights.TelemetryClient(configuration);
|
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["MachineName"] = Environment.MachineName;
|
||||||
client.Context.GlobalProperties["Version"] = Environment.Version.ToString();
|
client.Context.GlobalProperties["Version"] = Environment.Version.ToString();
|
||||||
client.Context.GlobalProperties["ProcessorCount"] = Environment.ProcessorCount.ToString();
|
client.Context.GlobalProperties["ProcessorCount"] = Environment.ProcessorCount.ToString();
|
||||||
|
|
@ -34,10 +33,11 @@ namespace PlanTempus.Core.ModuleRegistry
|
||||||
configuration.TelemetryChannel = new Telemetry.SeqTelemetryChannel(messageChannel, client);
|
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.Use(next => new Telemetry.Enrichers.EnrichWithMetaTelemetry(next));
|
||||||
telemetryProcessorChain.Build();
|
telemetryProcessorChain.Build();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ using Microsoft.ApplicationInsights.DataContracts;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using PlanTempus.Core.Telemetry;
|
using PlanTempus.Core.Telemetry;
|
||||||
|
|
||||||
namespace PlanTempus.Core.Logging
|
namespace PlanTempus.Core.SeqLogging
|
||||||
{
|
{
|
||||||
public class SeqBackgroundService : BackgroundService
|
public class SeqBackgroundService : BackgroundService
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace PlanTempus.Core.Logging
|
namespace PlanTempus.Core.SeqLogging
|
||||||
{
|
{
|
||||||
public record SeqConfiguration(string IngestionEndpoint, string ApiKey, string Environment);
|
public record SeqConfiguration(string IngestionEndpoint, string ApiKey, string Environment);
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace PlanTempus.Core.Logging
|
namespace PlanTempus.Core.SeqLogging
|
||||||
{
|
{
|
||||||
public class SeqHttpClient
|
public class SeqHttpClient
|
||||||
{
|
{
|
||||||
|
|
@ -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<T>
|
public class SeqLogger<T>
|
||||||
{
|
{
|
||||||
private readonly SeqHttpClient _httpClient;
|
private readonly SeqHttpClient _httpClient;
|
||||||
private readonly string _environmentName;
|
|
||||||
private readonly string _machineName;
|
|
||||||
private readonly SeqConfiguration _configuration;
|
private readonly SeqConfiguration _configuration;
|
||||||
|
|
||||||
public SeqLogger(SeqHttpClient httpClient, SeqConfiguration configuration)
|
public SeqLogger(SeqHttpClient httpClient, SeqConfiguration configuration)
|
||||||
|
|
@ -23,8 +21,7 @@ namespace PlanTempus.Core.Logging
|
||||||
{ "@t", trace.Timestamp.UtcDateTime.ToString("o") },
|
{ "@t", trace.Timestamp.UtcDateTime.ToString("o") },
|
||||||
{ "@mt", trace.Message },
|
{ "@mt", trace.Message },
|
||||||
{ "@l", MapSeverityToLevel(trace.SeverityLevel) },
|
{ "@l", MapSeverityToLevel(trace.SeverityLevel) },
|
||||||
{ "Environment", _environmentName },
|
{ "Environment", _configuration.Environment },
|
||||||
{ "MachineName", _machineName }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var prop in trace.Properties)
|
foreach (var prop in trace.Properties)
|
||||||
|
|
@ -43,8 +40,7 @@ namespace PlanTempus.Core.Logging
|
||||||
{ "@t", evt.Timestamp.UtcDateTime.ToString("o") },
|
{ "@t", evt.Timestamp.UtcDateTime.ToString("o") },
|
||||||
{ "@mt", evt.Name },
|
{ "@mt", evt.Name },
|
||||||
{ "@l", "Information" },
|
{ "@l", "Information" },
|
||||||
{ "Environment", _environmentName },
|
{ "Environment", _configuration.Environment }
|
||||||
{ "MachineName", _machineName }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var prop in evt.Properties)
|
foreach (var prop in evt.Properties)
|
||||||
|
|
@ -67,9 +63,8 @@ namespace PlanTempus.Core.Logging
|
||||||
{ "@mt", ex.Exception.Message },
|
{ "@mt", ex.Exception.Message },
|
||||||
{ "@l", "Error" },
|
{ "@l", "Error" },
|
||||||
{ "@x", FormatExceptionForSeq(ex.Exception) },
|
{ "@x", FormatExceptionForSeq(ex.Exception) },
|
||||||
{ "Environment", _environmentName },
|
{ "Environment", _configuration.Environment },
|
||||||
{ "MachineName", _machineName },
|
{ "ExceptionType", ex.Exception.GetType().Name }
|
||||||
{ "ExceptionType", ex.Exception.GetType().Name },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var prop in ex.Properties)
|
foreach (var prop in ex.Properties)
|
||||||
|
|
@ -88,8 +83,7 @@ namespace PlanTempus.Core.Logging
|
||||||
{ "@t", dep.Timestamp.UtcDateTime.ToString("o") },
|
{ "@t", dep.Timestamp.UtcDateTime.ToString("o") },
|
||||||
{ "@mt", $"Dependency: {dep.Name}" },
|
{ "@mt", $"Dependency: {dep.Name}" },
|
||||||
{ "@l", dep.Success ?? true ? "Information" : "Error" },
|
{ "@l", dep.Success ?? true ? "Information" : "Error" },
|
||||||
{ "Environment", _environmentName },
|
{ "Environment", _configuration.Environment },
|
||||||
{ "MachineName", _machineName },
|
|
||||||
{ "DependencyType", dep.Type },
|
{ "DependencyType", dep.Type },
|
||||||
{ "Target", dep.Target },
|
{ "Target", dep.Target },
|
||||||
{ "Duration", dep.Duration.TotalMilliseconds }
|
{ "Duration", dep.Duration.TotalMilliseconds }
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using Insight.Database;
|
using Insight.Database;
|
||||||
using PlanTempus.Core.Sql.ConnectionFactory;
|
|
||||||
using PlanTempus.Database.Core;
|
using PlanTempus.Database.Core;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using PlanTempus.Core.Database.ConnectionFactory;
|
||||||
|
|
||||||
namespace PlanTempus.Database.ConfigurationManagementSystem;
|
namespace PlanTempus.Database.ConfigurationManagementSystem;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using Insight.Database;
|
using Insight.Database;
|
||||||
using PlanTempus.Core.Sql.ConnectionFactory;
|
using PlanTempus.Core.Database.ConnectionFactory;
|
||||||
using PlanTempus.Database.Common;
|
using PlanTempus.Database.Common;
|
||||||
|
|
||||||
namespace PlanTempus.Database.Core.DCL
|
namespace PlanTempus.Database.Core.DCL
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using Insight.Database;
|
using Insight.Database;
|
||||||
using PlanTempus.Core.Sql.ConnectionFactory;
|
using PlanTempus.Core.Database.ConnectionFactory;
|
||||||
using PlanTempus.Database.Common;
|
using PlanTempus.Database.Common;
|
||||||
|
|
||||||
namespace PlanTempus.Database.Core.DCL
|
namespace PlanTempus.Database.Core.DCL
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using Insight.Database;
|
using Insight.Database;
|
||||||
using PlanTempus.Core.Sql.ConnectionFactory;
|
using PlanTempus.Core.Database.ConnectionFactory;
|
||||||
using PlanTempus.Database.Common;
|
using PlanTempus.Database.Common;
|
||||||
using PlanTempus.Database.Core;
|
using PlanTempus.Database.Core;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Insight.Database;
|
using Insight.Database;
|
||||||
using PlanTempus.Core.Sql.ConnectionFactory;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using PlanTempus.Core.Database.ConnectionFactory;
|
||||||
|
|
||||||
namespace PlanTempus.Database.Core.DDL
|
namespace PlanTempus.Database.Core.DDL
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using PlanTempus.Core.Sql.ConnectionFactory;
|
using PlanTempus.Core.Database.ConnectionFactory;
|
||||||
|
|
||||||
namespace PlanTempus.Database.Core
|
namespace PlanTempus.Database.Core
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using PlanTempus.Core.Sql;
|
using PlanTempus.Core.Database;
|
||||||
using PlanTempus.Core.Sql.ConnectionFactory;
|
using PlanTempus.Core.Database.ConnectionFactory;
|
||||||
|
|
||||||
namespace PlanTempus.Database.ModuleRegistry
|
namespace PlanTempus.Database.ModuleRegistry
|
||||||
{
|
{
|
||||||
|
|
|
||||||
24
PlanTempus.Components/ModuleRegistry/SeqLoggingModule.cs
Normal file
24
PlanTempus.Components/ModuleRegistry/SeqLoggingModule.cs
Normal file
|
|
@ -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<TCommand>
|
||||||
|
builder.RegisterGenericDecorator(
|
||||||
|
typeof(LoggingCommandHandlerDecorator<>), // Din decorator-klasse
|
||||||
|
typeof(ICommandHandler<>)); // Interface, der skal dekoreres
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Insight.Database;
|
using Insight.Database;
|
||||||
using Microsoft.ApplicationInsights;
|
using Microsoft.ApplicationInsights;
|
||||||
using PlanTempus.Core.Sql;
|
using PlanTempus.Core.Database;
|
||||||
using PlanTempus.Core.Telemetry;
|
using PlanTempus.Core.Telemetry;
|
||||||
|
|
||||||
namespace PlanTempus.Components.Organizations.Create
|
namespace PlanTempus.Components.Organizations.Create
|
||||||
|
|
@ -32,8 +32,6 @@ namespace PlanTempus.Components.Organizations.Create
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
|
|
||||||
db.Success();
|
|
||||||
|
|
||||||
telemetryClient.TrackTrace(GetType().Name, orgResult.Format());
|
telemetryClient.TrackTrace(GetType().Name, orgResult.Format());
|
||||||
return orgResult;
|
return orgResult;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
namespace PlanTempus.Components.Users.Create
|
namespace PlanTempus.Components.Users.Create
|
||||||
{
|
{
|
||||||
public class CreateUserCommand
|
public interface ICommand
|
||||||
{
|
{
|
||||||
public string Email { get; set; }
|
Guid CorrelationId { get; set; }
|
||||||
public string Password { get; set; }
|
}
|
||||||
public bool IsActive { get; set; } = true;
|
|
||||||
}
|
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; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,15 +1,22 @@
|
||||||
using Insight.Database;
|
using Insight.Database;
|
||||||
using Microsoft.ApplicationInsights;
|
using Microsoft.ApplicationInsights;
|
||||||
|
using Npgsql;
|
||||||
|
using PlanTempus.Components.Users.Exceptions;
|
||||||
using PlanTempus.Core;
|
using PlanTempus.Core;
|
||||||
using PlanTempus.Core.Sql;
|
using PlanTempus.Core.Database;
|
||||||
using PlanTempus.Core.Telemetry;
|
using PlanTempus.Core.Telemetry;
|
||||||
|
|
||||||
namespace PlanTempus.Components.Users.Create
|
namespace PlanTempus.Components.Users.Create
|
||||||
{
|
{
|
||||||
|
public interface ICommandHandler<T, TResult>
|
||||||
|
{
|
||||||
|
Task<TResult> Handle(T input);
|
||||||
|
}
|
||||||
|
|
||||||
public class CreateUserHandler(
|
public class CreateUserHandler(
|
||||||
TelemetryClient telemetryClient,
|
TelemetryClient telemetryClient,
|
||||||
IDatabaseOperations databaseOperations,
|
IDatabaseOperations databaseOperations,
|
||||||
ISecureTokenizer secureTokenizer)
|
ISecureTokenizer secureTokenizer) : ICommandHandler<CreateUserCommand, CreateUserResult>
|
||||||
{
|
{
|
||||||
public async Task<CreateUserResult> Handle(CreateUserCommand command)
|
public async Task<CreateUserResult> Handle(CreateUserCommand command)
|
||||||
{
|
{
|
||||||
|
|
@ -36,13 +43,17 @@ namespace PlanTempus.Components.Users.Create
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
db.Success();
|
|
||||||
var result = data.First();
|
var result = data.First();
|
||||||
|
|
||||||
telemetryClient.TrackTrace(GetType().Name, result.Format());
|
telemetryClient.TrackTrace(GetType().Name, result.Format());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
catch (PostgresException ex) when (ex.SqlState == "23505")
|
||||||
|
{
|
||||||
|
db.Error(ex);
|
||||||
|
throw new EmailAlreadyRegistreredException();
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
db.Error(ex);
|
db.Error(ex);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
using Microsoft.ApplicationInsights;
|
||||||
|
|
||||||
|
namespace PlanTempus.Components.Users.Create;
|
||||||
|
|
||||||
|
public class CreateUserHandlerDecorator : ICommandHandler<CreateUserCommand, CreateUserResult>
|
||||||
|
{
|
||||||
|
private readonly ICommandHandler<CreateUserCommand, CreateUserResult> _decoratedHandler;
|
||||||
|
private readonly TelemetryClient _telemetryClient;
|
||||||
|
|
||||||
|
public CreateUserHandlerDecorator(
|
||||||
|
ICommandHandler<CreateUserCommand, CreateUserResult> decoratedHandler,
|
||||||
|
TelemetryClient telemetryClient)
|
||||||
|
{
|
||||||
|
_decoratedHandler = decoratedHandler;
|
||||||
|
_telemetryClient = telemetryClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<CreateUserResult> Handle(CreateUserCommand command)
|
||||||
|
{
|
||||||
|
_telemetryClient.TrackTrace($"Before handling {nameof(CreateUserCommand)}");
|
||||||
|
var result = await _decoratedHandler.Handle(command);
|
||||||
|
_telemetryClient.TrackTrace($"After handling {nameof(CreateUserCommand)}");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace PlanTempus.Components.Users.Exceptions;
|
||||||
|
|
||||||
|
public class EmailAlreadyRegistreredException: Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,12 +3,12 @@ using Insight.Database;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
using PlanTempus.Core.Sql.ConnectionFactory;
|
|
||||||
using PlanTempus.Database.ConfigurationManagementSystem;
|
using PlanTempus.Database.ConfigurationManagementSystem;
|
||||||
using PlanTempus.Database.Core.DCL;
|
using PlanTempus.Database.Core.DCL;
|
||||||
using PlanTempus.Database.Core.DDL;
|
using PlanTempus.Database.Core.DDL;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using PlanTempus.Core.Database.ConnectionFactory;
|
||||||
|
|
||||||
namespace PlanTempus.SetupInfrastructure
|
namespace PlanTempus.SetupInfrastructure
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
using PlanTempus.Core.Configurations;
|
using PlanTempus.Core.Configurations;
|
||||||
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
||||||
using PlanTempus.Core.ModuleRegistry;
|
using PlanTempus.Core.ModuleRegistry;
|
||||||
|
using PlanTempus.Core.SeqLogging;
|
||||||
using PlanTempus.Database.Core;
|
using PlanTempus.Database.Core;
|
||||||
|
|
||||||
namespace PlanTempus.SetupInfrastructure
|
namespace PlanTempus.SetupInfrastructure
|
||||||
|
|
@ -34,7 +35,7 @@ namespace PlanTempus.SetupInfrastructure
|
||||||
|
|
||||||
builder.RegisterModule(new SeqLoggingModule
|
builder.RegisterModule(new SeqLoggingModule
|
||||||
{
|
{
|
||||||
SeqConfiguration = configuration.GetSection("SeqConfiguration").ToObject<Core.Logging.SeqConfiguration>()
|
SeqConfiguration = configuration.GetSection("SeqConfiguration").ToObject<SeqConfiguration>()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Insight.Database;
|
using Insight.Database;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using PlanTempus.Core.Sql.ConnectionFactory;
|
using PlanTempus.Core.Database.ConnectionFactory;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace PlanTempus.X.TDD.ConfigurationSystem;
|
namespace PlanTempus.X.TDD.ConfigurationSystem;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using Insight.Database;
|
||||||
using PlanTempus.Core.Configurations;
|
using PlanTempus.Core.Configurations;
|
||||||
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
||||||
using PlanTempus.Core.Configurations.SmartConfigProvider;
|
using PlanTempus.Core.Configurations.SmartConfigProvider;
|
||||||
using PlanTempus.Core.Sql.ConnectionFactory;
|
using PlanTempus.Core.Database.ConnectionFactory;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace PlanTempus.X.TDD.ConfigurationTests;
|
namespace PlanTempus.X.TDD.ConfigurationTests;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using Autofac;
|
||||||
using Microsoft.ApplicationInsights;
|
using Microsoft.ApplicationInsights;
|
||||||
using Microsoft.ApplicationInsights.Channel;
|
using Microsoft.ApplicationInsights.Channel;
|
||||||
using Microsoft.ApplicationInsights.DataContracts;
|
using Microsoft.ApplicationInsights.DataContracts;
|
||||||
using PlanTempus.Core.Logging;
|
using PlanTempus.Core.SeqLogging;
|
||||||
using PlanTempus.Core.Telemetry;
|
using PlanTempus.Core.Telemetry;
|
||||||
|
|
||||||
namespace PlanTempus.X.TDD.Logging;
|
namespace PlanTempus.X.TDD.Logging;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Microsoft.ApplicationInsights;
|
using Microsoft.ApplicationInsights;
|
||||||
using Microsoft.ApplicationInsights.DataContracts;
|
using Microsoft.ApplicationInsights.DataContracts;
|
||||||
using PlanTempus.Core.Logging;
|
using PlanTempus.Core.SeqLogging;
|
||||||
|
|
||||||
namespace PlanTempus.X.TDD.Logging;
|
namespace PlanTempus.X.TDD.Logging;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ using Autofac;
|
||||||
using Microsoft.ApplicationInsights;
|
using Microsoft.ApplicationInsights;
|
||||||
using Microsoft.ApplicationInsights.Channel;
|
using Microsoft.ApplicationInsights.Channel;
|
||||||
using Microsoft.ApplicationInsights.DataContracts;
|
using Microsoft.ApplicationInsights.DataContracts;
|
||||||
using PlanTempus.Core.Logging;
|
using PlanTempus.Core.SeqLogging;
|
||||||
using PlanTempus.Core.Telemetry;
|
using PlanTempus.Core.Telemetry;
|
||||||
|
|
||||||
namespace PlanTempus.X.TDD.Logging;
|
namespace PlanTempus.X.TDD.Logging;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Application\PlanTempus.Application.csproj"/>
|
<ProjectReference Include="..\Application\PlanTempus.Application.csproj"/>
|
||||||
<ProjectReference Include="..\Database\PlanTempus.Database.csproj"/>
|
<ProjectReference Include="..\Database\PlanTempus.Database.csproj"/>
|
||||||
|
<ProjectReference Include="..\PlanTempus.Components\PlanTempus.Components.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Insight.Database;
|
using Insight.Database;
|
||||||
using PlanTempus.Core.Sql;
|
using PlanTempus.Components.Users.Exceptions;
|
||||||
using PlanTempus.Core.Sql.ConnectionFactory;
|
using PlanTempus.Core.Database;
|
||||||
|
using PlanTempus.Core.Database.ConnectionFactory;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace PlanTempus.X.TDD;
|
namespace PlanTempus.X.TDD;
|
||||||
|
|
@ -38,8 +39,6 @@ public class PostgresTests : TestFixture
|
||||||
{
|
{
|
||||||
var user = await db.Connection.QuerySqlAsync<string>(
|
var user = await db.Connection.QuerySqlAsync<string>(
|
||||||
"SELECT tablename FROM pg_tables limit 5");
|
"SELECT tablename FROM pg_tables limit 5");
|
||||||
|
|
||||||
db.Success();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -56,8 +55,6 @@ public class PostgresTests : TestFixture
|
||||||
{
|
{
|
||||||
var user = await db.Connection.QuerySqlAsync<string>(
|
var user = await db.Connection.QuerySqlAsync<string>(
|
||||||
"SELECT tablename FROM pg_tables limit 5");
|
"SELECT tablename FROM pg_tables limit 5");
|
||||||
|
|
||||||
db.Success();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -69,7 +66,7 @@ public class PostgresTests : TestFixture
|
||||||
public async Task TestForUniqueUserEmail()
|
public async Task TestForUniqueUserEmail()
|
||||||
{
|
{
|
||||||
using var db = _databaseOperations.CreateScope(nameof(TestForUniqueUserEmail));
|
using var db = _databaseOperations.CreateScope(nameof(TestForUniqueUserEmail));
|
||||||
try
|
// try
|
||||||
{
|
{
|
||||||
var sql = @"
|
var sql = @"
|
||||||
INSERT INTO system.users(email, password_hash, security_stamp, email_confirmed,
|
INSERT INTO system.users(email, password_hash, security_stamp, email_confirmed,
|
||||||
|
|
@ -81,7 +78,7 @@ public class PostgresTests : TestFixture
|
||||||
|
|
||||||
var parameters = new
|
var parameters = new
|
||||||
{
|
{
|
||||||
Email = "elon.musk@mars.com",
|
Email = "jarjarbinks22233@mars.com",
|
||||||
PasswordHash = "MartianRover2025",
|
PasswordHash = "MartianRover2025",
|
||||||
SecurityStamp = "MarsOrBust",
|
SecurityStamp = "MarsOrBust",
|
||||||
EmailConfirmed = true,
|
EmailConfirmed = true,
|
||||||
|
|
@ -92,19 +89,18 @@ public class PostgresTests : TestFixture
|
||||||
|
|
||||||
var user = await db.Connection.QuerySqlAsync<dynamic>(sql, parameters);
|
var user = await db.Connection.QuerySqlAsync<dynamic>(sql, parameters);
|
||||||
|
|
||||||
user.ShouldNotBeNull();
|
// user.ShouldNotBeNull();
|
||||||
// ((string)user.email).ShouldBe("elon.musk@mars.com");
|
|
||||||
// ((bool)user.is_active).ShouldBeTrue();
|
|
||||||
|
|
||||||
db.Success();
|
//try insert, to test exception
|
||||||
}
|
var ex = await Should.ThrowAsync<EmailAlreadyRegistreredException>(async () =>
|
||||||
catch (Exception ex)
|
await db.Connection.ExecuteAsync(sql, parameters));
|
||||||
{
|
|
||||||
db.Error(ex);
|
|
||||||
}
|
}
|
||||||
|
// catch (Exception ex)
|
||||||
|
// {
|
||||||
|
// db.Error(ex);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task TestSimpleDatabaseOperation()
|
public async Task TestSimpleDatabaseOperation()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ using Microsoft.ApplicationInsights;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PlanTempus.Core.Configurations;
|
using PlanTempus.Core.Configurations;
|
||||||
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
||||||
using PlanTempus.Core.Logging;
|
|
||||||
using PlanTempus.Core.ModuleRegistry;
|
using PlanTempus.Core.ModuleRegistry;
|
||||||
|
using PlanTempus.Core.SeqLogging;
|
||||||
using PlanTempus.Database.ModuleRegistry;
|
using PlanTempus.Database.ModuleRegistry;
|
||||||
|
|
||||||
namespace PlanTempus.X.TDD;
|
namespace PlanTempus.X.TDD;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue