Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

LuOrderByBinderTest.cs 3.5KB

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