-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse expressions from activity implementations
- Loading branch information
1 parent
7d795e5
commit 8ab18b3
Showing
7 changed files
with
1,766 additions
and
18 deletions.
There are no files selected for viewing
755 changes: 755 additions & 0 deletions
755
src/Test/TestCases.Workflows/ExpressionCompilerResults/CS_ExpressionCompilerResult
Large diffs are not rendered by default.
Oops, something went wrong.
778 changes: 778 additions & 0 deletions
778
src/Test/TestCases.Workflows/ExpressionCompilerResults/VB_ExpressionCompilerResult
Large diffs are not rendered by default.
Oops, something went wrong.
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
103 changes: 103 additions & 0 deletions
103
src/Test/TestCases.Workflows/TextExpressionCompilerTests.cs
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,103 @@ | ||
using Xunit; | ||
using System; | ||
using System.IO; | ||
using System.Activities; | ||
using Microsoft.CSharp.Activities; | ||
using System.Activities.Statements; | ||
using Microsoft.VisualBasic.Activities; | ||
using System.Activities.XamlIntegration; | ||
|
||
namespace TestCases.Workflows | ||
{ | ||
public class TextExpressionCompilerTests | ||
{ | ||
[Theory] | ||
[InlineData("VB")] | ||
[InlineData("C#")] | ||
public void EnsureCompilationParity(string expressionLanguage) | ||
{ | ||
var actualSourceWriter = new StringWriter(); | ||
var currentAsm = typeof(TextExpressionCompilerTests).Assembly; | ||
|
||
TextExpressionCompilerSettings settings = new() | ||
{ | ||
RootNamespace = null, | ||
ForImplementation = true, | ||
ActivityName = "TestClass", | ||
AlwaysGenerateSource = true, | ||
Language = expressionLanguage, | ||
GenerateAsPartialClass = false, | ||
ActivityNamespace = "TestNamespace", | ||
Activity = new DynamicActivity { Implementation = () => GetActivity(expressionLanguage) }, | ||
}; | ||
|
||
new TextExpressionCompiler(settings).GenerateSource(actualSourceWriter); | ||
var expectedStream = currentAsm.GetManifestResourceStream($"{currentAsm.GetName().Name}.ExpressionCompilerResults.{GetExpectedResourceName(expressionLanguage)}"); | ||
|
||
var actualSource = actualSourceWriter.ToString(); | ||
var expectedSource = new StreamReader(expectedStream).ReadToEnd(); | ||
Assert.Equal(expectedSource, actualSource); | ||
} | ||
|
||
private static string GetExpectedResourceName(string expressionLanguage) | ||
=> expressionLanguage switch | ||
{ | ||
"C#" => "CS_ExpressionCompilerResult", | ||
"VB" => "VB_ExpressionCompilerResult", | ||
_ => throw new NotImplementedException() | ||
}; | ||
|
||
private static Activity GetActivity(string expressionLanguage) | ||
=> expressionLanguage switch | ||
{ | ||
"C#" => GetActivity(v1 => new CSharpValue<bool>(v1), v2 => new CSharpValue<string>(v2), v3 => new CSharpReference<string>(v3)), | ||
"VB" => GetActivity(v1 => new VisualBasicValue<bool>(v1), v2 => new VisualBasicValue<string>(v2), v3 => new VisualBasicReference<string>(v3)), | ||
_ => throw new NotImplementedException() | ||
}; | ||
|
||
private static Activity GetActivity<T1, T2, T3>(Func<string, T1> boolValueFactory, Func<string, T2> strValueFactory, Func<string, T3> referenceFactory) | ||
where T1 : TextExpressionBase<bool> | ||
where T2 : TextExpressionBase<string> | ||
where T3 : TextExpressionBase<Location<string>> | ||
=> new Sequence() | ||
{ | ||
Variables = | ||
{ | ||
new Variable<string>("var1") | ||
}, | ||
Activities = | ||
{ | ||
new WriteLine() { Text = new InArgument<string>(strValueFactory("var1")) }, | ||
new Assign() { To = new OutArgument<string>(referenceFactory("var1")), Value = new InArgument<string>("test1") }, | ||
new If() { | ||
Condition = new InArgument<bool>(boolValueFactory("var1 != \"test\"")), | ||
Then = new Sequence() | ||
{ | ||
Variables = | ||
{ | ||
new Variable<string>("var2") | ||
}, | ||
Activities = | ||
{ | ||
new Assign() { To = new OutArgument<string>(referenceFactory("var2")), Value = new InArgument<string>("test2") }, | ||
new WriteLine() { Text = new InArgument<string>(strValueFactory("var2")) }, | ||
} | ||
}, | ||
Else = new Sequence() | ||
{ | ||
Activities = | ||
{ | ||
new Sequence() | ||
{ | ||
Activities = | ||
{ | ||
new WriteLine() { Text = new InArgument<string>(strValueFactory("test3")) }, | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
} |
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