diff --git a/.editorconfig b/.editorconfig index cb8910a..deceb67 100644 --- a/.editorconfig +++ b/.editorconfig @@ -218,6 +218,9 @@ csharp_style_prefer_pattern_matching = true:silent csharp_style_prefer_not_pattern = true:suggestion csharp_style_prefer_extended_property_pattern = true:suggestion +[*.cs] +dotnet_diagnostic.SA1402.severity = none + # Xml project files [*.{csproj,props,targets}] indent_size = 2 diff --git a/Streamistry.Core/ExceptionRouterPipe.cs b/Streamistry.Core/ExceptionRouterPipe.cs index 44c28ee..011a33c 100644 --- a/Streamistry.Core/ExceptionRouterPipe.cs +++ b/Streamistry.Core/ExceptionRouterPipe.cs @@ -16,7 +16,7 @@ public ExceptionRouterPipe(IChainablePort? upstream) [Trace] public override void Emit(TInput obj) { - if (TryCatchInvoke(obj, out var value, out var exception)) + if (TryCatchInvoke(obj, out var value, out var _)) PushDownstream(value); else Alternate.PushDownstream(obj); diff --git a/Streamistry.Core/Fluent/ParserBuilder.cs b/Streamistry.Core/Fluent/ParserBuilder.cs index 0b56634..2a90321 100644 --- a/Streamistry.Core/Fluent/ParserBuilder.cs +++ b/Streamistry.Core/Fluent/ParserBuilder.cs @@ -40,9 +40,9 @@ public ParserBuilder(IPipeBuilder upstream) => Upstream = upstream; public SpecializedParserBuilder AsDate() - => new SpecializedParserBuilder(Upstream, typeof(DateParser), FormatProvider); + => new (Upstream, typeof(DateParser), FormatProvider); public SpecializedParserBuilder AsDateTime() - => new SpecializedParserBuilder(Upstream, typeof(DateTimeParser), FormatProvider); + => new (Upstream, typeof(DateTimeParser), FormatProvider); public ParserBuilder WithFormatProvider(IFormatProvider formatProvider) { diff --git a/Streamistry.Core/OutputPort.cs b/Streamistry.Core/OutputPort.cs index 14d4854..78e0598 100644 --- a/Streamistry.Core/OutputPort.cs +++ b/Streamistry.Core/OutputPort.cs @@ -27,7 +27,7 @@ public void PushDownstream(T? obj) => Downstream?.Invoke(obj); public Action[] GetDownstreamInvocations() - => Downstream?.GetInvocationList().Cast>().ToArray() ?? Array.Empty>(); + => Downstream?.GetInvocationList().Cast>().ToArray() ?? []; } public class MainOutputPort : OutputPort diff --git a/Streamistry.Core/Pipes/Mappers/Caster.cs b/Streamistry.Core/Pipes/Mappers/Caster.cs index 8afb1a8..a9e4dfe 100644 --- a/Streamistry.Core/Pipes/Mappers/Caster.cs +++ b/Streamistry.Core/Pipes/Mappers/Caster.cs @@ -62,8 +62,6 @@ public static bool HasInheritanceConversion() } return null; } - - } public class Caster : Mapper diff --git a/Streamistry.Testing/Fluent/PipelineBuilderTests.cs b/Streamistry.Testing/Fluent/PipelineBuilderTests.cs index 8644ebb..5b7b61d 100644 --- a/Streamistry.Testing/Fluent/PipelineBuilderTests.cs +++ b/Streamistry.Testing/Fluent/PipelineBuilderTests.cs @@ -62,8 +62,11 @@ public void Build_FilterCheckpoint_Success() .Filter(x => x % 2 != 0).Checkpoint(out var filter) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(filter, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(filter, Is.Not.Null); + }); var output = filter.GetOutputs(pipeline.Start); Assert.That(output, Has.Length.EqualTo(2)); @@ -78,8 +81,11 @@ public void Build_PluckerCheckpoint_Success() .Pluck(x => x.Month).Checkpoint(out var plucker) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(plucker, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(plucker, Is.Not.Null); + }); var output = plucker.GetOutputs(pipeline.Start); Assert.Multiple(() => @@ -98,8 +104,11 @@ public void Build_ConstantCheckpoint_Success() .Constant(0).Checkpoint(out var constant) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(constant, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(constant, Is.Not.Null); + }); var output = constant.GetOutputs(pipeline.Start); Assert.Multiple(() => @@ -118,8 +127,11 @@ public void Build_SplitterCheckpoint_Success() .Split(x => x?.Split('-') ?? []).Checkpoint(out var splitter) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(splitter, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(splitter, Is.Not.Null); + }); var output = splitter.GetOutputs(pipeline.Start); Assert.Multiple(() => @@ -137,8 +149,11 @@ public void Build_AggregateMaxCheckpoint_Success() .Aggregate().AsMax().Checkpoint(out var aggr) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(aggr, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(aggr, Is.Not.Null); + }); var output = aggr.GetOutputs(pipeline.Start); Assert.That(output.Last(), Is.EqualTo(3)); @@ -152,8 +167,11 @@ public void Build_AggregateMinCheckpoint_Success() .Aggregate().AsMin().Checkpoint(out var aggr) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(aggr, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(aggr, Is.Not.Null); + }); var output = aggr.GetOutputs(pipeline.Start); Assert.That(output.Last(), Is.EqualTo(1)); @@ -167,8 +185,11 @@ public void Build_AggregateAverageCheckpoint_Success() .Aggregate().AsAverage().Checkpoint(out var aggr) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(aggr, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(aggr, Is.Not.Null); + }); var output = aggr.GetOutputs(pipeline.Start); Assert.That(output.Last(), Is.EqualTo(2)); @@ -182,8 +203,11 @@ public void Build_AggregateMedianCheckpoint_Success() .Aggregate().AsMedian().Checkpoint(out var aggr) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(aggr, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(aggr, Is.Not.Null); + }); var output = aggr.GetOutputs(pipeline.Start); Assert.That(output.Last(), Is.EqualTo(2)); @@ -197,8 +221,11 @@ public void Build_AggregateSumCheckpoint_Success() .Aggregate().AsSum().Checkpoint(out var aggr) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(aggr, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(aggr, Is.Not.Null); + }); var output = aggr.GetOutputs(pipeline.Start); Assert.That(output.Last(), Is.EqualTo(6)); @@ -212,8 +239,11 @@ public void Build_AggregateCountCheckpoint_Success() .Aggregate().AsCount().Checkpoint(out var aggr) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(aggr, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(aggr, Is.Not.Null); + }); var output = aggr.GetOutputs(pipeline.Start); Assert.That(output.Last(), Is.EqualTo(3)); @@ -227,8 +257,11 @@ public void Build_AggregateUniversalCheckpoint_Success() .Aggregate((x, y) => x + y).Checkpoint(out var aggr) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(aggr, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(aggr, Is.Not.Null); + }); var output = aggr.GetOutputs(pipeline.Start); Assert.That(output.Last(), Is.EqualTo("fooBar")); @@ -242,8 +275,11 @@ public void Build_AggregateUniversal2Checkpoint_Success() .Aggregate((x, y) => x + (string.IsNullOrEmpty(y) ? 0 : y!.Length)).Checkpoint(out var aggr) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(aggr, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(aggr, Is.Not.Null); + }); var output = aggr.GetOutputs(pipeline.Start); Assert.That(output.Last(), Is.EqualTo(6)); @@ -260,8 +296,11 @@ public void Build_AggregateUniversal3Checkpoint_Success() .Checkpoint(out var aggr) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(aggr, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(aggr, Is.Not.Null); + }); var output = aggr.GetOutputs(pipeline.Start); Assert.That(output.Last(), Is.EqualTo(false)); @@ -278,8 +317,11 @@ public void Build_AggregateUniversal4Checkpoint_Success() .Checkpoint(out var aggr) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(aggr, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(aggr, Is.Not.Null); + }); var output = aggr.GetOutputs(pipeline.Start); Assert.That(output.Last(), Is.EqualTo(true)); @@ -295,8 +337,11 @@ public void Build_ParserDateCheckpoint_Success() .Checkpoint(out var parser) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(parser, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(parser, Is.Not.Null); + }); var output = parser.GetOutputs(pipeline.Start); Assert.That(output, Does.Contain(new DateOnly(2024, 09, 14))); @@ -313,8 +358,11 @@ public void Build_ParserDateTimeCheckpoint_Success() .Checkpoint(out var parser) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(parser, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(parser, Is.Not.Null); + }); var output = parser.GetOutputs(pipeline.Start); Assert.That(output, Has.Length.EqualTo(2)); @@ -341,8 +389,11 @@ public void Build_ParserRomanFiguresCheckpoint_Success() }).Checkpoint(out var parser) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(parser, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(parser, Is.Not.Null); + }); var output = parser.GetOutputs(pipeline.Start); Assert.That(output, Has.Length.EqualTo(2)); @@ -364,8 +415,11 @@ public void Build_ComplexTryOnlyMainCheckpoint_Success() .Checkpoint(out var aggr) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(aggr, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(aggr, Is.Not.Null); + }); var output = aggr.GetOutputs(pipeline.Start); Assert.That(output.Last(), Is.EqualTo(16)); @@ -385,8 +439,11 @@ public void Build_CombineTwoUpstreamsCheckpoint_Success() .Zip((day, month) => $"{day} {month}").Checkpoint(out var zip) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(zip, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(zip, Is.Not.Null); + }); var output = zip.GetOutputs(pipeline.Start); Assert.That(output, Does.Contain("15 September")); @@ -407,8 +464,11 @@ public void Build_CombineThreeUpstreamsCheckpoint_Success() .Zip((day, month, year) => $"on {day} {month} {year}").Checkpoint(out var zip) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(zip, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(zip, Is.Not.Null); + }); var output = zip.GetOutputs(pipeline.Start); Assert.That(output, Does.Contain("on 15 September 2025")); @@ -428,8 +488,11 @@ public void Build_InBranchCheckpoint_Success() ).Checkpoints(out var ports) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(ports, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(ports, Is.Not.Null); + }); Assert.That(ports, Has.Length.EqualTo(2)); var outputMonth = ((IChainablePort)ports[1]).GetOutputs(pipeline.Start); @@ -449,8 +512,11 @@ public void Build_InBranchCheckpointForAllPorts_Success() ).Checkpoints(out var ports) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(ports, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(ports, Is.Not.Null); + }); Assert.That(ports, Has.Length.EqualTo(2)); var outputMonth = ((IChainablePort)ports[1]).GetOutputs(pipeline.Start); @@ -472,8 +538,11 @@ public void Build_InBranchCheckpointWithDiscardedPorts_Success() ).Checkpoints(out var _, out var monthPort, out var _) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(monthPort, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(monthPort, Is.Not.Null); + }); var outputMonth = monthPort.GetOutputs(pipeline.Start); Assert.That(outputMonth, Does.Contain("September")); @@ -492,15 +561,21 @@ public void Build_InBranchCheckpointForAllPortsAllAsserted_Success() ).Checkpoints(out var ports) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(ports, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(ports, Is.Not.Null); + }); Assert.That(ports, Has.Length.EqualTo(2)); var action = pipeline.Start; var (outputDay, outputMonth) = action.GetMultipleOutputs((IChainablePort)ports[0], (IChainablePort)ports[1]); Assert.That(outputDay, Does.Contain(15)); - Assert.That(outputDay, Does.Contain(16)); - Assert.That(outputMonth, Does.Contain("September")); + Assert.Multiple(() => + { + Assert.That(outputDay, Does.Contain(16)); + Assert.That(outputMonth, Does.Contain("September")); + }); } [Test] @@ -516,15 +591,21 @@ public void Build_InBranchCheckpointForAllPortsTypedAllAsserted_Success() ).Checkpoints(out var portDay, out var portMonth) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(portDay, Is.Not.Null); - Assert.That(portMonth, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(portDay, Is.Not.Null); + Assert.That(portMonth, Is.Not.Null); + }); var action = pipeline.Start; var (outputDay, outputMonth) = action.GetMultipleOutputs(portDay, portMonth); Assert.That(outputDay, Does.Contain(15)); - Assert.That(outputDay, Does.Contain(16)); - Assert.That(outputMonth, Does.Contain("September")); + Assert.Multiple(() => + { + Assert.That(outputDay, Does.Contain(16)); + Assert.That(outputMonth, Does.Contain("September")); + }); } [Test] @@ -543,15 +624,21 @@ public void Build_InBranchOfBranchCheckpointForAllPortsTypedAllAsserted_Success( ).Checkpoints(out var portDay, out var portMonth) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(portDay, Is.Not.Null); - Assert.That(portMonth, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(portDay, Is.Not.Null); + Assert.That(portMonth, Is.Not.Null); + }); var action = pipeline.Start; var (outputDay, outputMonth) = action.GetMultipleOutputs(portDay, portMonth); Assert.That(outputDay, Does.Contain(33)); - Assert.That(outputDay, Does.Contain(35)); - Assert.That(outputMonth, Does.Contain("September")); + Assert.Multiple(() => + { + Assert.That(outputDay, Does.Contain(35)); + Assert.That(outputMonth, Does.Contain("September")); + }); } [Test] @@ -568,8 +655,11 @@ public void Build_CombineFiveUpstreamsCheckpoint_Success() .Zip((stream1, stream2, stream3, stream4, stream5) => stream1 + stream2 + stream3 + stream4 + stream5).Checkpoint(out var zip) .Build(); - Assert.That(pipeline, Is.Not.Null); - Assert.That(zip, Is.Not.Null); + Assert.Multiple(() => + { + Assert.That(pipeline, Is.Not.Null); + Assert.That(zip, Is.Not.Null); + }); var output = zip.GetOutputs(pipeline.Start); Assert.That(output, Does.Contain(20)); diff --git a/Streamistry.Testing/UnionTests.cs b/Streamistry.Testing/UnionTests.cs index 01a7975..5841ff1 100644 --- a/Streamistry.Testing/UnionTests.cs +++ b/Streamistry.Testing/UnionTests.cs @@ -13,12 +13,12 @@ public class UnionTests [Test] public void Union_ManyPipes_AsSinglePipe() { - var firstSource = new EnumerableSource([1, 2, 3]); var secondSource = new EnumerableSource([10, 20, 30]); var pipeline = new Pipeline([firstSource, secondSource]); var union = new Union([firstSource, secondSource]); - Assert.That(union.GetOutputs(pipeline.Start), Is.EqualTo(new int[] { 1, 2, 3, 10, 20, 30 })); + var expected = new int[] { 1, 2, 3, 10, 20, 30 }; + Assert.That(union.GetOutputs(pipeline.Start), Is.EqualTo(expected)); } }