Skip to content

Commit

Permalink
Use AssemblyReferences instead of AssemblyNames for validation (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-ungureanu-uipath authored Feb 8, 2024
1 parent aaff158 commit 98661e3
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 131 deletions.
6 changes: 4 additions & 2 deletions src/Perf/CoreWf.Benchmarks/ExpressionTextboxPerformance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Microsoft.CSharp.Activities;
using Microsoft.VisualBasic.Activities;
using System.Activities;
using System.Activities.Expressions;
using System.Reflection;

namespace CoreWf.Benchmarks
{
Expand All @@ -27,13 +29,13 @@ public void VB_CreatePrecompiledValue()
[Benchmark]
public async Task CS_CreatePrecompiledValueAsync()
{
await CSharpDesignerHelper.CreatePrecompiledValueAsync(typeof(object), $"1 + {index++}", new[] { "System" }, new[] { "System" }, GetFreshEnvironment);
await CSharpDesignerHelper.CreatePrecompiledValueAsync(typeof(object), $"1 + {index++}", new[] { "System" }, new[] { (AssemblyReference)new AssemblyName("System") }, GetFreshEnvironment);
}

[Benchmark]
public async Task VB_CreatePrecompiledValueAsync()
{
await VisualBasicDesignerHelper.CreatePrecompiledValueAsync(typeof(object), $"1 + {index++}", new[] { "System" }, new[] { "System" }, GetFreshEnvironment);
await VisualBasicDesignerHelper.CreatePrecompiledValueAsync(typeof(object), $"1 + {index++}", new[] { "System" }, new[] { (AssemblyReference)new AssemblyName("System") }, GetFreshEnvironment);
}
}
}
23 changes: 13 additions & 10 deletions src/Test/TestCases.Workflows/XamlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;

Expand Down Expand Up @@ -228,7 +229,7 @@ public void CSharpShould_Infer_Type(string text, Type resultType, string[] names

[Theory]
[MemberData(nameof(GetCSharpTestData))]
public async Task CS_CreatePrecompiledValueAsync(string expression, IEnumerable<string> namespaces, IEnumerable<string> assemblies, IEnumerable<VisualBasicImportReference> importReferences)
public async Task CS_CreatePrecompiledValueAsync(string expression, IEnumerable<string> namespaces, IEnumerable<AssemblyReference> assemblies, IEnumerable<VisualBasicImportReference> importReferences)
{
var result = await CSharpDesignerHelper.CreatePrecompiledValueAsync(null, expression, namespaces, assemblies, null);

Expand All @@ -240,7 +241,7 @@ public async Task CS_CreatePrecompiledValueAsync(string expression, IEnumerable<

[Theory]
[MemberData(nameof(GetVBTestData))]
public async Task VB_CreatePrecompiledValueAsync(string expression, IEnumerable<string> namespaces, IEnumerable<string> assemblies, IEnumerable<VisualBasicImportReference> importReferences)
public async Task VB_CreatePrecompiledValueAsync(string expression, IEnumerable<string> namespaces, IEnumerable<AssemblyReference> assemblies, IEnumerable<VisualBasicImportReference> importReferences)
{
var result = await VisualBasicDesignerHelper.CreatePrecompiledValueAsync(null, expression, namespaces, assemblies, null);

Expand All @@ -254,21 +255,23 @@ public static IEnumerable<object[]> GetCSharpTestData
{
get
{
yield return new object[] { "typeof(JsonConvert)", new[] { "Newtonsoft.Json" }, new[] { "Newtonsoft.Json" }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new JToken[5]", new[] { "Newtonsoft.Json", "Newtonsoft.Json.Linq" }, new[] { "Newtonsoft.Json" }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new Dictionary<Dictionary<JToken, string>, JToken>()", new[] { "System.Collections.Generic", "Newtonsoft.Json", "Newtonsoft.Json.Linq" }, new[] { "Newtonsoft.Json" }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new ClassWithDictionaryProperty().TestProperty", new[] { "TestCases.Workflows" }, new[] { "System.Collections", "TestCases.Workflows", }, new[] { new VisualBasicImportReference { Assembly = "TestCases.Workflows", Import = "TestCases.Workflows" }, new VisualBasicImportReference { Assembly = "System.Private.CoreLib", Import = "System.Collections" } } };
yield return new object[] { "typeof(JsonConvert)", new[] { "Newtonsoft.Json" }, new[] { (AssemblyReference)new AssemblyName("Newtonsoft.Json") }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "typeof(JsonConvert)", new[] { "Newtonsoft.Json" }, new[] { (AssemblyReference)typeof(JsonToken).Assembly }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new JToken[5]", new[] { "Newtonsoft.Json", "Newtonsoft.Json.Linq" }, new[] { (AssemblyReference)new AssemblyName("Newtonsoft.Json") }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new Dictionary<Dictionary<JToken, string>, JToken>()", new[] { "System.Collections.Generic", "Newtonsoft.Json", "Newtonsoft.Json.Linq" }, new[] { (AssemblyReference)new AssemblyName("Newtonsoft.Json") }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new ClassWithDictionaryProperty().TestProperty", new[] { "TestCases.Workflows" }, new[] { (AssemblyReference)new AssemblyName("System.Collections"), (AssemblyReference)new AssemblyName("TestCases.Workflows") }, new[] { new VisualBasicImportReference { Assembly = "TestCases.Workflows", Import = "TestCases.Workflows" }, new VisualBasicImportReference { Assembly = "System.Private.CoreLib", Import = "System.Collections" } } };
}
}

public static IEnumerable<object[]> GetVBTestData
{
get
{
yield return new object[] { "GetType(JsonConvert)", new[] { "Newtonsoft.Json" }, new[] { "Newtonsoft.Json" }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new JToken(5){}", new[] { "Newtonsoft.Json", "Newtonsoft.Json.Linq" }, new[] { "Newtonsoft.Json" }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new Dictionary(Of Dictionary(Of JToken, String), JToken)()", new[] { "System.Collections.Generic", "Newtonsoft.Json", "Newtonsoft.Json.Linq" }, new[] { "Newtonsoft.Json" }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new ClassWithDictionaryProperty().TestProperty", new[] { "TestCases.Workflows" }, new[] { "System.Collections", "TestCases.Workflows", }, new[] { new VisualBasicImportReference { Assembly = "TestCases.Workflows", Import = "TestCases.Workflows" }, new VisualBasicImportReference { Assembly = "System.Private.CoreLib", Import = "System.Collections" } } };
yield return new object[] { "GetType(JsonConvert)", new[] { "Newtonsoft.Json" }, new[] { (AssemblyReference)new AssemblyName("Newtonsoft.Json") }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "GetType(JsonConvert)", new[] { "Newtonsoft.Json" }, new[] { (AssemblyReference)typeof(JsonToken).Assembly }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new JToken(5){}", new[] { "Newtonsoft.Json", "Newtonsoft.Json.Linq" }, new[] { (AssemblyReference)new AssemblyName("Newtonsoft.Json") }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new Dictionary(Of Dictionary(Of JToken, String), JToken)()", new[] { "System.Collections.Generic", "Newtonsoft.Json", "Newtonsoft.Json.Linq" }, new[] { (AssemblyReference)new AssemblyName("Newtonsoft.Json") }, new[] { new VisualBasicImportReference { Assembly = "Newtonsoft.Json", Import = "Newtonsoft.json" } } };
yield return new object[] { "new ClassWithDictionaryProperty().TestProperty", new[] { "TestCases.Workflows" }, new[] { (AssemblyReference)new AssemblyName("System.Collections"), (AssemblyReference)new AssemblyName("TestCases.Workflows") }, new[] { new VisualBasicImportReference { Assembly = "TestCases.Workflows", Import = "TestCases.Workflows" }, new VisualBasicImportReference { Assembly = "System.Private.CoreLib", Import = "System.Collections" } } };
}
}

Expand Down
Loading

0 comments on commit 98661e3

Please sign in to comment.