Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-ungureanu-uipath committed Apr 24, 2024
1 parent 4e80869 commit e1acbb3
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
61 changes: 61 additions & 0 deletions src/Test/TestCases.Workflows/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,25 @@ public void Vb_CompareLambdas()
validationResults.Errors[0].Message.ShouldContain("A null propagating operator cannot be converted into an expression tree.");
}

[Fact]
public void Cs_CompareLambdas()
{
CSharpValue<string> csv = new(@$"string.Concat(""alpha "", b?.Substring(0, 10), ""beta "", 1)");
WriteLine writeLine = new();
writeLine.Text = new InArgument<string>(csv);
Sequence workflow = new();
workflow.Activities.Add(writeLine);
workflow.Variables.Add(new Variable<string>("b", "I'm a variable"));

ValidationResults validationResults = ActivityValidationServices.Validate(workflow, _forceCache);
validationResults.Errors.Count.ShouldBe(1, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
validationResults.Errors[0].Message.ShouldContain("An expression tree lambda may not contain a null propagating operator.");

validationResults = ActivityValidationServices.Validate(workflow, _useValidator);
validationResults.Errors.Count.ShouldBe(1, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
validationResults.Errors[0].Message.ShouldContain("An expression tree lambda may not contain a null propagating operator.");
}

[Fact]
public void Vb_LambdaExtension()
{
Expand All @@ -172,6 +191,20 @@ public void Vb_LambdaExtension()
validationResults.Errors.Count.ShouldBe(0, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
}

[Fact]
public void Cs_LambdaExtension()
{
CSharpValue<string> csv = new("list.First()");
WriteLine writeLine = new();
writeLine.Text = new InArgument<string>(csv);
Sequence workflow = new();
workflow.Activities.Add(writeLine);
workflow.Variables.Add(new Variable<List<string>>("list"));

ValidationResults validationResults = ActivityValidationServices.Validate(workflow, _useValidator);
validationResults.Errors.Count.ShouldBe(0, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
}

[Fact]
public void Vb_Dictionary()
{
Expand All @@ -185,6 +218,20 @@ public void Vb_Dictionary()
ValidationResults validationResults = ActivityValidationServices.Validate(workflow, _useValidator);
validationResults.Errors.Count.ShouldBe(0, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
}

[Fact]
public void Cs_Dictionary()
{
CSharpValue<string> csv = new("something.FooDictionary[\"key\"].ToString()");
WriteLine writeLine = new();
writeLine.Text = new InArgument<string>(csv);
Sequence workflow = new();
workflow.Activities.Add(writeLine);
workflow.Variables.Add(new Variable<ClassWithCollectionProperties>("something"));

ValidationResults validationResults = ActivityValidationServices.Validate(workflow, _useValidator);
validationResults.Errors.Count.ShouldBe(0, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
}
#region Check locations are not readonly
[Fact]
public void VB_Readonly_ThrowsError()
Expand Down Expand Up @@ -291,6 +338,20 @@ public void Vb_IntOverflow()
validationResults.Errors[0].Message.ShouldContain("Constant expression not representable in type 'Integer'");
}

[Fact]
public void Cs_IntOverflow()
{
VisualBasicValue<int> csv = new("2147483648");
Sequence workflow = new();
workflow.Variables.Add(new Variable<int>("someint"));
Assign assign = new() { To = new OutArgument<int>(workflow.Variables[0]), Value = new InArgument<int>(csv) };
workflow.Activities.Add(assign);

ValidationResults validationResults = ActivityValidationServices.Validate(workflow, _useValidator);
validationResults.Errors.Count.ShouldBe(1, string.Join("\n", validationResults.Errors.Select(e => e.Message)));
validationResults.Errors[0].Message.ShouldContain("Constant expression not representable in type 'Integer'");
}

[Fact]
public void VBValidator_StrictOn()
{
Expand Down
19 changes: 18 additions & 1 deletion src/Test/TestCases.Workflows/WF4Samples/Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class AheadOfTimeExpressions : ExpressionsBase
static readonly string CSharpCalculationResult = "Result == XX^2" + Environment.NewLine;
static readonly StringDictionary CSharpCalculationInputs = new() { ["XX"] = 16, ["YY"] = 16 };
[Fact]
public void SameTextDifferentTypes()
public void VBSameTextDifferentTypes()
{
var text = new VisualBasicValue<string>("var");
var values = new VisualBasicValue<IEnumerable<char>>("var");
Expand All @@ -101,6 +101,23 @@ public void SameTextDifferentTypes()
((LambdaExpression)values.GetExpressionTree()).ReturnType.ShouldBe(typeof(IEnumerable<char>));
}
[Fact]
public void CSSameTextDifferentTypes()
{
var text = new CSharpValue<string>("var");
var values = new CSharpValue<IEnumerable<char>>("var");
var root = new DynamicActivity
{
Implementation = () => new Sequence
{
Variables = { new Variable<string>("var") },
Activities = { new ForEach<char> { Values = new InArgument<IEnumerable<char>>(values) }, new WriteLine { Text = new InArgument<string>(text) } }
}
};
ActivityXamlServices.Compile(root, new());
((LambdaExpression)text.GetExpressionTree()).ReturnType.ShouldBe(typeof(string));
((LambdaExpression)values.GetExpressionTree()).ReturnType.ShouldBe(typeof(IEnumerable<char>));
}
[Fact]
public void CompileCSharpCalculation()
{
var activity = Compile(TestXamls.CSharpCalculation);
Expand Down

0 comments on commit e1acbb3

Please sign in to comment.