123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System;
- using System.Linq.Expressions;
- using Luticate2.Auth.Tests.Business.ObjectConverter;
- using Luticate2.Auth.Utils.Business.Pagination;
- using Luticate2.Auth.Utils.Dbo;
- using Luticate2.Auth.Utils.Dbo.Pagination;
- using Luticate2.Auth.Utils.Dbo.Result;
- using Microsoft.CodeAnalysis.CSharp.Scripting;
- using Microsoft.CodeAnalysis.Scripting;
- using Xunit;
-
- namespace Luticate2.Auth.Tests
- {
- public class RandomTests
- {
- public static LuResult<LuFilterDbo> Parse<T>(string data)
- {
- if (string.IsNullOrWhiteSpace(data))
- {
- data = "true";
- }
- var completeData = $"(x) => ({data})";
- try
- {
- var options = ScriptOptions.Default.AddReferences(typeof(RandomTests).Assembly,
- typeof(LuFilterParser).Assembly).AddImports("System.Linq.Enumerable");
- var expr = CSharpScript.EvaluateAsync<Expression<Func<T, bool>>>(completeData, options).Result;
- return LuResult<LuFilterDbo>.Ok(new LuFilterDbo
- {
- Expression = expr
- });
- }
- catch (Exception e)
- {
- return LuResult<LuFilterDbo>.Error(LuStatus.InputError.ToInt(), e, "Failed to parse filter expression");
- }
- }
-
- [Fact]
- public void Test()
- {
- // var parentScopeVar = new TestDbo1();
- // Expression<Func<TestDbo2, Guid>> expDbo = (x => parentScopeVar.Id);
- // var type = typeof(ILuObjectConverterDescriptor<,>);
- // var gtype = type.MakeGenericType(typeof(int), typeof(Enumerable));
- var result = Parse<TestDbo1>("x.TestDbo2s.Any(y => y.Name == null)");
- // var result = Parse<TestDbo1>("System.Linq.Enumerable.Any(x.TestDbo2s, y => y.Name == null)");
- }
-
- }
- }
|