123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- using System.Collections.Generic;
- using Luticate2.Utils.Dbo.Filter;
- using Luticate2.Utils.Dbo.Result;
- using Xunit;
-
- namespace TestUtils.Binders
- {
- public class LuFilterBinderTest
- {
- [Fact]
- public void Test1()
- {
- var res = LuFilterBinder.FromString("");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>(), res.Data.Filters);
- }
-
- [Fact]
- public void Test2()
- {
- var res = LuFilterBinder.FromString("test");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("test", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>(), res.Data.Filters);
- }
-
- [Fact]
- public void Test3()
- {
- var res = LuFilterBinder.FromString(" Test.42 24 ");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("Test.42 24", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>(), res.Data.Filters);
- }
-
- [Fact]
- public void Test4()
- {
- var res = LuFilterBinder.FromString(" test: 42");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("test: 42", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>(), res.Data.Filters);
- }
-
- [Fact]
- public void Test5()
- {
- var res = LuFilterBinder.FromString("test: 42");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>{{"test", "42"}}, res.Data.Filters);
- }
-
- [Fact]
- public void Test6()
- {
- var res = LuFilterBinder.FromString("test: 42 a filter value");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("a filter value", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>{{"test", "42"}}, res.Data.Filters);
- }
-
- [Fact]
- public void Test7()
- {
- var res = LuFilterBinder.FromString("test: \"42 a filter value\"");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>{{"test", "42 a filter value"}}, res.Data.Filters);
- }
-
- [Fact]
- public void Test8()
- {
- var res = LuFilterBinder.FromString("test: \'42 a filter value\'");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>{{"test", "42 a filter value"}}, res.Data.Filters);
- }
-
- [Fact]
- public void Test9()
- {
- var res = LuFilterBinder.FromString("test: \'42 a filter value\' test-2: ' 42 ' test-3: ' 4 ' test-3: ' ' some text");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("some text", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>
- {
- {"test", "42 a filter value"},
- {"test-2", "42"},
- {"test-3", ""}
- }, res.Data.Filters);
- }
-
- [Fact]
- public void Test10()
- {
- var res = LuFilterBinder.FromString("test: \'42 a filter value\' test-2 : \'another value\' some text");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("some text", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>
- {
- {"test", "42 a filter value"},
- {"test-2", "another value"}
- }, res.Data.Filters);
- }
-
- [Fact]
- public void TestBool()
- {
- var res = LuFilterBinder.FromString("test: true test-2 : \'false\' fail: 42 some text");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("some text", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>
- {
- {"test", "true"},
- {"test-2", "false"},
- {"fail", "42"}
- }, res.Data.Filters);
- Assert.True(res.Data.GetFilterBool("test", false));
- Assert.True(res.Data.GetFilterBool("test", true));
- Assert.False(res.Data.GetFilterBool("test-2", false));
- Assert.False(res.Data.GetFilterBool("test-2", true));
- Assert.False(res.Data.GetFilterBool("fail", false));
- Assert.True(res.Data.GetFilterBool("fail", true));
- Assert.False(res.Data.GetFilterBool("nx", false));
- Assert.True(res.Data.GetFilterBool("nx", true));
- }
-
- [Fact]
- public void TestString()
- {
- var res = LuFilterBinder.FromString("test: 42 test-2 : \'24\' fail: test some text");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("some text", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>
- {
- {"test", "42"},
- {"test-2", "24"},
- {"fail", "test"}
- }, res.Data.Filters);
- Assert.Equal("42", res.Data.GetFilterString("test", ""));
- Assert.Equal("24", res.Data.GetFilterString("test-2", ""));
- Assert.Equal("test", res.Data.GetFilterString("fail", "azerty"));
- Assert.Equal("qwerty", res.Data.GetFilterString("nx", "qwerty"));
- }
-
- [Fact]
- public void TestInt()
- {
- var res = LuFilterBinder.FromString("test: 42 test-2 : \'24\' fail: test some text");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("some text", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>
- {
- {"test", "42"},
- {"test-2", "24"},
- {"fail", "test"}
- }, res.Data.Filters);
- Assert.Equal(42, res.Data.GetFilterInt("test", 0));
- Assert.Equal(24, res.Data.GetFilterInt("test-2", 0));
- Assert.Equal(2424, res.Data.GetFilterInt("fail", 2424));
- Assert.Equal(4242, res.Data.GetFilterInt("nx", 4242));
- }
-
- [Fact]
- public void TestFloat()
- {
- var res = LuFilterBinder.FromString("test: 42.24 test-2 : \'24.42\' fail:test some text");
- Assert.NotNull(res);
- Assert.NotNull(res.Data);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.Equal("some text", res.Data.Query);
- Assert.Equal(new Dictionary<string, string>
- {
- {"test", "42.24"},
- {"test-2", "24.42"},
- {"fail", "test"}
- }, res.Data.Filters);
- Assert.Equal(42.24, res.Data.GetFilterFloat("test", 0));
- Assert.Equal(24.42, res.Data.GetFilterFloat("test-2", 0));
- Assert.Equal(2424.4242, res.Data.GetFilterFloat("fail", 2424.4242));
- Assert.Equal(4242.2424, res.Data.GetFilterFloat("nx", 4242.2424));
- }
- }
- }
|