From 1898b60697b6dc8a3d95dcea4b733a88c0f4a559 Mon Sep 17 00:00:00 2001 From: "Frank R. Haugen" Date: Sun, 31 Dec 2023 04:02:15 +0100 Subject: [PATCH] Remove benchmark and CLI tests projects The projects Frank.PulseFlow.Tests.Benchmarks and Frank.PulseFlow.Tests.Cli have been removed as they were unnecessary. Some minor refactoring has been done to the logging feature, including added support for logging scopes. --- Frank.PulseFlow.Logging/LogPulse.cs | 18 ++++--------- Frank.PulseFlow.Logging/PulseFlowLogger.cs | 6 +---- .../PulseFlowLoggerScope.cs | 10 +++++++ .../ServiceCollectionExtensions.cs | 6 ++++- .../Benchmarks.cs | 21 --------------- .../Frank.PulseFlow.Tests.Benchmarks.csproj | 27 ------------------- Frank.PulseFlow.Tests.Benchmarks/Program.cs | 17 ------------ .../Shared/PersistenceService.cs | 6 ----- .../Traditional/MyTraditionalService.cs | 6 ----- .../Frank.PulseFlow.Tests.Cli.csproj | 16 ----------- .../NotificationPulse.cs | 7 ----- Frank.PulseFlow.Tests.Cli/Program.cs | 17 ------------ .../Properties/launchSettings.json | 12 --------- Frank.PulseFlow.Tests.Cli/TestingService.cs | 18 ------------- Frank.PulseFlow.Tests.Cli/TextFlow.cs | 17 ------------ Frank.PulseFlow.Tests.Cli/TextPulse.cs | 6 ----- .../appsettings.Development.json | 8 ------ Frank.PulseFlow.Tests.Cli/appsettings.json | 8 ------ .../{UnitTest1.cs => PulseFlowTests.cs} | 1 - Frank.PulseFlow.sln | 12 --------- 20 files changed, 21 insertions(+), 218 deletions(-) create mode 100644 Frank.PulseFlow.Logging/PulseFlowLoggerScope.cs delete mode 100644 Frank.PulseFlow.Tests.Benchmarks/Benchmarks.cs delete mode 100644 Frank.PulseFlow.Tests.Benchmarks/Frank.PulseFlow.Tests.Benchmarks.csproj delete mode 100644 Frank.PulseFlow.Tests.Benchmarks/Program.cs delete mode 100644 Frank.PulseFlow.Tests.Benchmarks/Shared/PersistenceService.cs delete mode 100644 Frank.PulseFlow.Tests.Benchmarks/Traditional/MyTraditionalService.cs delete mode 100644 Frank.PulseFlow.Tests.Cli/Frank.PulseFlow.Tests.Cli.csproj delete mode 100644 Frank.PulseFlow.Tests.Cli/NotificationPulse.cs delete mode 100644 Frank.PulseFlow.Tests.Cli/Program.cs delete mode 100644 Frank.PulseFlow.Tests.Cli/Properties/launchSettings.json delete mode 100644 Frank.PulseFlow.Tests.Cli/TestingService.cs delete mode 100644 Frank.PulseFlow.Tests.Cli/TextFlow.cs delete mode 100644 Frank.PulseFlow.Tests.Cli/TextPulse.cs delete mode 100644 Frank.PulseFlow.Tests.Cli/appsettings.Development.json delete mode 100644 Frank.PulseFlow.Tests.Cli/appsettings.json rename Frank.PulseFlow.Tests/{UnitTest1.cs => PulseFlowTests.cs} (97%) diff --git a/Frank.PulseFlow.Logging/LogPulse.cs b/Frank.PulseFlow.Logging/LogPulse.cs index 9668bf1..7a1c6f0 100644 --- a/Frank.PulseFlow.Logging/LogPulse.cs +++ b/Frank.PulseFlow.Logging/LogPulse.cs @@ -2,20 +2,12 @@ namespace Frank.PulseFlow.Logging; -public abstract class LogPulse : BasePulse +public class LogPulse : BasePulse { - public abstract LogLevel LogLevel { get; } - public abstract EventId EventId { get; } - public abstract Exception? Exception { get; } - public abstract string CategoryName { get; } -} -public class LogPulse : LogPulse -{ - public override LogLevel LogLevel { get; } - public override EventId EventId { get; } - public override Exception? Exception { get; } - public override string CategoryName { get; } - + public LogLevel LogLevel { get; } + public EventId EventId { get; } + public Exception? Exception { get; } + public string CategoryName { get; } public TState State { get; } public Func Formatter { get; } diff --git a/Frank.PulseFlow.Logging/PulseFlowLogger.cs b/Frank.PulseFlow.Logging/PulseFlowLogger.cs index e051719..1482d15 100644 --- a/Frank.PulseFlow.Logging/PulseFlowLogger.cs +++ b/Frank.PulseFlow.Logging/PulseFlowLogger.cs @@ -39,9 +39,5 @@ public bool IsEnabled(LogLevel logLevel) return logLevel >= filterOptions.MinLevel; } - public IDisposable? BeginScope(TState state) where TState : notnull - { - // no scope support - return null; - } + public IDisposable? BeginScope(TState state) where TState : notnull => new PulseFlowLoggerScope(state); } \ No newline at end of file diff --git a/Frank.PulseFlow.Logging/PulseFlowLoggerScope.cs b/Frank.PulseFlow.Logging/PulseFlowLoggerScope.cs new file mode 100644 index 0000000..c67d400 --- /dev/null +++ b/Frank.PulseFlow.Logging/PulseFlowLoggerScope.cs @@ -0,0 +1,10 @@ +namespace Frank.PulseFlow.Logging; + +public class PulseFlowLoggerScope : IDisposable +{ + public TState? State { get; private set; } + + public PulseFlowLoggerScope(TState state) => State = state; + + public void Dispose() => State = default; +} \ No newline at end of file diff --git a/Frank.PulseFlow.Logging/ServiceCollectionExtensions.cs b/Frank.PulseFlow.Logging/ServiceCollectionExtensions.cs index 919038b..7435767 100644 --- a/Frank.PulseFlow.Logging/ServiceCollectionExtensions.cs +++ b/Frank.PulseFlow.Logging/ServiceCollectionExtensions.cs @@ -1,11 +1,15 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; namespace Frank.PulseFlow.Logging; public static class LoggingBuilderExtensions { + /// + /// Adds PulseFlow logger provider to the logging builder. + /// + /// The logging builder. + /// The updated logging builder. public static ILoggingBuilder AddPulseFlow(this ILoggingBuilder builder) { builder.Services.AddSingleton(); diff --git a/Frank.PulseFlow.Tests.Benchmarks/Benchmarks.cs b/Frank.PulseFlow.Tests.Benchmarks/Benchmarks.cs deleted file mode 100644 index 50ef8b7..0000000 --- a/Frank.PulseFlow.Tests.Benchmarks/Benchmarks.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -using BenchmarkDotNet; -using BenchmarkDotNet.Attributes; - -namespace Frank.PulseFlow.Tests.Benchmarks; - -public class Benchmarks -{ - [Benchmark] - public void Scenario1() - { - // Implement your benchmark here - } - - [Benchmark] - public void Scenario2() - { - // Implement your benchmark here - } -} \ No newline at end of file diff --git a/Frank.PulseFlow.Tests.Benchmarks/Frank.PulseFlow.Tests.Benchmarks.csproj b/Frank.PulseFlow.Tests.Benchmarks/Frank.PulseFlow.Tests.Benchmarks.csproj deleted file mode 100644 index 9d982ad..0000000 --- a/Frank.PulseFlow.Tests.Benchmarks/Frank.PulseFlow.Tests.Benchmarks.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - Exe - true - false - - - AnyCPU - pdbonly - true - true - true - Release - false - - - - - - - - - - - - - \ No newline at end of file diff --git a/Frank.PulseFlow.Tests.Benchmarks/Program.cs b/Frank.PulseFlow.Tests.Benchmarks/Program.cs deleted file mode 100644 index 26728e3..0000000 --- a/Frank.PulseFlow.Tests.Benchmarks/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -using BenchmarkDotNet.Configs; -using BenchmarkDotNet.Reports; -using BenchmarkDotNet.Running; - -namespace Frank.PulseFlow.Tests.Benchmarks; - -public class Program -{ - public static void Main(string[] args) - { - IConfig? config = DefaultConfig.Instance; - Summary? summary = BenchmarkRunner.Run(config, args); - - // Use this to select benchmarks from the console: - // var summaries = BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); - } -} \ No newline at end of file diff --git a/Frank.PulseFlow.Tests.Benchmarks/Shared/PersistenceService.cs b/Frank.PulseFlow.Tests.Benchmarks/Shared/PersistenceService.cs deleted file mode 100644 index fc61f29..0000000 --- a/Frank.PulseFlow.Tests.Benchmarks/Shared/PersistenceService.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Frank.PulseFlow.Tests.Benchmarks.Shared; - -public class PersistenceService -{ - -} \ No newline at end of file diff --git a/Frank.PulseFlow.Tests.Benchmarks/Traditional/MyTraditionalService.cs b/Frank.PulseFlow.Tests.Benchmarks/Traditional/MyTraditionalService.cs deleted file mode 100644 index fbcf61d..0000000 --- a/Frank.PulseFlow.Tests.Benchmarks/Traditional/MyTraditionalService.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Frank.PulseFlow.Tests.Benchmarks.Traditional; - -public class MyTraditionalService -{ - -} \ No newline at end of file diff --git a/Frank.PulseFlow.Tests.Cli/Frank.PulseFlow.Tests.Cli.csproj b/Frank.PulseFlow.Tests.Cli/Frank.PulseFlow.Tests.Cli.csproj deleted file mode 100644 index a993ead..0000000 --- a/Frank.PulseFlow.Tests.Cli/Frank.PulseFlow.Tests.Cli.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - true - false - dotnet-Frank.PulseFlow.Tests.Cli-6411a286-dfbb-4d8c-b48a-184038a5a93c - - - - - - - - - - diff --git a/Frank.PulseFlow.Tests.Cli/NotificationPulse.cs b/Frank.PulseFlow.Tests.Cli/NotificationPulse.cs deleted file mode 100644 index 06efa39..0000000 --- a/Frank.PulseFlow.Tests.Cli/NotificationPulse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Frank.PulseFlow.Tests.Cli; - -public class NotificationPulse : BasePulse -{ - public string Title { get; set; } - public string Body { get; set; } -} \ No newline at end of file diff --git a/Frank.PulseFlow.Tests.Cli/Program.cs b/Frank.PulseFlow.Tests.Cli/Program.cs deleted file mode 100644 index 8c26639..0000000 --- a/Frank.PulseFlow.Tests.Cli/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Frank.PulseFlow; -using Frank.PulseFlow.Tests.Cli; - -IHostBuilder builder = Host.CreateDefaultBuilder(); - -builder.ConfigureServices((context, services) => -{ - services.AddPulseFlow(messagingBuilder => - { - messagingBuilder.AddFlow(); - }); - services.AddHostedService(); -}); - -IHost app = builder.Build(); - -await app.RunAsync(); \ No newline at end of file diff --git a/Frank.PulseFlow.Tests.Cli/Properties/launchSettings.json b/Frank.PulseFlow.Tests.Cli/Properties/launchSettings.json deleted file mode 100644 index 46e3d28..0000000 --- a/Frank.PulseFlow.Tests.Cli/Properties/launchSettings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "profiles": { - "Frank.PulseFlow.Tests.Cli": { - "commandName": "Project", - "dotnetRunMessages": true, - "environmentVariables": { - "DOTNET_ENVIRONMENT": "Development" - } - } - } -} diff --git a/Frank.PulseFlow.Tests.Cli/TestingService.cs b/Frank.PulseFlow.Tests.Cli/TestingService.cs deleted file mode 100644 index 6dd79b7..0000000 --- a/Frank.PulseFlow.Tests.Cli/TestingService.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Frank.PulseFlow.Tests.Cli; - -public class TestingService : BackgroundService -{ - private readonly IConduit _messenger; - - public TestingService(IConduit messenger) => _messenger = messenger; - - protected override async Task ExecuteAsync(CancellationToken stoppingToken) - { - await Task.Delay(2000, stoppingToken); - while (!stoppingToken.IsCancellationRequested) - { - await _messenger.SendAsync(new TextPulse { Id = Guid.NewGuid(), Text = "Hello World" }); - await Task.Delay(1000, stoppingToken); - } - } -} \ No newline at end of file diff --git a/Frank.PulseFlow.Tests.Cli/TextFlow.cs b/Frank.PulseFlow.Tests.Cli/TextFlow.cs deleted file mode 100644 index 3737858..0000000 --- a/Frank.PulseFlow.Tests.Cli/TextFlow.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Frank.PulseFlow.Tests.Cli; - -public class TextFlow : IFlow -{ - private readonly ILogger _logger; - - public TextFlow(ILogger logger) => _logger = logger; - - public async Task HandleAsync(IPulse message, CancellationToken cancellationToken) - { - if (message is TextPulse textMessage) - _logger.LogInformation("Received text message: {Text}", textMessage.Text); - await Task.CompletedTask; - } - - public bool CanHandle(Type pulseType) => pulseType == typeof(TextPulse); -} \ No newline at end of file diff --git a/Frank.PulseFlow.Tests.Cli/TextPulse.cs b/Frank.PulseFlow.Tests.Cli/TextPulse.cs deleted file mode 100644 index 187b4db..0000000 --- a/Frank.PulseFlow.Tests.Cli/TextPulse.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Frank.PulseFlow.Tests.Cli; - -public class TextPulse : BasePulse -{ - public string Text { get; set; } -} \ No newline at end of file diff --git a/Frank.PulseFlow.Tests.Cli/appsettings.Development.json b/Frank.PulseFlow.Tests.Cli/appsettings.Development.json deleted file mode 100644 index b2dcdb6..0000000 --- a/Frank.PulseFlow.Tests.Cli/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git a/Frank.PulseFlow.Tests.Cli/appsettings.json b/Frank.PulseFlow.Tests.Cli/appsettings.json deleted file mode 100644 index b2dcdb6..0000000 --- a/Frank.PulseFlow.Tests.Cli/appsettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git a/Frank.PulseFlow.Tests/UnitTest1.cs b/Frank.PulseFlow.Tests/PulseFlowTests.cs similarity index 97% rename from Frank.PulseFlow.Tests/UnitTest1.cs rename to Frank.PulseFlow.Tests/PulseFlowTests.cs index 7bfabcf..e2453ca 100644 --- a/Frank.PulseFlow.Tests/UnitTest1.cs +++ b/Frank.PulseFlow.Tests/PulseFlowTests.cs @@ -52,7 +52,6 @@ private IHostBuilder CreateHostBuilder() services.AddPulseFlow(builder => { builder.AddFlow(); - // builder.AddFlow(); }); services.AddHostedService(); diff --git a/Frank.PulseFlow.sln b/Frank.PulseFlow.sln index 35a80ad..c300b07 100644 --- a/Frank.PulseFlow.sln +++ b/Frank.PulseFlow.sln @@ -7,10 +7,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frank.PulseFlow", "Frank.Pu EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frank.PulseFlow.Tests", "Frank.PulseFlow.Tests\Frank.PulseFlow.Tests.csproj", "{CDFBB79A-4D36-4C6C-865A-EC6A48EEA08E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frank.PulseFlow.Tests.Benchmarks", "Frank.PulseFlow.Tests.Benchmarks\Frank.PulseFlow.Tests.Benchmarks.csproj", "{31BB9094-E736-45DC-9310-386921878506}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frank.PulseFlow.Tests.Cli", "Frank.PulseFlow.Tests.Cli\Frank.PulseFlow.Tests.Cli.csproj", "{A2981338-9563-49BD-BE39-EDFD759C39D7}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F0BA9824-F862-4CCF-A326-7E5AB567F9E4}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig @@ -43,14 +39,6 @@ Global {CDFBB79A-4D36-4C6C-865A-EC6A48EEA08E}.Debug|Any CPU.Build.0 = Debug|Any CPU {CDFBB79A-4D36-4C6C-865A-EC6A48EEA08E}.Release|Any CPU.ActiveCfg = Release|Any CPU {CDFBB79A-4D36-4C6C-865A-EC6A48EEA08E}.Release|Any CPU.Build.0 = Release|Any CPU - {31BB9094-E736-45DC-9310-386921878506}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {31BB9094-E736-45DC-9310-386921878506}.Debug|Any CPU.Build.0 = Debug|Any CPU - {31BB9094-E736-45DC-9310-386921878506}.Release|Any CPU.ActiveCfg = Release|Any CPU - {31BB9094-E736-45DC-9310-386921878506}.Release|Any CPU.Build.0 = Release|Any CPU - {A2981338-9563-49BD-BE39-EDFD759C39D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A2981338-9563-49BD-BE39-EDFD759C39D7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A2981338-9563-49BD-BE39-EDFD759C39D7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A2981338-9563-49BD-BE39-EDFD759C39D7}.Release|Any CPU.Build.0 = Release|Any CPU {37DF9EE8-CDF2-430C-B407-D9546088D890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {37DF9EE8-CDF2-430C-B407-D9546088D890}.Debug|Any CPU.Build.0 = Debug|Any CPU {37DF9EE8-CDF2-430C-B407-D9546088D890}.Release|Any CPU.ActiveCfg = Release|Any CPU