Example #1
0
        /// <summary>
        /// Returns the value needed by the search query value.
        /// </summary>
        /// <typeparam name="T">The type of <see cref="IndexableEntity"/> implementation to use.</typeparam>
        /// <param name="searchQueryRule">The specifed search query rule</param>
        /// <returns>A typed value</returns>
        public object GetValueForSearchQueryRule <T>(SearchQueryRule <T> searchQueryRule) where T : IndexableEntity, new()
        {
            Assert.ArgumentNotNull(searchQueryRule, "searchQueryRule");

            object retVal;

            var value = GetRawDefaultOrDynamicValueProvidedByParameter(searchQueryRule);

            if (string.IsNullOrWhiteSpace(value))
            {
                return(null);
            }

            var propertyType = ExpressionUtils.GetPropertyTypeFromPropertySelector(searchQueryRule.PropertySelector);

            Tuple <string, string> rangeValueParts;

            if (SearchQueryValueConversionService.TryConvertToRangeValueParts(value, out rangeValueParts))
            {
                var lowerValue = SearchQueryValueConversionService.ToTypedValue(propertyType, rangeValueParts.Item1);
                var upperValue = SearchQueryValueConversionService.ToTypedValue(propertyType, rangeValueParts.Item2);

                retVal = new RangeValue(lowerValue, upperValue);
            }
            else
            {
                retVal = SearchQueryValueConversionService.ToTypedValue(propertyType, value);
            }

            return(retVal);
        }
        public void TryConvertToRangeValueParts_ValueIsNull_ThrowsException()
        {
            // Arrange
            string value = null;
            Tuple <string, string> rangeValueParts;

            // Acts
            Action act = () => SearchQueryValueConversionService.TryConvertToRangeValueParts(value, out rangeValueParts);

            // Assert
            act.ShouldThrow <ArgumentNullException>();
        }
        public void TryConvertToRangeValueParts_ValueIsNotInValidRangeFormat_ReturnsNull()
        {
            // Arrange
            string value = "1:2";
            Tuple <string, string> actualRangeValueParts;

            // Acts
            var actual = SearchQueryValueConversionService.TryConvertToRangeValueParts(value, out actualRangeValueParts);

            // Assert
            actual.Should().BeFalse();
            actualRangeValueParts.Should().BeNull();
        }
        public void TryConvertToRangeValueParts_ValueIsValidRangeFormat_ReturnsRangeValueParts
            (string value, string firstPart, string secondPart)
        {
            // Arrange
            Tuple <string, string> actualRangeValueParts;
            Tuple <string, string> expectedRangeValueParts = new Tuple <string, string>(firstPart, secondPart);

            // Acts
            var actual = SearchQueryValueConversionService.TryConvertToRangeValueParts(value, out actualRangeValueParts);

            // Assert
            actual.Should().BeTrue();
            actualRangeValueParts.ShouldBeEquivalentTo(expectedRangeValueParts);
        }