From 27a2c4af3a8639d5826a20ce4a52c8a90642d952 Mon Sep 17 00:00:00 2001 From: Christian Siewert Date: Tue, 12 Nov 2024 14:48:16 +0100 Subject: [PATCH] Add extension to create strings`.AsInstruction()`. --- .../VisualInstructorExtensions.cs | 19 ++++++++++++- .../VisualInstructorExtensionsTests.cs | 27 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/Tests/Moryx.ControlSystem.Tests/VisualInstructions/VisualInstructorExtensionsTests.cs diff --git a/src/Moryx.ControlSystem/VisualInstructions/VisualInstructorExtensions.cs b/src/Moryx.ControlSystem/VisualInstructions/VisualInstructorExtensions.cs index dd0bffb..278a06c 100644 --- a/src/Moryx.ControlSystem/VisualInstructions/VisualInstructorExtensions.cs +++ b/src/Moryx.ControlSystem/VisualInstructions/VisualInstructorExtensions.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) 2024, Phoenix Contact GmbH & Co. KG +// Licensed under the Apache License, Version 2.0 + +using System; using System.Reflection; using Moryx.AbstractionLayer; using Moryx.ControlSystem.Cells; @@ -133,5 +136,19 @@ private static VisualInstruction[] GetInstructions(ActivityStart activity) return parameters.Instructions; } + + /// + /// Returns a text instruction for the given string. + /// + /// Instruction text + /// with type `Text` the given string as content + public static VisualInstruction AsInstruction(this string text) + { + return new VisualInstruction + { + Content = text, + Type = InstructionContentType.Text, + }; + } } } diff --git a/src/Tests/Moryx.ControlSystem.Tests/VisualInstructions/VisualInstructorExtensionsTests.cs b/src/Tests/Moryx.ControlSystem.Tests/VisualInstructions/VisualInstructorExtensionsTests.cs new file mode 100644 index 0000000..b7e0ac6 --- /dev/null +++ b/src/Tests/Moryx.ControlSystem.Tests/VisualInstructions/VisualInstructorExtensionsTests.cs @@ -0,0 +1,27 @@ +// Copyright (c) 2024, Phoenix Contact GmbH & Co. KG +// Licensed under the Apache License, Version 2.0 + +using Moq; +using Moryx.ControlSystem.VisualInstructions; +using NUnit.Framework; +using System; + +namespace Moryx.ControlSystem.Tests.VisualInstructions +{ + [TestFixture] + + public class VisualInstructorExtensionsTests + { + [Test] + public void ExtensionCreatesStringAsInstruction() + { + var str = "text instruction"; + + var instruction = str.AsInstruction(); + + Assert.That(instruction.Type, Is.EqualTo(InstructionContentType.Text)); + Assert.That(instruction.Content, Is.EqualTo(str)); + } + + } +}