Skip to content

Commit

Permalink
Add extension to create strings.AsInstruction().
Browse files Browse the repository at this point in the history
  • Loading branch information
seveneleven committed Nov 12, 2024
1 parent 5e245c5 commit 27a2c4a
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 27a2c4a

Please sign in to comment.