Skip to content

Commit a34b9a9

Browse files
added unit tests
1 parent 816b1b4 commit a34b9a9

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

src/Test/TestCases.Workflows/ExpressionTests.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,25 @@ public void Vb_CompareLambdas()
158158
validationResults.Errors[0].Message.ShouldContain("A null propagating operator cannot be converted into an expression tree.");
159159
}
160160

161+
[Fact]
162+
public void Cs_CompareLambdas()
163+
{
164+
CSharpValue<string> csv = new(@$"string.Concat(""alpha "", b?.Substring(0, 10), ""beta "", 1)");
165+
WriteLine writeLine = new();
166+
writeLine.Text = new InArgument<string>(csv);
167+
Sequence workflow = new();
168+
workflow.Activities.Add(writeLine);
169+
workflow.Variables.Add(new Variable<string>("b", "I'm a variable"));
170+
171+
ValidationResults validationResults = ActivityValidationServices.Validate(workflow, _forceCache);
172+
validationResults.Errors.Count.ShouldBe(1, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
173+
validationResults.Errors[0].Message.ShouldContain("An expression tree lambda may not contain a null propagating operator.");
174+
175+
validationResults = ActivityValidationServices.Validate(workflow, _useValidator);
176+
validationResults.Errors.Count.ShouldBe(1, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
177+
validationResults.Errors[0].Message.ShouldContain("An expression tree lambda may not contain a null propagating operator.");
178+
}
179+
161180
[Fact]
162181
public void Vb_LambdaExtension()
163182
{
@@ -172,6 +191,20 @@ public void Vb_LambdaExtension()
172191
validationResults.Errors.Count.ShouldBe(0, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
173192
}
174193

194+
[Fact]
195+
public void Cs_LambdaExtension()
196+
{
197+
CSharpValue<string> csv = new("list.First()");
198+
WriteLine writeLine = new();
199+
writeLine.Text = new InArgument<string>(csv);
200+
Sequence workflow = new();
201+
workflow.Activities.Add(writeLine);
202+
workflow.Variables.Add(new Variable<List<string>>("list"));
203+
204+
ValidationResults validationResults = ActivityValidationServices.Validate(workflow, _useValidator);
205+
validationResults.Errors.Count.ShouldBe(0, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
206+
}
207+
175208
[Fact]
176209
public void Vb_Dictionary()
177210
{
@@ -185,6 +218,20 @@ public void Vb_Dictionary()
185218
ValidationResults validationResults = ActivityValidationServices.Validate(workflow, _useValidator);
186219
validationResults.Errors.Count.ShouldBe(0, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
187220
}
221+
222+
[Fact]
223+
public void Cs_Dictionary()
224+
{
225+
CSharpValue<string> csv = new("something.FooDictionary[\"key\"].ToString()");
226+
WriteLine writeLine = new();
227+
writeLine.Text = new InArgument<string>(csv);
228+
Sequence workflow = new();
229+
workflow.Activities.Add(writeLine);
230+
workflow.Variables.Add(new Variable<ClassWithCollectionProperties>("something"));
231+
232+
ValidationResults validationResults = ActivityValidationServices.Validate(workflow, _useValidator);
233+
validationResults.Errors.Count.ShouldBe(0, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
234+
}
188235
#region Check locations are not readonly
189236
[Fact]
190237
public void VB_Readonly_ThrowsError()
@@ -291,6 +338,20 @@ public void Vb_IntOverflow()
291338
validationResults.Errors[0].Message.ShouldContain("Constant expression not representable in type 'Integer'");
292339
}
293340

341+
[Fact]
342+
public void Cs_IntOverflow()
343+
{
344+
VisualBasicValue<int> csv = new("2147483648");
345+
Sequence workflow = new();
346+
workflow.Variables.Add(new Variable<int>("someint"));
347+
Assign assign = new() { To = new OutArgument<int>(workflow.Variables[0]), Value = new InArgument<int>(csv) };
348+
workflow.Activities.Add(assign);
349+
350+
ValidationResults validationResults = ActivityValidationServices.Validate(workflow, _useValidator);
351+
validationResults.Errors.Count.ShouldBe(1, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
352+
validationResults.Errors[0].Message.ShouldContain("Constant expression not representable in type 'Integer'");
353+
}
354+
294355
[Fact]
295356
public void VBValidator_StrictOn()
296357
{

src/Test/TestCases.Workflows/WF4Samples/Expressions.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class AheadOfTimeExpressions : ExpressionsBase
8787
static readonly string CSharpCalculationResult = "Result == XX^2" + Environment.NewLine;
8888
static readonly StringDictionary CSharpCalculationInputs = new() { ["XX"] = 16, ["YY"] = 16 };
8989
[Fact]
90-
public void SameTextDifferentTypes()
90+
public void VBSameTextDifferentTypes()
9191
{
9292
var text = new VisualBasicValue<string>("var");
9393
var values = new VisualBasicValue<IEnumerable<char>>("var");
@@ -101,6 +101,23 @@ public void SameTextDifferentTypes()
101101
((LambdaExpression)values.GetExpressionTree()).ReturnType.ShouldBe(typeof(IEnumerable<char>));
102102
}
103103
[Fact]
104+
public void CSSameTextDifferentTypes()
105+
{
106+
var text = new CSharpValue<string>("var");
107+
var values = new CSharpValue<IEnumerable<char>>("var");
108+
var root = new DynamicActivity
109+
{
110+
Implementation = () => new Sequence
111+
{
112+
Variables = { new Variable<string>("var") },
113+
Activities = { new ForEach<char> { Values = new InArgument<IEnumerable<char>>(values) }, new WriteLine { Text = new InArgument<string>(text) } }
114+
}
115+
};
116+
ActivityXamlServices.Compile(root, new());
117+
((LambdaExpression)text.GetExpressionTree()).ReturnType.ShouldBe(typeof(string));
118+
((LambdaExpression)values.GetExpressionTree()).ReturnType.ShouldBe(typeof(IEnumerable<char>));
119+
}
120+
[Fact]
104121
public void CompileCSharpCalculation()
105122
{
106123
var activity = Compile(TestXamls.CSharpCalculation);

0 commit comments

Comments
 (0)