Skip to content

Commit

Permalink
Merge pull request #94 from PHOENIXCONTACT/feature/text-instruction-e…
Browse files Browse the repository at this point in the history
…xtension

Add extension to create strings`.AsInstruction()`.
  • Loading branch information
seveneleven authored Dec 3, 2024
2 parents 5e245c5 + 27a2c4a commit 9e8ea40
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -133,5 +136,19 @@ private static VisualInstruction[] GetInstructions(ActivityStart activity)

return parameters.Instructions;
}

/// <summary>
/// Returns a text instruction for the given string.
/// </summary>
/// <param name="text">Instruction text</param>
/// <returns><see cref="VisualInstruction"/> with type `Text` the given string as content</returns>
public static VisualInstruction AsInstruction(this string text)
{
return new VisualInstruction
{
Content = text,
Type = InstructionContentType.Text,
};
}
}
}
Original file line number Diff line number Diff line change
@@ -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));
}

}
}

0 comments on commit 9e8ea40

Please sign in to comment.