Example #1
0
        public void ShouldSupportMultipleFiltering()
        {
            // arrange
            const bool   isEvenFilterValue = true;
            const string nameFilterValue   = "TestName_6";
            var          filterFields      = new FilterField <TestModel> [2];

            filterFields[0] = new FilterField <TestModel>
            {
                PropertyName = "IsEven",
                FilterValue  = isEvenFilterValue
            };
            filterFields[1] = new FilterField <TestModel>
            {
                PropertyName = "Name",
                FilterValue  = nameFilterValue
            };
            var expectedData = testData.Where(t => t.IsEven == (isEvenFilterValue))
                               .Where(t => t.Name.Contains(nameFilterValue));
            // act
            var result = filterFields.Filter(testData);

            // assert
            result.Should().BeEquivalentTo(expectedData);
        }
Example #2
0
        public void ShouldReturnOriginalDataWhenFilteringFieldEmpty()
        {
            // arrange
            var filterFields = new FilterField <TestModel> [0];
            // act
            var result = filterFields.Filter(testData);

            // assert
            result.Should().BeEquivalentTo(testData);
        }
Example #3
0
        public void ShouldReturnFilteredDataWhenNonStringFilteringFieldProvided()
        {
            // arrange
            const string propertyName = "IsEven";
            const bool   filterValue  = true;
            var          filterField  = new FilterField <TestModel>(propertyName, filterValue);
            var          expectedData = testData.Where(t => t.IsEven == (filterValue));
            // act
            var result = filterField.Filter(testData);

            // assert
            result.Should().BeEquivalentTo(expectedData);
        }
Example #4
0
        public void ShouldReturnEveryElement()
        {
            // arrange
            const string propertyName = "Name";
            const string filterValue  = "TestName";
            var          filterField  = new FilterField <TestModel>(propertyName, filterValue);
            var          expectedData = testData.Where(t => t.Name.Contains(filterValue));
            // act
            var result = filterField.Filter(testData);

            // assert
            result.Should().BeEquivalentTo(expectedData);
        }
Example #5
0
        public void ShouldReturnFilteredDataWhenStringFullNameFilteringFieldProvided()
        {
            // arrange
            const string propertyName = "Name";
            const string filterValue  = "TestName_6";
            var          filterField  = new FilterField <TestModel>(propertyName, filterValue);
            var          expectedData = testData.Where(t => t.Name == filterValue);
            // act
            var result = filterField.Filter(testData);

            // assert
            result.Should().BeEquivalentTo(expectedData);
        }