コード例 #1
0
        public void CreatorShouldThrowAnArgumentOutOfRangeExceptionWhenTheSourceFieldIsNotAPropertyOfTheModel()
        {
            // arrange
            var creator = new IntegerEqualsExpressionCreator();

            var columnMock = new Mock <IColumn>();

            columnMock.SetupGet(model => model.Field).Returns("UnknownField");

            var searchMock = new Mock <ISearch>();

            var parameterExpression = Expression.Parameter(typeof(TestModel));

            // act & assert
            Assert.Throws <ArgumentOutOfRangeException>(() => creator.CreateExpression <TestModel>(columnMock.Object, searchMock.Object, parameterExpression));
        }
コード例 #2
0
        public void CreatorShouldThrowNotSupportedExceptionWhenTheSearchQueryIsBasedOnARegularExpression()
        {
            // arrange
            var creator = new IntegerEqualsExpressionCreator();

            var columnMock = new Mock <IColumn>();

            columnMock.SetupGet(model => model.Field).Returns(nameof(TestModel.IntProp));

            var searchMock = new Mock <ISearch>();

            searchMock.SetupGet(search => search.IsRegex).Returns(true);

            var parameterExpression = Expression.Parameter(typeof(TestModel));

            // act & assert
            Assert.Throws <NotSupportedException>(() => creator.CreateExpression <TestModel>(columnMock.Object, searchMock.Object, parameterExpression));
        }
コード例 #3
0
        public void CreatorShouldReturnNoItemsWhenTheQueryDoesNotContainAnIntegerValue()
        {
            // arrange
            var creator = new IntegerEqualsExpressionCreator();

            var columnMock = new Mock <IColumn>();

            columnMock.SetupGet(model => model.Field).Returns(nameof(TestModel.IntProp));

            var searchMock = new Mock <ISearch>();

            searchMock.SetupGet(search => search.IsRegex).Returns(false);
            searchMock.SetupGet(search => search.Value).Returns("One");

            var parameterExpression = Expression.Parameter(typeof(TestModel));

            // act
            var searchExpression = creator.CreateExpression <TestModel>(columnMock.Object, searchMock.Object, parameterExpression);

            // assert
            Assert.Null(searchExpression);
        }
コード例 #4
0
        public void CreatorShouldReturnAnExpressionThatCorrectlyFiltersAListUsingEqualsMethod()
        {
            // arrange
            var creator = new IntegerEqualsExpressionCreator();

            var columnMock = new Mock <IColumn>();

            columnMock.SetupGet(model => model.Field).Returns(nameof(TestModel.IntProp));

            var searchMock = new Mock <ISearch>();

            searchMock.SetupGet(search => search.IsRegex).Returns(false);
            searchMock.SetupGet(search => search.Value).Returns("1");

            var parameterExpression = Expression.Parameter(typeof(TestModel));

            var testItemToBeFound = new TestModel()
            {
                IntProp = 1
            };
            var testItemNotToBeFound = new TestModel()
            {
                IntProp = 2
            };

            var testList = new List <TestModel>()
            {
                testItemToBeFound,
                testItemNotToBeFound
            };

            // act
            var searchExpression = creator.CreateExpression <TestModel>(columnMock.Object, searchMock.Object, parameterExpression);
            var searchResults    = testList.Where(searchExpression.Compile());

            // assert
            Assert.Collection(searchResults, searchHit => Assert.Equal(testItemToBeFound, searchHit));
        }