Esempio n. 1
0
        public void FilterModifier_MultipleFiltersOneByOne_ReturnsCorrectQueryParam()
        {
            // Arrange
            var modifier = new FilterModifier <TestFilter>();
            Func <TestFilter, FilterExpression> filterExpression1 = (f) => f.Id.IsEqual(100);
            Func <TestFilter, FilterExpression> filterExpression2 = (f) => f.Name.Contains("a.s.");
            Func <TestFilter, FilterExpression> filterExpression3 = (f) => f.Date.IsEqual(DateTime.Now);

            modifier.Filter(filterExpression1);
            modifier.Filter(filterExpression2);
            modifier.Filter(filterExpression3);

            // Act
            var queryParams = modifier.GetQueryParameters();

            // Assert
            Assert.AreEqual(2, queryParams.Count);
            Assert.IsTrue(queryParams.TryGetValue("filter", out var filter));
            var filter1 = GetFilterExpression(filterExpression1);
            var filter2 = GetFilterExpression(filterExpression2);
            var filter3 = GetFilterExpression(filterExpression3);

            Assert.AreEqual($"{filter1}|{filter2}|{filter3}", filter);
            Assert.IsTrue(queryParams.TryGetValue("filterType", out var filterType));
            Assert.AreEqual("and", filterType);
        }
Esempio n. 2
0
        public void FilterModifier_AddComplexFilterAfterComplexFilter_ThrowsException()
        {
            // Arrange
            var modifier = new FilterModifier <TestFilter>();

            modifier.Filter(f => f.Name.Contains("a.s.") || f.Name.Contains("s.r.o."));

            // Act + Assert
            Assert.Throws <InvalidOperationException>(() => modifier.Filter(f => f.Name.Contains("aaa") || f.Name.Contains("bbb")));
        }
Esempio n. 3
0
        public void FilterModifier_ComplexExpression_ReturnsCorrectQueryParam()
        {
            // Arrange
            var modifier = new FilterModifier <TestFilter>();
            Func <TestFilter, FilterExpression> filterExpression1 = (f) => f.Id.IsEqual(100);
            Func <TestFilter, FilterExpression> filterExpression2 = (f) => f.Name.Contains("a.s.");
            Func <TestFilter, FilterExpression> filterExpression3 = (f) => f.Name.Contains("s.r.o.");
            Func <TestFilter, FilterExpression> filterExpression4 = (f) => f.Name.Contains("s.r.o.");
            Func <TestFilter, FilterExpression> filterExpression5 = (f) => f.Date.IsLowerThan(new DateTime(2020, 1, 1));

            modifier.Filter(f => (filterExpression1(f) && (filterExpression2(f) || filterExpression3(f) || filterExpression4(f))) || filterExpression5(f));

            // Act
            var queryParams = modifier.GetQueryParameters();

            // Assert
            Assert.AreEqual(1, queryParams.Count);
            Assert.IsTrue(queryParams.TryGetValue("filter", out var filter));
            var filter1 = GetFilterExpression(filterExpression1);
            var filter2 = GetFilterExpression(filterExpression2);
            var filter3 = GetFilterExpression(filterExpression3);
            var filter4 = GetFilterExpression(filterExpression4);
            var filter5 = GetFilterExpression(filterExpression5);

            Assert.AreEqual($"(({filter1}~and~(({filter2}~or~{filter3})~or~{filter4}))~or~{filter5})", filter);
        }
Esempio n. 4
0
        public void FilterModifier_TwoSimpleExpressionsWithAnd_ReturnsCorrectQueryParam()
        {
            // Arrange
            var modifier = new FilterModifier <TestFilter>();
            Func <TestFilter, FilterExpression> filterExpression1 = (f) => f.Id.IsEqual(100);
            Func <TestFilter, FilterExpression> filterExpression2 = (f) => f.Name.Contains("a.s.");

            modifier.Filter(f => filterExpression1(f) && filterExpression2(f));

            // Act
            var queryParams = modifier.GetQueryParameters();

            // Assert
            Assert.AreEqual(1, queryParams.Count);
            Assert.IsTrue(queryParams.TryGetValue("filter", out var filter));
            var filter1 = GetFilterExpression(filterExpression1);
            var filter2 = GetFilterExpression(filterExpression2);

            Assert.AreEqual($"({filter1}~and~{filter2})", filter);
        }
Esempio n. 5
0
        public void FilterModifier_SingleFilter_ReturnsCorrectQueryParam()
        {
            // Arrange
            var modifier = new FilterModifier <TestFilter>();
            Func <TestFilter, FilterExpression> filterExpression = (f) => f.Name.Contains("a");

            modifier.Filter(filterExpression);

            // Act
            var queryParams = modifier.GetQueryParameters();

            // Assert
            Assert.AreEqual(2, queryParams.Count);
            Assert.IsTrue(queryParams.TryGetValue("filter", out var filter));
            var filterString = GetFilterExpression(filterExpression);

            Assert.AreEqual(filterString, filter);
            Assert.IsTrue(queryParams.TryGetValue("filterType", out var filterType));
            Assert.AreEqual("and", filterType);
        }
Esempio n. 6
0
        public void FilterModifier_ThreeSimpleExpressionsWithOr_ReturnsCorrectQueryParam()
        {
            // Arrange
            var modifier = new FilterModifier <TestFilter>();
            Func <TestFilter, FilterExpression> filterExpression1 = (f) => f.Name.Contains("a.s.");
            Func <TestFilter, FilterExpression> filterExpression2 = (f) => f.Name.Contains("s.r.o.");
            Func <TestFilter, FilterExpression> filterExpression3 = (f) => f.Name.Contains("k.s.");

            modifier.Filter(f => filterExpression1(f) || filterExpression2(f) || filterExpression3(f));

            // Act
            var queryParams = modifier.GetQueryParameters();

            // Assert
            Assert.AreEqual(1, queryParams.Count);
            Assert.IsTrue(queryParams.TryGetValue("filter", out var filter));
            var filter1 = GetFilterExpression(filterExpression1);
            var filter2 = GetFilterExpression(filterExpression2);
            var filter3 = GetFilterExpression(filterExpression3);

            Assert.AreEqual($"(({filter1}~or~{filter2})~or~{filter3})", filter);
        }
Esempio n. 7
0
 /// <summary>
 /// Filter for a list.
 /// </summary>
 /// <param name="filter">Filter expressions.</param>
 /// <returns>List of models.</returns>
 public TList Filter(params Func <TFilter, FilterExpression>[] filter)
 {
     _filter.Filter(filter);
     return(This);
 }