-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from delegateas/tst/metadata-function
Tst/metadata function
- Loading branch information
Showing
8 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace ExpressionEngine | ||
{ | ||
/// <summary> | ||
/// A Function Definition is a map to a collected set of functions. | ||
/// - currentCellValue() -> formvalue(logicalName())[idx()][attributeLogicalName()] | ||
/// </summary> | ||
public class FunctionDefinition : IFunctionDefinition | ||
{ | ||
/// <summary> | ||
/// The from 'function name' which is replaced | ||
/// </summary> | ||
public string From { get; set; } | ||
/// <summary> | ||
/// The replacement | ||
/// </summary> | ||
public string To { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace ExpressionEngine | ||
{ | ||
/// <summary> | ||
/// Interface to function definitions | ||
/// </summary> | ||
public interface IFunctionDefinition | ||
{ | ||
/// <summary> | ||
/// The name of the 'function' which is replaced | ||
/// </summary> | ||
string From { get; set; } | ||
|
||
/// <summary> | ||
/// What it is replaced with | ||
/// </summary> | ||
string To { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using ExpressionEngine; | ||
using ExpressionEngine.Functions.CustomException; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
|
||
namespace Test | ||
{ | ||
public class FunctionDefinitionTests | ||
{ | ||
private ServiceCollection _serviceCollection; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_serviceCollection = new ServiceCollection(); | ||
_serviceCollection.AddExpressionEngine(); | ||
_serviceCollection.AddFunctionDefinition("addAndConcat", "concat('result of 1+1 is: ', add(1,1))"); | ||
} | ||
|
||
[TestCase] | ||
public async Task TestFunctionDef() | ||
{ | ||
var ee = _serviceCollection.BuildServiceProvider().GetRequiredService<IExpressionEngine>(); | ||
const string expectedResult = "result of 1+1 is: 2!"; | ||
|
||
var actualResult = await ee.Parse("@concat(addAndConcat(), '!')"); | ||
|
||
Assert.AreEqual(expectedResult, actualResult); | ||
} | ||
|
||
[TestCase] | ||
public void TestFunctionException() | ||
{ | ||
const string expectedMessage = "fromFunctionName cannot end in ()"; | ||
|
||
var exception = Assert.Throws<ArgumentError>(() => | ||
{ | ||
_serviceCollection.AddFunctionDefinition("addAndConcat()", "concat('result of 1+1 is: ', add(1,1))"); | ||
}); | ||
|
||
Assert.NotNull(exception); | ||
Assert.AreEqual(expectedMessage,exception.Message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters