public int CompareTo(ISupportSortSearchValue other, ComparisonRange range)
        {
            if (other == null)
            {
                throw new ArgumentException("Value to be compared to cannot be null");
            }

            var otherValue = other as DateTimeSearchValue;

            if (otherValue == null)
            {
                throw new ArgumentException($"Value to be compared should be of type {typeof(DateTimeSearchValue)}");
            }

            switch (range)
            {
            case ComparisonRange.Min:
                return(DateTimeOffset.Compare(Start, otherValue.Start));

            case ComparisonRange.Max:
                return(DateTimeOffset.Compare(End, otherValue.End));

            default:
                throw new ArgumentOutOfRangeException(nameof(range));
            }
        }
        public void GivenOneStringSearchValueForEachParameter_WhenCreate_ThenBothMinMaxSetToTrue()
        {
            var searchIndexEntry1 = new SearchIndexEntry(_nameSearchParameterInfo, new StringSearchValue("alpha"));
            var searchIndexEntry2 = new SearchIndexEntry(_addressSearchParameterInfo, new StringSearchValue("redmond"));

            _searchIndexer
            .Extract(Arg.Any <ResourceElement>())
            .Returns(new List <SearchIndexEntry>()
            {
                searchIndexEntry1, searchIndexEntry2
            });

            ResourceElement resource        = Samples.GetDefaultPatient(); // Resource does not matter for this test.
            ResourceWrapper resourceWrapper = _resourceWrapperFactory.Create(resource, deleted: false, keepMeta: false);

            foreach (SearchIndexEntry searchEntry in resourceWrapper.SearchIndices)
            {
                ISupportSortSearchValue searchEntryValue = searchEntry.Value as ISupportSortSearchValue;
                switch (searchEntry.Value.ToString())
                {
                case "alpha":
                    Assert.True(searchEntryValue.IsMin);
                    Assert.True(searchEntryValue.IsMax);
                    break;

                case "redmond":
                    Assert.True(searchEntryValue.IsMin);
                    Assert.True(searchEntryValue.IsMax);
                    break;

                default:
                    throw new Exception("Unexpected value");
                }
            }
        }
        /// <inheritdoc />
        public int CompareTo(ISupportSortSearchValue supportSortSearchValue, ComparisonRange range)
        {
            if (supportSortSearchValue == null)
            {
                throw new ArgumentException("Value to be compared to cannot be null");
            }

            var otherValue = supportSortSearchValue as StringSearchValue;

            if (otherValue == null)
            {
                throw new ArgumentException($"Value to be compared should be of type {typeof(StringSearchValue)}");
            }

            return(string.Compare(ToString(), otherValue.ToString(), CultureInfo.InvariantCulture, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase));
        }
Пример #4
0
        /// <inheritdoc />
        public int CompareTo(ISupportSortSearchValue other, ComparisonRange range)
        {
            if (other == null)
            {
                throw new ArgumentException("Value to be compared to cannot be null");
            }

            var otherValue = other as StringSearchValue;

            if (otherValue == null)
            {
                throw new ArgumentException($"Value to be compared should be of type {typeof(StringSearchValue)}");
            }

            // We want to do a case and accent insensitive comparison here.
            // This is to be in-line with the collation used in our SQL tables for the StringSearchParam values
#pragma warning disable CA1309
            return(string.Compare(ToString(), otherValue.ToString(), CultureInfo.InvariantCulture, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase));

#pragma warning restore CA1309
        }