-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override the equals method of workplan including tests
- compare the types of steps and connectors - create tests
- Loading branch information
Showing
9 changed files
with
348 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/Tests/Moryx.Tests/Workplans/Dummies/AssemblingActivity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Moryx.AbstractionLayer; | ||
using Moryx.AbstractionLayer.Capabilities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Moryx.Tests.Workplans.Dummies | ||
{ | ||
[ActivityResults(typeof(DefaultActivityResult))] | ||
public class AssemblingActivity : Activity<AssemblingParameters> | ||
{ | ||
|
||
|
||
public override ProcessRequirement ProcessRequirement => ProcessRequirement.NotRequired; | ||
|
||
public override ICapabilities RequiredCapabilities => new AssemblingCapabilities(); | ||
|
||
protected override ActivityResult CreateResult(long resultNumber) | ||
{ | ||
return ActivityResult.Create((DefaultActivityResult)resultNumber); | ||
} | ||
|
||
protected override ActivityResult CreateFailureResult() | ||
{ | ||
return ActivityResult.Create(DefaultActivityResult.Failed); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Tests/Moryx.Tests/Workplans/Dummies/AssemblingCapabilities.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Moryx.AbstractionLayer.Capabilities; | ||
|
||
namespace Moryx.Tests.Workplans.Dummies | ||
{ | ||
|
||
public class AssemblingCapabilities : CapabilitiesBase | ||
{ | ||
public int Value { get; set; } | ||
|
||
protected override bool ProvidedBy(ICapabilities provided) | ||
{ | ||
var providedAssembling = provided as AssemblingCapabilities; | ||
if (providedAssembling == null) | ||
return false; | ||
|
||
if (providedAssembling.Value < Value) // Provided must be greater or equal | ||
return false; | ||
|
||
return true; | ||
} | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/Tests/Moryx.Tests/Workplans/Dummies/AssemblingParameters.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Moryx.AbstractionLayer; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Moryx.Tests.Workplans.Dummies | ||
{ | ||
public class AssemblingParameters : Parameters | ||
{ | ||
protected override void Populate(IProcess process, Parameters instance) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Moryx.AbstractionLayer; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml.Linq; | ||
|
||
namespace Moryx.Tests.Workplans.Dummies | ||
{ | ||
[Display(Name = "Assembling Task", Description = "Task which does something with a product")] | ||
public class AssemblingTask : TaskStep<AssemblingActivity, AssemblingParameters> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Moryx.AbstractionLayer; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml.Linq; | ||
|
||
namespace Moryx.Tests.Workplans.Dummies | ||
{ | ||
[Display(Name = "PackagingTask", Description = "Task which does something with a product")] | ||
public class ColorizingTask : TaskStep<AssemblingActivity, AssemblingParameters> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Moryx.AbstractionLayer; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml.Linq; | ||
|
||
namespace Moryx.Tests.Workplans.Dummies | ||
{ | ||
[Display(Name = "PackagingTask", Description = "Task which does something with a product")] | ||
public class PackagingTask : TaskStep<AssemblingActivity, AssemblingParameters> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using Moryx.Workplans; | ||
using Moryx.AbstractionLayer; | ||
using NUnit.Framework; | ||
using Moryx.Tests.Workplans.Dummies; | ||
|
||
namespace Moryx.Tests.Workplans | ||
{ | ||
|
||
[TestFixture] | ||
public class EqualTest | ||
{ | ||
private Workplan firstWorkplan; | ||
private Workplan secondWorkplan; | ||
private Workplan thirdWorkplan; | ||
private Workplan fourthWorkplan; | ||
private Workplan fifthWorkplan; | ||
private Workplan sixthWorkplan; | ||
|
||
public Workplan CreateFirstWorkplan() | ||
{ | ||
var plan = new Workplan(); | ||
|
||
var start = plan.AddConnector("Start", NodeClassification.Start); | ||
var end = plan.AddConnector("End", NodeClassification.End); | ||
var failed = plan.AddConnector("Failed", NodeClassification.Failed); | ||
|
||
var input = start; | ||
var outputA = plan.AddConnector("A"); | ||
var outputB = plan.AddConnector("B"); | ||
|
||
plan.AddStep(new AssemblingTask(), new AssemblingParameters(), input, outputA, outputB, failed); | ||
|
||
input = outputA; | ||
plan.AddStep(new PackagingTask(), new AssemblingParameters(), input, end, end, failed); | ||
|
||
input = outputB; | ||
plan.AddStep(new ColorizingTask(), new AssemblingParameters(), input, end, failed, failed); | ||
return plan; | ||
} | ||
|
||
public Workplan CreateSecondWorkplan() | ||
{ | ||
var plan = new Workplan(); | ||
|
||
var start = plan.AddConnector("Start", NodeClassification.Start); | ||
var end = plan.AddConnector("End", NodeClassification.End); | ||
var failed = plan.AddConnector("Failed", NodeClassification.Failed); | ||
|
||
var input = start; | ||
var outptuA = input; | ||
var outputB = plan.AddConnector("A"); | ||
|
||
plan.AddStep(new AssemblingTask(), new AssemblingParameters(), input, outptuA, outputB, failed); | ||
|
||
input = outputB; | ||
plan.AddStep(new PackagingTask(), new AssemblingParameters(), input, outputB, end, failed); | ||
|
||
return plan; | ||
} | ||
|
||
public Workplan CreateThirdWorkplan() | ||
{ | ||
var plan = new Workplan(); | ||
|
||
var start = plan.AddConnector("Start", NodeClassification.Start); | ||
var end = plan.AddConnector("End", NodeClassification.End); | ||
var failed = plan.AddConnector("Failed", NodeClassification.Failed); | ||
|
||
var outputA = plan.AddConnector("A"); | ||
var outputB = plan.AddConnector("B"); | ||
|
||
plan.AddStep(new AssemblingTask(), new AssemblingParameters(), start, outputA, outputB, failed); | ||
|
||
var input = outputA; | ||
|
||
plan.AddStep(new PackagingTask(), new AssemblingParameters(), input, start, end, failed); | ||
|
||
input = outputB; | ||
|
||
plan.AddStep(new ColorizingTask(), new AssemblingParameters(), input, outputA, end, failed); | ||
|
||
return plan; | ||
} | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
firstWorkplan = CreateFirstWorkplan(); | ||
secondWorkplan = CreateFirstWorkplan(); | ||
|
||
thirdWorkplan = CreateSecondWorkplan(); | ||
fourthWorkplan = CreateSecondWorkplan(); | ||
|
||
fifthWorkplan = CreateThirdWorkplan(); | ||
sixthWorkplan = CreateThirdWorkplan(); | ||
} | ||
|
||
[Test] | ||
public void TestEqualWorkplans() | ||
{ | ||
bool result = firstWorkplan.Equals(secondWorkplan); | ||
Assert.That(result, Is.True); | ||
} | ||
|
||
[Test] | ||
public void TestEqualWorkplansSimpleLoop() | ||
{ | ||
bool result = thirdWorkplan.Equals(fourthWorkplan); | ||
Assert.That(result, Is.True); | ||
} | ||
|
||
[Test] | ||
public void TestEqualWorkplansDoubleLoop() | ||
{ | ||
bool result = fifthWorkplan.Equals(sixthWorkplan); | ||
Assert.That(result, Is.True); | ||
} | ||
|
||
[Test] | ||
public void TestUnequalWorkplans() | ||
{ | ||
bool r = thirdWorkplan.Equals(fifthWorkplan); | ||
Assert.That(r, Is.False); | ||
} | ||
} | ||
|
||
} |