You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuOrderByBinderTest.cs 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using Luticate2.Utils.Dbo.OrderBy;
  2. using Luticate2.Utils.Dbo.Result;
  3. using Xunit;
  4. namespace TestUtils.Binders
  5. {
  6. public class LuOrderByBinderTest
  7. {
  8. [Fact]
  9. public void Test1()
  10. {
  11. var res = LuOrderByBinder.FromString("");
  12. Assert.NotNull(res);
  13. Assert.Equal(LuStatus.InputError, res.Status);
  14. }
  15. [Fact]
  16. public void Test2()
  17. {
  18. var res = LuOrderByBinder.FromString("test");
  19. Assert.NotNull(res);
  20. Assert.Equal(LuStatus.Success, res.Status);
  21. var dbo = res.Data;
  22. Assert.NotNull(dbo);
  23. Assert.NotNull(dbo.Fields);
  24. Assert.Equal(1, dbo.Fields.Count);
  25. var field = dbo.Fields[0];
  26. Assert.NotNull(field);
  27. Assert.True(field.Asc);
  28. Assert.Equal("test", field.Name);
  29. }
  30. [Fact]
  31. public void Test3()
  32. {
  33. var res = LuOrderByBinder.FromString("test,test2");
  34. Assert.NotNull(res);
  35. Assert.Equal(LuStatus.Success, res.Status);
  36. var dbo = res.Data;
  37. Assert.NotNull(dbo);
  38. Assert.NotNull(dbo.Fields);
  39. Assert.Equal(2, dbo.Fields.Count);
  40. var field = dbo.Fields[0];
  41. Assert.NotNull(field);
  42. Assert.True(field.Asc);
  43. Assert.Equal("test", field.Name);
  44. field = dbo.Fields[1];
  45. Assert.NotNull(field);
  46. Assert.True(field.Asc);
  47. Assert.Equal("test2", field.Name);
  48. }
  49. [Fact]
  50. public void Test4()
  51. {
  52. var res = LuOrderByBinder.FromString("test:DESC,test2:ASC");
  53. Assert.NotNull(res);
  54. Assert.Equal(LuStatus.Success, res.Status);
  55. var dbo = res.Data;
  56. Assert.NotNull(dbo);
  57. Assert.NotNull(dbo.Fields);
  58. Assert.Equal(2, dbo.Fields.Count);
  59. var field = dbo.Fields[0];
  60. Assert.NotNull(field);
  61. Assert.False(field.Asc);
  62. Assert.Equal("test", field.Name);
  63. field = dbo.Fields[1];
  64. Assert.NotNull(field);
  65. Assert.True(field.Asc);
  66. Assert.Equal("test2", field.Name);
  67. }
  68. [Fact]
  69. public void Test5()
  70. {
  71. var res = LuOrderByBinder.FromString(",test2:ASC");
  72. Assert.NotNull(res);
  73. Assert.Equal(LuStatus.InputError, res.Status);
  74. }
  75. [Fact]
  76. public void Test6()
  77. {
  78. var res = LuOrderByBinder.FromString("test2:ASC,");
  79. Assert.NotNull(res);
  80. Assert.Equal(LuStatus.InputError, res.Status);
  81. }
  82. [Fact]
  83. public void Test7()
  84. {
  85. var res = LuOrderByBinder.FromString(",");
  86. Assert.NotNull(res);
  87. Assert.Equal(LuStatus.InputError, res.Status);
  88. }
  89. [Fact]
  90. public void Test8()
  91. {
  92. var res = LuOrderByBinder.FromString("test:firstOrder");
  93. Assert.NotNull(res);
  94. Assert.Equal(LuStatus.InputError, res.Status);
  95. }
  96. [Fact]
  97. public void Test9()
  98. {
  99. var res = LuOrderByBinder.FromString("test:42:ASC");
  100. Assert.NotNull(res);
  101. Assert.Equal(LuStatus.InputError, res.Status);
  102. }
  103. }
  104. }