Skip to content

Commit 528e108

Browse files
committed
Add .GetOrder() and .GetOperation() to IProcessExtensions
Created a UnitTest for both methods.
1 parent a39df2d commit 528e108

3 files changed

Lines changed: 80 additions & 2 deletions

File tree

src/Moryx.ControlSystem/Processes/IProcessExtensions.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using Moryx.AbstractionLayer.Products;
2-
using Moryx.AbstractionLayer;
31
using System;
42
using System.Collections.Generic;
53
using System.Text;
4+
using Moryx.AbstractionLayer;
5+
using Moryx.AbstractionLayer.Products;
6+
using Moryx.AbstractionLayer.Recipes;
7+
using Moryx.ControlSystem.Recipes;
68

79
namespace Moryx.ControlSystem.Processes
810
{
@@ -66,5 +68,37 @@ public static bool TryModifyProductInstance<TInstance>(this IProcess process, Ac
6668
setter.Invoke(instance);
6769
return true;
6870
}
71+
72+
/// <summary>
73+
/// Returns <see cref="IOrderBasedRecipe.OrderNumber"/> on the <see cref="IProcess"/> using the given <paramref name="process"/>.
74+
/// </summary>
75+
/// <param name="process">The process holding the order number</param>
76+
/// <example>
77+
/// <code>
78+
/// <![CDATA[
79+
/// process.GetOrder()
80+
/// ]]>
81+
/// </code>
82+
/// </example>
83+
public static string GetOrder(this IProcess process)
84+
{
85+
return (process.Recipe as IOrderBasedRecipe)?.OrderNumber;
86+
}
87+
88+
/// <summary>
89+
/// Returns <see cref="IOrderBasedRecipe.OperationNumber"/> on the <see cref="IProcess"/> using the given <paramref name="process"/>.
90+
/// </summary>
91+
/// <param name="process">The process holding the operation number</param>
92+
/// <example>
93+
/// <code>
94+
/// <![CDATA[
95+
/// process.GetOperation()
96+
/// ]]>
97+
/// </code>
98+
/// </example>
99+
public static string GetOperation(this IProcess process)
100+
{
101+
return (process.Recipe as IOrderBasedRecipe)?.OperationNumber;
102+
}
69103
}
70104
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
2+
3+
using Moryx.AbstractionLayer.Recipes;
4+
using Moryx.ControlSystem.Recipes;
5+
6+
namespace Moryx.ControlSystem.Tests.Mocks;
7+
8+
public class DummyRecipe : ProductionRecipe, IOrderBasedRecipe
9+
{
10+
public string OrderNumber { get; set; }
11+
public string OperationNumber { get; set; }
12+
13+
public DummyRecipe()
14+
{
15+
}
16+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
2+
3+
using Moryx.AbstractionLayer;
4+
using Moryx.ControlSystem.Processes;
5+
using Moryx.ControlSystem.Tests.Mocks;
6+
using NUnit.Framework;
7+
8+
namespace Moryx.ControlSystem.Tests;
9+
10+
[TestFixture]
11+
internal class ProcessExtensionsTest
12+
{
13+
[Test]
14+
public void ShouldReturnOrderAndOperationNumber()
15+
{
16+
// Arrange
17+
var recipe = new DummyRecipe { OrderNumber = "O10", OperationNumber = "Op082"};
18+
var process = new Process { Recipe = recipe};
19+
20+
// Act
21+
var orderNumber = process?.GetOrder();
22+
var operationNumber = process?.GetOperation();
23+
24+
// Assert
25+
Assert.That(orderNumber, Is.EqualTo(recipe.OrderNumber));
26+
Assert.That(operationNumber, Is.EqualTo(recipe.OperationNumber));
27+
}
28+
}

0 commit comments

Comments
 (0)