Skip to content

Commit

Permalink
Merge pull request 7399 from hotfix/v4.4.6 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Project Collection Build Service (51degrees) authored and Project Collection Build Service (51degrees) committed Jul 22, 2022
2 parents a429251 + 608e923 commit 440d349
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 4 deletions.
18 changes: 18 additions & 0 deletions FiftyOne.Pipeline.Core/FlowElements/IPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ public interface IPipeline : IDisposable
/// </summary>
bool IsDisposed { get; }

/// <summary>
/// Check if the pipeline contains an instance of <typeparamref name="TExpectedElement"/>
/// that will be executed after <typeparamref name="TElement"/>.
/// </summary>
/// <typeparam name="TElement">
/// The type of the element to check.
/// </typeparam>
/// <typeparam name="TExpectedElement">
/// The type of the element that should come after <typeparamref name="TElement"/>.
/// </typeparam>
/// <returns>
/// True if <typeparamref name="TExpectedElement"/> is present in the pipeline and will be
/// executed after <typeparamref name="TElement"/>
/// </returns>
bool HasExpectedElementAfter<TElement, TExpectedElement>()
where TElement : IFlowElement
where TExpectedElement : IFlowElement;

/// <summary>
/// Get the specified element from the pipeline.
/// </summary>
Expand Down
59 changes: 59 additions & 0 deletions FiftyOne.Pipeline.Core/FlowElements/Pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,65 @@ public TElement GetElement<TElement>()
return result;
}


/// <summary>
/// Check if the pipeline contains an instance of <typeparamref name="TExpectedElement"/>
/// that will be executed after <typeparamref name="TElement"/>.
/// </summary>
/// <typeparam name="TElement">
/// The type of the element to check.
/// </typeparam>
/// <typeparam name="TExpectedElement">
/// The type of the element that should come after <typeparamref name="TElement"/>.
/// </typeparam>
/// <returns>
/// True if <typeparamref name="TExpectedElement"/> is present in the pipeline and will be
/// executed after <typeparamref name="TElement"/>
/// </returns>
public bool HasExpectedElementAfter<TElement, TExpectedElement>()
where TElement : IFlowElement
where TExpectedElement : IFlowElement
{
// Get the indicies for these elements.
int elementIndex = GetElementIndex<TElement>();
int expectedElementIndex = GetElementIndex<TExpectedElement>();

return elementIndex >= 0 && expectedElementIndex >= 0 &&
expectedElementIndex > elementIndex;
}

/// <summary>
/// Get the index of the element matching the specified type.
/// Note that if there are multiple instances matching the given type, the index of the
/// first instance will be returned.
/// </summary>
/// <typeparam name="TElement"></typeparam>
/// <returns></returns>
private int GetElementIndex<TElement>()
{
for (int i = 0; i < _flowElements.Count; i++)
{
// If the element is a ParallelElements instance then check the child elements.
// If there is a match then we want to take the index from the top level element.
if (_flowElements[i] is ParallelElements parallel)
{
if (parallel.FlowElements.Any(e => typeof(TElement).IsAssignableFrom(e.GetType())))
{
return i;
}
}
else
{
if (typeof(TElement).IsAssignableFrom(_flowElements[i].GetType()))
{
return i;
}
}
}
return -1;
}


/// <summary>
/// Add the specified flow elements to the
/// <see cref="_elementsByType"/> dictionary, which contains a list
Expand Down
7 changes: 7 additions & 0 deletions FiftyOne.Pipeline.Engines.TestHelpers/TestPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public IElementPropertyMetaData GetMetaDataForProperty(string propertyName)
}
}

public bool HasExpectedElementAfter<TElement, TExpectedElement>()
where TElement : IFlowElement
where TExpectedElement : IFlowElement
{
return _pipeline.HasExpectedElementAfter<TElement, TExpectedElement>();
}

public void Process(IFlowData data)
{
var pipelineInternal = _pipeline as IPipelineInternal;
Expand Down
11 changes: 11 additions & 0 deletions FiftyOne.Pipeline.Web.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FiftyOne.Pipeline.Web.Share
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "performance-tests", "performance-tests\performance-tests.csproj", "{439673A0-0255-403D-A412-5C5C9190A0F9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FiftyOne.Pipeline.Engines.TestHelpers", "FiftyOne.Pipeline.Engines.TestHelpers\FiftyOne.Pipeline.Engines.TestHelpers.csproj", "{A4ED2E2B-7B7F-4337-951F-911445D79FE7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -221,6 +223,14 @@ Global
{439673A0-0255-403D-A412-5C5C9190A0F9}.LinuxRelease|Any CPU.Build.0 = Release|Any CPU
{439673A0-0255-403D-A412-5C5C9190A0F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{439673A0-0255-403D-A412-5C5C9190A0F9}.Release|Any CPU.Build.0 = Release|Any CPU
{A4ED2E2B-7B7F-4337-951F-911445D79FE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4ED2E2B-7B7F-4337-951F-911445D79FE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4ED2E2B-7B7F-4337-951F-911445D79FE7}.LinuxDebug|Any CPU.ActiveCfg = Debug|Any CPU
{A4ED2E2B-7B7F-4337-951F-911445D79FE7}.LinuxDebug|Any CPU.Build.0 = Debug|Any CPU
{A4ED2E2B-7B7F-4337-951F-911445D79FE7}.LinuxRelease|Any CPU.ActiveCfg = Release|Any CPU
{A4ED2E2B-7B7F-4337-951F-911445D79FE7}.LinuxRelease|Any CPU.Build.0 = Release|Any CPU
{A4ED2E2B-7B7F-4337-951F-911445D79FE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4ED2E2B-7B7F-4337-951F-911445D79FE7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -243,6 +253,7 @@ Global
{D3D54E8A-6674-4788-A177-55A3C2FFC9FF} = {AF5A4BF7-6197-4E0F-B796-EC6630C1C9CD}
{E9D230EE-88F0-4EC5-AF40-CEFFB8093251} = {5B0DFCCB-A77B-48AF-A50A-5AA3717A6697}
{439673A0-0255-403D-A412-5C5C9190A0F9} = {5B0DFCCB-A77B-48AF-A50A-5AA3717A6697}
{A4ED2E2B-7B7F-4337-951F-911445D79FE7} = {5B0DFCCB-A77B-48AF-A50A-5AA3717A6697}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {053DC44B-CB50-4B57-AEBE-33861B756AAF}
Expand Down
24 changes: 24 additions & 0 deletions Tests/FiftyOne.Pipeline.Core.Tests/FlowElements/PipelineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,30 @@ public void Pipeline_GetPropertyMetaData_Concurrent()
}
}

[TestMethod]
public void Pipeline_HasExpectedElementAfter()
{
var element1 = new TestElement();
var element2 = new ListSplitterElement(new List<string>(), 1);

var pipeline = CreatePipeline(false, false, element1, element2);

// Verify the 'HasExpectedElementAfter' method returns the expected results
Assert.IsTrue(pipeline.HasExpectedElementAfter<TestElement, ListSplitterElement>(),
"ListSplitterElement should be after TestElement");
Assert.IsFalse(pipeline.HasExpectedElementAfter<ListSplitterElement, TestElement>(),
"TestElement should not be after ListSplitterElement");
// Check that the method still works when using interfaces.
Assert.IsTrue(pipeline.HasExpectedElementAfter<ITestElement, ListSplitterElement>(),
"ListSplitterElement should be after ITestElement");
Assert.IsFalse(pipeline.HasExpectedElementAfter<ListSplitterElement, ITestElement>(),
"ITestElement should not be after ListSplitterElement");
// If the element is not in the pipeline, return false.
Assert.IsFalse(pipeline.HasExpectedElementAfter<StopElement, TestElement>());
// If the 'expected element' is not in the pipeline, return false.
Assert.IsFalse(pipeline.HasExpectedElementAfter<TestElement, StopElement>());
}

/// <summary>
/// Helper method to create a new pipeline instance.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions Tests/FiftyOne.Pipeline.Core.Tests/HelperClasses/ITestElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using FiftyOne.Pipeline.Core.FlowElements;
using System;
using System.Collections.Generic;
using System.Text;

namespace FiftyOne.Pipeline.Core.Tests.HelperClasses
{
public interface ITestElement : IFlowElement
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ namespace FiftyOne.Pipeline.Core.Tests.HelperClasses
/// <summary>
/// Custom test class extending FlowElementBase.
/// </summary>
public class TestElement : FlowElementBase<TestElementData, IElementPropertyMetaData>
public class TestElement : FlowElementBase<TestElementData, IElementPropertyMetaData>, ITestElement
{
public override string ElementDataKey => "testkey";

public override IEvidenceKeyFilter EvidenceKeyFilter => throw new NotImplementedException();
public override IList<IElementPropertyMetaData> Properties => throw new NotImplementedException();
public override IList<IElementPropertyMetaData> Properties => new List<IElementPropertyMetaData>();

public TestElement() :
base(new Mock<ILogger<TestElement>>().Object)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void TestAddFiftyOne(bool shareUsageEnabled, bool clientSideEvidenceEnabl

// Create the ServiceCollection and call the 'AddFiftyOne' extension method.
var services = new ServiceCollection();
services.AddLogging(b => b.AddConsole().SetMinimumLevel(LogLevel.Debug));
services.AddSingleton<EmptyEngineBuilder>();
services.AddFiftyOne(host.Services.GetRequiredService<IConfiguration>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FiftyOne.Pipeline.Engines.TestHelpers" Version="4.3.16" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
Expand All @@ -21,6 +20,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\FiftyOne.Pipeline.Engines.TestHelpers\FiftyOne.Pipeline.Engines.TestHelpers.csproj" />
<ProjectReference Include="..\..\FiftyOne.Pipeline.Web\FiftyOne.Pipeline.Web.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion ci/common-ci
Submodule common-ci updated 1 files
+64 −2 release-config.json

0 comments on commit 440d349

Please sign in to comment.