From bd8d26cb100a3011d232e7326cf44a8c62157250 Mon Sep 17 00:00:00 2001 From: Max Vorchakov Date: Fri, 17 Nov 2023 17:48:37 +0100 Subject: [PATCH] Added Directory.Build.props; removed obsolete code; minor changes (#49) --- .gitignore | 6 +- Directory.Build.props | 18 +++++ .../PowerPipe.Sample/PowerPipe.Sample.csproj | 2 + ...nsions.MicrosoftDependencyInjection.csproj | 15 ---- .../ServiceCollectionExtension.cs | 69 +------------------ .../Builder/Steps/CompensationStep.cs | 14 +--- src/PowerPipe/Builder/Steps/InternalStep.cs | 13 +--- src/PowerPipe/Pipeline.cs | 15 +--- src/PowerPipe/PowerPipe.csproj | 15 ---- .../Fixtures/AutoDIFixture.cs | 24 ------- .../PowerPipe.UnitTests/Fixtures/DIFixture.cs | 27 -------- tests/PowerPipe.UnitTests/PipelineDITests.cs | 48 ------------- ...cs => PipelineDependencyInjectionTests.cs} | 26 ++++++- tests/PowerPipe.UnitTests/PipelineTests.cs | 3 +- .../PowerPipe.UnitTests.csproj | 2 +- 15 files changed, 59 insertions(+), 238 deletions(-) create mode 100644 Directory.Build.props delete mode 100644 tests/PowerPipe.UnitTests/Fixtures/AutoDIFixture.cs delete mode 100644 tests/PowerPipe.UnitTests/Fixtures/DIFixture.cs delete mode 100644 tests/PowerPipe.UnitTests/PipelineDITests.cs rename tests/PowerPipe.UnitTests/{PipelineAutoDITests.cs => PipelineDependencyInjectionTests.cs} (85%) diff --git a/.gitignore b/.gitignore index 8afdcb6..d43202e 100644 --- a/.gitignore +++ b/.gitignore @@ -145,9 +145,9 @@ _TeamCity* !.axoCover/settings.json # Coverlet is a free, cross platform Code Coverage Tool -coverage*.json -coverage*.xml -coverage*.info +*coverage*.json +*coverage*.xml +*coverage*.info # Visual Studio code coverage results *.coverage diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..7ff24a6 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,18 @@ + + + net6.0 + logo.png + true + + PowerPipe + Maksym Vorchakov + A library for .NET that uses a fluent interface to construct advanced workflows with ease + pipeline, powerpipe, pipe, builder, chain, chain-of-responsibility, workflow, workflow-engine + https://github.com/mvSapphire/PowerPipe + MIT + + + + + + \ No newline at end of file diff --git a/samples/PowerPipe.Sample/PowerPipe.Sample.csproj b/samples/PowerPipe.Sample/PowerPipe.Sample.csproj index 1ff7c2d..8e0f908 100644 --- a/samples/PowerPipe.Sample/PowerPipe.Sample.csproj +++ b/samples/PowerPipe.Sample/PowerPipe.Sample.csproj @@ -3,6 +3,8 @@ Exe net6.0 + false + false diff --git a/src/PowerPipe.Extensions.MicrosoftDependencyInjection/PowerPipe.Extensions.MicrosoftDependencyInjection.csproj b/src/PowerPipe.Extensions.MicrosoftDependencyInjection/PowerPipe.Extensions.MicrosoftDependencyInjection.csproj index 436575d..0ba0de0 100644 --- a/src/PowerPipe.Extensions.MicrosoftDependencyInjection/PowerPipe.Extensions.MicrosoftDependencyInjection.csproj +++ b/src/PowerPipe.Extensions.MicrosoftDependencyInjection/PowerPipe.Extensions.MicrosoftDependencyInjection.csproj @@ -3,23 +3,8 @@ net6.0 true - PowerPipe.Extensions.MicrosoftDependencyInjection - Maksym Vorchakov - PowerPipe - Dependency injection extensions for PowerPipe. - https://github.com/mvSapphire/PowerPipe - MIT - pipeline, powerpipe, pipe, di, dependency injection - logo.png - README.md - true - - - - - diff --git a/src/PowerPipe.Extensions.MicrosoftDependencyInjection/ServiceCollectionExtension.cs b/src/PowerPipe.Extensions.MicrosoftDependencyInjection/ServiceCollectionExtension.cs index 77effff..4df4ddb 100644 --- a/src/PowerPipe.Extensions.MicrosoftDependencyInjection/ServiceCollectionExtension.cs +++ b/src/PowerPipe.Extensions.MicrosoftDependencyInjection/ServiceCollectionExtension.cs @@ -1,6 +1,4 @@ using System; -using PowerPipe.Factories; -using PowerPipe.Interfaces; namespace Microsoft.Extensions.DependencyInjection; @@ -9,71 +7,6 @@ namespace Microsoft.Extensions.DependencyInjection; /// public static class ServiceCollectionExtension { - /// - /// Adds PowerPipe services to the DI container with the specified lifetime. - /// - /// The DI service collection to which services are added. - /// The lifetime of the added services (Transient, Scoped, or Singleton). - /// The modified DI service collection. - [Obsolete("Use new registration with PowerPipeConfiguration")] - public static IServiceCollection AddPowerPipe( - this IServiceCollection serviceCollection, ServiceLifetime lifetime = ServiceLifetime.Transient) - { - return lifetime switch - { - ServiceLifetime.Transient => serviceCollection.AddTransient(), - ServiceLifetime.Scoped => serviceCollection.AddScoped(), - ServiceLifetime.Singleton => serviceCollection.AddSingleton(), - _ => throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null) - }; - } - - /// - /// Adds a PowerPipe step to the DI container with the specified lifetime. - /// - /// The type of the step to add. - /// The type of context used in the pipeline. - /// The DI service collection to which the step is added. - /// The lifetime of the added step (Transient, Scoped, or Singleton). - /// The modified DI service collection. - [Obsolete("Use new registration with PowerPipeConfiguration")] - public static IServiceCollection AddPowerPipeStep( - this IServiceCollection serviceCollection, ServiceLifetime lifetime = ServiceLifetime.Transient) - where TStep : class, IStepBase - where TContext : class - { - return lifetime switch - { - ServiceLifetime.Transient => serviceCollection.AddTransient(), - ServiceLifetime.Scoped => serviceCollection.AddScoped(), - ServiceLifetime.Singleton => serviceCollection.AddSingleton(), - _ => throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null) - }; - } - - /// - /// Adds a PowerPipe compensation step to the DI container with the specified lifetime. - /// - /// The type of the compensation step to add. - /// The type of context used in the pipeline. - /// The DI service collection to which the compensation step is added. - /// The lifetime of the added compensation step (Transient, Scoped, or Singleton). - /// The modified DI service collection. - [Obsolete("Use new registration with PowerPipeConfiguration")] - public static IServiceCollection AddPowerPipeCompensationStep( - this IServiceCollection serviceCollection, ServiceLifetime lifetime = ServiceLifetime.Transient) - where TStep : class, IPipelineCompensationStep - where TContext : class - { - return lifetime switch - { - ServiceLifetime.Transient => serviceCollection.AddTransient(), - ServiceLifetime.Scoped => serviceCollection.AddScoped(), - ServiceLifetime.Singleton => serviceCollection.AddSingleton(), - _ => throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null) - }; - } - /// /// Registers Pipeline builder and Step types from the specified assemblies /// @@ -87,7 +20,7 @@ public static IServiceCollection AddPowerPipe( configuration.Invoke(serviceConfig); return services.AddPowerPipe(serviceConfig); } - + /// /// Registers Pipeline builder and Step types from the specified assemblies /// diff --git a/src/PowerPipe/Builder/Steps/CompensationStep.cs b/src/PowerPipe/Builder/Steps/CompensationStep.cs index dc11cdf..bdd735d 100644 --- a/src/PowerPipe/Builder/Steps/CompensationStep.cs +++ b/src/PowerPipe/Builder/Steps/CompensationStep.cs @@ -5,10 +5,7 @@ namespace PowerPipe.Builder.Steps; -/// -/// Represents a compensation step used in pipeline processing to perform compensation actions. -/// -/// The type of context used in the pipeline. +/// internal class CompensationStep : IPipelineCompensationStep { private readonly Lazy> _step; @@ -31,16 +28,11 @@ internal CompensationStep(Func> factory) }); } - /// - /// Performs compensation actions asynchronously. - /// - /// The context on which the compensation action is performed. - /// A cancellation token to cancel the operation. - /// A task representing the asynchronous compensation operation. + /// public async Task CompensateAsync(TContext context, CancellationToken cancellationToken) { IsCompensated = true; await _step.Value.CompensateAsync(context, cancellationToken); } -} \ No newline at end of file +} diff --git a/src/PowerPipe/Builder/Steps/InternalStep.cs b/src/PowerPipe/Builder/Steps/InternalStep.cs index 28adc2b..37412cc 100644 --- a/src/PowerPipe/Builder/Steps/InternalStep.cs +++ b/src/PowerPipe/Builder/Steps/InternalStep.cs @@ -12,9 +12,7 @@ namespace PowerPipe.Builder.Steps; /// The type of context used in the pipeline. internal abstract class InternalStep : IPipelineStep, IPipelineParallelStep { - /// - /// Gets or sets the next step in the pipeline. - /// + /// public IPipelineStep NextStep { get; set; } /// @@ -74,12 +72,7 @@ public void ConfigureErrorHandling(PipelineStepErrorHandling errorHandling, Time ErrorHandlingPredicate = predicate; } - /// - /// Executes the pipeline step asynchronously. - /// - /// The context on which the step operates. - /// A cancellation token to cancel the operation. - /// A task representing the asynchronous operation. + /// public async Task ExecuteAsync(TContext context, CancellationToken cancellationToken) { try @@ -166,4 +159,4 @@ public enum PipelineStepErrorHandling /// Retries the step execution in case of an error. /// Retry = 1, -} \ No newline at end of file +} diff --git a/src/PowerPipe/Pipeline.cs b/src/PowerPipe/Pipeline.cs index 84429c6..228e55a 100644 --- a/src/PowerPipe/Pipeline.cs +++ b/src/PowerPipe/Pipeline.cs @@ -5,11 +5,7 @@ namespace PowerPipe; -/// -/// Represents a pipeline for executing a series of steps. -/// -/// The type of context used in the pipeline. -/// The type of result returned by the pipeline. +/// public class Pipeline : IPipeline where TContext : PipelineContext where TResult : class @@ -31,12 +27,7 @@ public Pipeline(TContext context, IReadOnlyList> steps) SetupSteps(steps); } - /// - /// Runs the pipeline asynchronously with the option to return a result. - /// - /// A cancellation token to cancel the operation. - /// A flag indicating whether to return a result. - /// A task representing the asynchronous operation and optionally the result. + /// public async Task RunAsync(CancellationToken cancellationToken, bool returnResult = true) { await _initStep.ExecuteAsync(_context, cancellationToken); @@ -52,4 +43,4 @@ private static void SetupSteps(IReadOnlyList> steps) steps[i].NextStep = steps[i + 1]; } } -} \ No newline at end of file +} diff --git a/src/PowerPipe/PowerPipe.csproj b/src/PowerPipe/PowerPipe.csproj index 58426f0..1e159ee 100644 --- a/src/PowerPipe/PowerPipe.csproj +++ b/src/PowerPipe/PowerPipe.csproj @@ -3,23 +3,8 @@ net6.0 true - PowerPipe - Maksym Vorchakov - PowerPipe - A library for .NET that uses a fluent interface to construct advanced pipelines with ease. - https://github.com/mvSapphire/PowerPipe - MIT - pipeline, powerpipe, pipe, builder, chain, chain-of-responsibility - logo.png - README.md - true - - - - - diff --git a/tests/PowerPipe.UnitTests/Fixtures/AutoDIFixture.cs b/tests/PowerPipe.UnitTests/Fixtures/AutoDIFixture.cs deleted file mode 100644 index 373a87c..0000000 --- a/tests/PowerPipe.UnitTests/Fixtures/AutoDIFixture.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using Microsoft.Extensions.DependencyInjection; - -namespace PowerPipe.UnitTests.Fixtures; - -public sealed class AutoDIFixture : IDisposable -{ - public readonly IServiceCollection ServiceCollection; - - public AutoDIFixture() - { - var services = new ServiceCollection(); - services.AddPowerPipe(c => - { - c.RegisterServicesFromAssemblies(typeof(AutoDIFixture).Assembly); - }); - - ServiceCollection = services; - } - - public void Dispose() - { - } -} diff --git a/tests/PowerPipe.UnitTests/Fixtures/DIFixture.cs b/tests/PowerPipe.UnitTests/Fixtures/DIFixture.cs deleted file mode 100644 index 192ad47..0000000 --- a/tests/PowerPipe.UnitTests/Fixtures/DIFixture.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using Microsoft.Extensions.DependencyInjection; -using PowerPipe.UnitTests.Steps; - -namespace PowerPipe.UnitTests.Fixtures; - -public sealed class DIFixture : IDisposable -{ - public readonly IServiceCollection ServiceCollection; - - public DIFixture() - { - var services = new ServiceCollection(); - services.AddPowerPipe(); - services.AddPowerPipeStep(); - services.AddPowerPipeStep(); - services.AddPowerPipeStep, TestPipelineContext>(); - services.AddPowerPipeStep(); - services.AddPowerPipeCompensationStep(); - - ServiceCollection = services; - } - - public void Dispose() - { - } -} diff --git a/tests/PowerPipe.UnitTests/PipelineDITests.cs b/tests/PowerPipe.UnitTests/PipelineDITests.cs deleted file mode 100644 index 1cb3c17..0000000 --- a/tests/PowerPipe.UnitTests/PipelineDITests.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; -using FluentAssertions; -using Microsoft.Extensions.DependencyInjection; -using PowerPipe.Builder; -using PowerPipe.Exceptions; -using PowerPipe.Factories; -using PowerPipe.UnitTests.Fixtures; -using PowerPipe.UnitTests.Steps; -using Xunit; - -namespace PowerPipe.UnitTests; - -public class PipelineDITests : IClassFixture -{ - private readonly ServiceProvider _serviceProvider; - public PipelineDITests(DIFixture diFixture) - { - _serviceProvider = diFixture.ServiceCollection.BuildServiceProvider(); - } - - [Fact] - public async Task TestDI() - { - var context = new TestPipelineContext(); - var cts = new CancellationTokenSource(); - - var stepFactory = new PipelineStepFactory(_serviceProvider); - - var pipeline = new PipelineBuilder(stepFactory, context) - .Parallel(b => b - .Add()) - .Add() - .Add>() - .Add() - .CompensateWith() - .Build(); - - // To check that the compensation step was resolved and executed TestStep2 throws an exception - var action = () => pipeline.RunAsync(cts.Token); - await action.Should().ThrowAsync(); - - context.Step1RunCount.Should().Be(1); - context.GenericStepRunCount.Should().Be(1); - context.ParallelStepRunCount.Should().Be(1); - context.CompensationStepRunCount.Should().Be(1); - } -} diff --git a/tests/PowerPipe.UnitTests/PipelineAutoDITests.cs b/tests/PowerPipe.UnitTests/PipelineDependencyInjectionTests.cs similarity index 85% rename from tests/PowerPipe.UnitTests/PipelineAutoDITests.cs rename to tests/PowerPipe.UnitTests/PipelineDependencyInjectionTests.cs index 5f8067d..c7a2f35 100644 --- a/tests/PowerPipe.UnitTests/PipelineAutoDITests.cs +++ b/tests/PowerPipe.UnitTests/PipelineDependencyInjectionTests.cs @@ -1,3 +1,4 @@ +using System; using System.Threading; using System.Threading.Tasks; using FluentAssertions; @@ -5,16 +6,15 @@ using PowerPipe.Builder; using PowerPipe.Exceptions; using PowerPipe.Factories; -using PowerPipe.UnitTests.Fixtures; using PowerPipe.UnitTests.Steps; using Xunit; namespace PowerPipe.UnitTests; -public class PipelineAutoDITests : IClassFixture +public class PipelineDependencyInjectionTests : IClassFixture { private readonly ServiceProvider _serviceProvider; - public PipelineAutoDITests(AutoDIFixture diFixture) + public PipelineDependencyInjectionTests(AutoDIFixture diFixture) { _serviceProvider = diFixture.ServiceCollection.BuildServiceProvider(); } @@ -92,3 +92,23 @@ public void TestAutoDIRegistration() TestStep3.CreationCount.Should().Be(3); } } + +public sealed class AutoDIFixture : IDisposable +{ + public readonly IServiceCollection ServiceCollection; + + public AutoDIFixture() + { + var services = new ServiceCollection(); + services.AddPowerPipe(c => + { + c.RegisterServicesFromAssemblies(typeof(AutoDIFixture).Assembly); + }); + + ServiceCollection = services; + } + + public void Dispose() + { + } +} diff --git a/tests/PowerPipe.UnitTests/PipelineTests.cs b/tests/PowerPipe.UnitTests/PipelineTests.cs index ae0a0ba..4f8e49e 100644 --- a/tests/PowerPipe.UnitTests/PipelineTests.cs +++ b/tests/PowerPipe.UnitTests/PipelineTests.cs @@ -1,4 +1,5 @@ using System; +using System.Reflection; using System.Threading; using System.Threading.Tasks; using FluentAssertions; @@ -194,7 +195,7 @@ public async Task CompensateWith_Succeed() var stepFactory = new PipelineStepFactory(new ServiceCollection() - .AddPowerPipeStep() + .AddTransient() .AddTransient(_ => step2) .AddTransient(_ => compensationStep) .BuildServiceProvider()); diff --git a/tests/PowerPipe.UnitTests/PowerPipe.UnitTests.csproj b/tests/PowerPipe.UnitTests/PowerPipe.UnitTests.csproj index 1158f8a..821ef05 100644 --- a/tests/PowerPipe.UnitTests/PowerPipe.UnitTests.csproj +++ b/tests/PowerPipe.UnitTests/PowerPipe.UnitTests.csproj @@ -2,8 +2,8 @@ net6.0 - false + false