Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

RandomTests.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Linq.Expressions;
  3. using Luticate2.Auth.Tests.Business.ObjectConverter;
  4. using Luticate2.Auth.Utils.Business.Pagination;
  5. using Luticate2.Auth.Utils.Dbo;
  6. using Luticate2.Auth.Utils.Dbo.Pagination;
  7. using Luticate2.Auth.Utils.Dbo.Result;
  8. using Microsoft.CodeAnalysis.CSharp.Scripting;
  9. using Microsoft.CodeAnalysis.Scripting;
  10. using Xunit;
  11. namespace Luticate2.Auth.Tests
  12. {
  13. public class RandomTests
  14. {
  15. public static LuResult<LuFilterDbo> Parse<T>(string data)
  16. {
  17. if (string.IsNullOrWhiteSpace(data))
  18. {
  19. data = "true";
  20. }
  21. var completeData = $"(x) => ({data})";
  22. try
  23. {
  24. var options = ScriptOptions.Default.AddReferences(typeof(RandomTests).Assembly,
  25. typeof(LuFilterParser).Assembly).AddImports("System.Linq.Enumerable");
  26. var expr = CSharpScript.EvaluateAsync<Expression<Func<T, bool>>>(completeData, options).Result;
  27. return LuResult<LuFilterDbo>.Ok(new LuFilterDbo
  28. {
  29. Expression = expr
  30. });
  31. }
  32. catch (Exception e)
  33. {
  34. return LuResult<LuFilterDbo>.Error(LuStatus.InputError.ToInt(), e, "Failed to parse filter expression");
  35. }
  36. }
  37. [Fact]
  38. public void Test()
  39. {
  40. // var parentScopeVar = new TestDbo1();
  41. // Expression<Func<TestDbo2, Guid>> expDbo = (x => parentScopeVar.Id);
  42. // var type = typeof(ILuObjectConverterDescriptor<,>);
  43. // var gtype = type.MakeGenericType(typeof(int), typeof(Enumerable));
  44. var result = Parse<TestDbo1>("x.TestDbo2s.Any(y => y.Name == null)");
  45. // var result = Parse<TestDbo1>("System.Linq.Enumerable.Any(x.TestDbo2s, y => y.Name == null)");
  46. }
  47. }
  48. }