diff --git a/src/Moryx.ControlSystem/Processes/IProcessExtensions.cs b/src/Moryx.ControlSystem/Processes/IProcessExtensions.cs index 56d30c8..94b9ba3 100644 --- a/src/Moryx.ControlSystem/Processes/IProcessExtensions.cs +++ b/src/Moryx.ControlSystem/Processes/IProcessExtensions.cs @@ -1,8 +1,7 @@ -using Moryx.AbstractionLayer.Products; +using System; using Moryx.AbstractionLayer; -using System; -using System.Collections.Generic; -using System.Text; +using Moryx.AbstractionLayer.Products; +using Moryx.ControlSystem.Recipes; namespace Moryx.ControlSystem.Processes { @@ -66,5 +65,37 @@ public static bool TryModifyProductInstance(this IProcess process, Ac setter.Invoke(instance); return true; } + + /// + /// Returns on the using the given . + /// + /// The process holding the order number + /// + /// + /// + /// + /// + public static string GetOrderNumber(this IProcess process) + { + return (process.Recipe as IOrderBasedRecipe)?.OrderNumber; + } + + /// + /// Returns on the using the given . + /// + /// The process holding the operation number + /// + /// + /// + /// + /// + public static string GetOperationNumber(this IProcess process) + { + return (process.Recipe as IOrderBasedRecipe)?.OperationNumber; + } } } diff --git a/src/Tests/Moryx.ControlSystem.Tests/Mocks/DummyRecipe.cs b/src/Tests/Moryx.ControlSystem.Tests/Mocks/DummyRecipe.cs new file mode 100644 index 0000000..26b4261 --- /dev/null +++ b/src/Tests/Moryx.ControlSystem.Tests/Mocks/DummyRecipe.cs @@ -0,0 +1,17 @@ +// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG + +using Moryx.AbstractionLayer.Recipes; +using Moryx.ControlSystem.Recipes; + +namespace Moryx.ControlSystem.Tests.Mocks +{ + public class DummyRecipe : ProductionRecipe, IOrderBasedRecipe + { + public string OrderNumber { get; set; } + public string OperationNumber { get; set; } + + public DummyRecipe() + { + } + } +} diff --git a/src/Tests/Moryx.ControlSystem.Tests/ProcessExtensionsTest.cs b/src/Tests/Moryx.ControlSystem.Tests/ProcessExtensionsTest.cs new file mode 100644 index 0000000..66e6632 --- /dev/null +++ b/src/Tests/Moryx.ControlSystem.Tests/ProcessExtensionsTest.cs @@ -0,0 +1,41 @@ +// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG + +using Moryx.AbstractionLayer; +using Moryx.ControlSystem.Processes; +using Moryx.ControlSystem.Tests.Mocks; +using NUnit.Framework; + +namespace Moryx.ControlSystem.Tests +{ + [TestFixture] + internal class ProcessExtensionsTest + { + [Test] + public void ShouldReturnOrderNumber() + { + // Arrange + var recipe = new DummyRecipe { OrderNumber = "O10", OperationNumber = "Op082" }; + var process = new Process { Recipe = recipe }; + + // Act + var orderNumber = process?.GetOrderNumber(); + + // Assert + Assert.That(orderNumber, Is.EqualTo(recipe.OrderNumber)); + } + + [Test] + public void ShouldReturnOperationNumber() + { + // Arrange + var recipe = new DummyRecipe { OrderNumber = "O10", OperationNumber = "Op082" }; + var process = new Process { Recipe = recipe }; + + // Act + var operationNumber = process?.GetOperationNumber(); + + // Assert + Assert.That(operationNumber, Is.EqualTo(recipe.OperationNumber)); + } + } +} \ No newline at end of file