123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using System.Linq;
- using Luticate2.Utils.Dbo;
- using Luticate2.Utils.Dbo.OrderBy;
- using Luticate2.Utils.Dbo.Result;
- using Xunit;
-
- namespace Test.Utils.Binders
- {
- public class LuOrderByBinderTest
- {
- [Fact]
- public void Test1()
- {
- var res = LuOrderByBinder.FromString("");
- Assert.NotNull(res);
- Assert.Equal(LuStatus.Success, res.Status);
- var dbo = res.Data;
- Assert.NotNull(dbo);
- Assert.NotNull(dbo.Fields);
- Assert.Equal(0, dbo.Fields.Count);
- }
-
- [Fact]
- public void Test2()
- {
- var res = LuOrderByBinder.FromString("test");
- Assert.NotNull(res);
- Assert.Equal(LuStatus.Success, res.Status);
- var dbo = res.Data;
- Assert.NotNull(dbo);
- Assert.NotNull(dbo.Fields);
- Assert.Equal(1, dbo.Fields.Count);
-
- var field = dbo.Fields[0];
- Assert.NotNull(field);
- Assert.True(field.Asc);
- Assert.Equal("test", field.Name);
- }
-
- [Fact]
- public void Test3()
- {
- var res = LuOrderByBinder.FromString("test,test2");
- Assert.NotNull(res);
- Assert.Equal(LuStatus.Success, res.Status);
- var dbo = res.Data;
- Assert.NotNull(dbo);
- Assert.NotNull(dbo.Fields);
- Assert.Equal(2, dbo.Fields.Count);
-
- var field = dbo.Fields[0];
- Assert.NotNull(field);
- Assert.True(field.Asc);
- Assert.Equal("test", field.Name);
-
- field = dbo.Fields[1];
- Assert.NotNull(field);
- Assert.True(field.Asc);
- Assert.Equal("test2", field.Name);
- }
-
- [Fact]
- public void Test4()
- {
- var res = LuOrderByBinder.FromString("test:DESC,test2:ASC");
- Assert.NotNull(res);
- Assert.Equal(LuStatus.Success, res.Status);
- var dbo = res.Data;
- Assert.NotNull(dbo);
- Assert.NotNull(dbo.Fields);
- Assert.Equal(2, dbo.Fields.Count);
-
- var field = dbo.Fields[0];
- Assert.NotNull(field);
- Assert.False(field.Asc);
- Assert.Equal("test", field.Name);
-
- field = dbo.Fields[1];
- Assert.NotNull(field);
- Assert.True(field.Asc);
- Assert.Equal("test2", field.Name);
- }
-
- [Fact]
- public void Test5()
- {
- var res = LuOrderByBinder.FromString(",test2:ASC");
- Assert.NotNull(res);
- Assert.Equal(LuStatus.InputError, res.Status);
- }
-
- [Fact]
- public void Test6()
- {
- var res = LuOrderByBinder.FromString("test2:ASC,");
- Assert.NotNull(res);
- Assert.Equal(LuStatus.InputError, res.Status);
- }
-
- [Fact]
- public void Test7()
- {
- var res = LuOrderByBinder.FromString(",");
- Assert.NotNull(res);
- Assert.Equal(LuStatus.InputError, res.Status);
- }
-
- [Fact]
- public void Test8()
- {
- var res = LuOrderByBinder.FromString("test:firstOrder");
- Assert.NotNull(res);
- Assert.Equal(LuStatus.InputError, res.Status);
- }
-
- [Fact]
- public void Test9()
- {
- var res = LuOrderByBinder.FromString("test:42:ASC");
- Assert.NotNull(res);
- Assert.Equal(LuStatus.InputError, res.Status);
- }
- }
- }
|