Esempio n. 1
0
        public void GivenAValidCompartmentSearchWithNullResourceType_WhenCreated_ThenCorrectCompartmentSearchExpressionShouldBeGenerated(CompartmentType compartmentType, string compartmentId)
        {
            SearchOptions options = CreateSearchOptions(
                resourceType: null,
                queryParameters: null,
                compartmentType.ToString(),
                compartmentId);

            Assert.NotNull(options);
            ValidateCompartmentSearchExpression(options.Expression, compartmentType.ToString(), compartmentId);
        }
Esempio n. 2
0
        public void GivenAValidCompartmentSearch_WhenCreated_ThenCorrectCompartmentSearchExpressionShouldBeGenerated(ResourceType resourceType, CompartmentType compartmentType, string compartmentId)
        {
            SearchOptions options = CreateSearchOptions(
                resourceType: resourceType.ToString(),
                queryParameters: null,
                compartmentType.ToString(),
                compartmentId);

            Assert.NotNull(options);
            ValidateMultiaryExpression(
                options.Expression,
                MultiaryOperator.And,
                e => ValidateResourceTypeSearchParameterExpression(e, resourceType.ToString()),
                e => ValidateCompartmentSearchExpression(e, compartmentType.ToString(), compartmentId));
        }
        public void GivenSearchIndicesWithMultipleReferenceSearchParams_WhenExtracted_ThenCorrectIndicesExtracted(CompartmentType expectedCompartmentType1, CompartmentType expectedCompartmentType2, CompartmentType expectedCompartmentType3)
        {
            HashSet <string> compParams = null;
            string           expectedCareTeamResource = ResourceType.CareTeam.ToString();

            // Setup the compartment search definitions.
            string expectedCompartmentType1Str = expectedCompartmentType1.ToString();

            _compartmentManager.TryGetSearchParams(expectedCareTeamResource, expectedCompartmentType1Str, out compParams)
            .Returns(x =>
            {
                x[2] = new HashSet <string> {
                    _referenceSearchTestParam.Name
                };
                return(true);
            });
            string expectedCompartmentType2Str = expectedCompartmentType2.ToString();

            _compartmentManager.TryGetSearchParams(expectedCareTeamResource, expectedCompartmentType2Str, out compParams)
            .Returns(x =>
            {
                x[2] = new HashSet <string> {
                    _anotherReferenceSearchTestParam.Name
                };
                return(true);
            });
            string expectedCompartmentType3Str = expectedCompartmentType3.ToString();

            _compartmentManager.TryGetSearchParams(expectedCareTeamResource, expectedCompartmentType3Str, out compParams)
            .Returns(x =>
            {
                x[2] = new HashSet <string> {
                    _yetAnotherReferenceSearchTestParam.Name
                };
                return(true);
            });
            const string ExpectedResourceIdR1 = "r1";
            const string ExpectedResourceIdR2 = "r2";
            const string ExpectedResourceIdR3 = "r3";

            // Setup multiple reference search parameters with expected resource ids for the compartments.
            var searchIndexEntries = new List <SearchIndexEntry>
            {
                new SearchIndexEntry(_referenceSearchTestParam, new ReferenceSearchValue(ReferenceKind.InternalOrExternal, _baseUri, CompartmentDefinitionManager.CompartmentTypeToResourceType(expectedCompartmentType1Str).ToString(), ExpectedResourceIdR1)),
                new SearchIndexEntry(_anotherReferenceSearchTestParam, new ReferenceSearchValue(ReferenceKind.Internal, _baseUri, CompartmentDefinitionManager.CompartmentTypeToResourceType(expectedCompartmentType2Str).ToString(), ExpectedResourceIdR2)),
                new SearchIndexEntry(_yetAnotherReferenceSearchTestParam, new ReferenceSearchValue(ReferenceKind.External, _baseUri, CompartmentDefinitionManager.CompartmentTypeToResourceType(expectedCompartmentType3Str).ToString(), ExpectedResourceIdR3)),
            };

            CompartmentIndices compartmentIndices = _compartmentIndexer.Extract(expectedCareTeamResource, searchIndexEntries);

            Assert.Collection(GetResourceIdsForCompartmentType(expectedCompartmentType1, compartmentIndices), r => string.Equals(ExpectedResourceIdR1, r, StringComparison.OrdinalIgnoreCase));
            Assert.Collection(GetResourceIdsForCompartmentType(expectedCompartmentType2, compartmentIndices), r => string.Equals(ExpectedResourceIdR2, r, StringComparison.OrdinalIgnoreCase));
            Assert.Collection(GetResourceIdsForCompartmentType(expectedCompartmentType3, compartmentIndices), r => string.Equals(ExpectedResourceIdR3, r, StringComparison.OrdinalIgnoreCase));
        }
Esempio n. 4
0
        public void GivenSearchParamsWithValidCompartmentSearch_WhenCreated_ThenCorrectCompartmentSearchExpressionShouldBeGenerated(ResourceType resourceType, CompartmentType compartmentType, string compartmentId)
        {
            const string paramName1 = "address-city";
            const string paramName2 = "address-state";
            const string value1     = "Seattle";
            const string value2     = "WA";

            Expression expression1 = Substitute.For <Expression>();
            Expression expression2 = Substitute.For <Expression>();

            _expressionParser.Parse(resourceType.ToString(), paramName1, value1).Returns(expression1);
            _expressionParser.Parse(resourceType.ToString(), paramName2, value2).Returns(expression2);

            var queryParameters = new[]
            {
                Tuple.Create(paramName1, value1),
                Tuple.Create(paramName2, value2),
            };

            SearchOptions options = CreateSearchOptions(
                resourceType: resourceType.ToString(),
                queryParameters: queryParameters,
                compartmentType.ToString(),
                compartmentId);

            Assert.NotNull(options);
            Assert.NotNull(options.Expression);

            ValidateMultiaryExpression(
                options.Expression,
                MultiaryOperator.And,
                e => ValidateResourceTypeSearchParameterExpression(e, resourceType.ToString()),
                e => Assert.Equal(expression1, e),
                e => Assert.Equal(expression2, e),
                e => ValidateCompartmentSearchExpression(e, compartmentType.ToString(), compartmentId));
        }
        public void GivenSearchIndicesWithResourceTypeAndCompartmentTypeAndNullReferenceSearchResourceType_WhenExtracted_ThenNoIndicesExtracted(ResourceType resourceType, CompartmentType compartmentType, ReferenceKind referenceKind, string expectedResourceId)
        {
            HashSet <string> compParams = null;

            _compartmentManager.TryGetSearchParams(resourceType.ToString(), compartmentType.ToString(), out compParams)
            .Returns(x =>
            {
                x[2] = new HashSet <string> {
                    _referenceSearchTestParam.Name
                };
                return(true);
            });
            var searchIndexEntries = new List <SearchIndexEntry>
            {
                new SearchIndexEntry(_referenceSearchTestParam, new ReferenceSearchValue(referenceKind, null, null, expectedResourceId)),
            };
            CompartmentIndices compartmentIndices = _compartmentIndexer.Extract(resourceType.ToString(), searchIndexEntries);

            Assert.Null(GetResourceIdsForCompartmentType(compartmentType, compartmentIndices));
        }
        public void GivenSearchIndicesWithResourceTypeAndCompartmentType_WhenExtracted_ThenCorrectIndicesExtracted(ResourceType resourceType, CompartmentType compartmentType, ReferenceKind referenceKind, string expectedResourceId)
        {
            HashSet <string> compParams = null;

            _compartmentManager.TryGetSearchParams(resourceType.ToString(), compartmentType.ToString(), out compParams)
            .Returns(x =>
            {
                x[2] = new HashSet <string> {
                    _referenceSearchTestParam.Name, _nonReferenceReferenceSearchTestParam.Name
                };
                return(true);
            });
            var searchIndexEntries = new List <SearchIndexEntry>
            {
                new SearchIndexEntry(_referenceSearchTestParam, new ReferenceSearchValue(referenceKind, _baseUri, CompartmentDefinitionManager.CompartmentTypeToResourceType(compartmentType.ToString()).ToString(), expectedResourceId)),
                new SearchIndexEntry(_nonReferenceReferenceSearchTestParam, new StringSearchValue("aadsdas")),
            };
            CompartmentIndices compartmentIndices = _compartmentIndexer.Extract(resourceType.ToString(), searchIndexEntries);

            Assert.Collection(GetResourceIdsForCompartmentType(compartmentType, compartmentIndices), r => string.Equals(expectedResourceId, r, StringComparison.OrdinalIgnoreCase));
        }
 public static ResourceType CompartmentTypeToResourceType(CompartmentType compartmentType)
 {
     EnsureArg.IsTrue(Enum.IsDefined(typeof(CompartmentType), compartmentType), nameof(compartmentType));
     return(ModelInfo.FhirTypeNameToResourceType(compartmentType.ToString()).Value);
 }
 public void GivenAValidCompartmentDefinitionBundle_WhenValidated_ThenValidSearchParams(ResourceType resourceType, CompartmentType compartmentType, int testCount)
 {
     Assert.True(_validBuiltCompartment.TryGetSearchParams(resourceType.ToString(), compartmentType.ToString(), out HashSet <string> searchParams));
     Assert.Equal(testCount, searchParams.Count);
 }