コード例 #1
0
        public async void Verify_Argument_passing(string dictionary, AudienceType audience, string language, string queryText, MatchType matchType)
        {
            const int expecedSizeRequest = 20;

            Mock <IAutosuggestQueryService> querySvc   = new Mock <IAutosuggestQueryService>();
            AutosuggestController           controller = new AutosuggestController(querySvc.Object);

            // Set up the mock query service to return an empty array.
            querySvc.Setup(
                autoSuggestQSvc => autoSuggestQSvc.GetSuggestions(
                    It.IsAny <string>(),
                    It.IsAny <AudienceType>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <MatchType>(),
                    It.IsAny <int>()
                    )
                )
            .Returns(Task.FromResult(new Suggestion[] { }));

            Suggestion[] result = await controller.GetSuggestions(dictionary, audience, language, queryText, matchType);

            // Verify that the service layer is called:
            //  a) with the exact values passed to the controller.
            //  b) exactly once.
            querySvc.Verify(
                svc => svc.GetSuggestions(dictionary, audience, language, queryText, matchType, expecedSizeRequest),
                Times.Once
                );

            Assert.Empty(result);
        }
コード例 #2
0
        public async void SearchText(string searchString)
        {
            // Set up the mock query service
            Mock <IAutosuggestQueryService> querySvc   = new Mock <IAutosuggestQueryService>();
            AutosuggestController           controller = new AutosuggestController(new NullLogger <AutosuggestController>(), querySvc.Object);

            querySvc.Setup(
                autoSuggestQSvc => autoSuggestQSvc.GetSuggestions(
                    It.IsAny <string>(),
                    It.IsAny <MatchType>(),
                    It.IsAny <int>(),
                    It.IsAny <DrugResourceType[]>(),
                    It.IsAny <TermNameType[]>(),
                    It.IsAny <TermNameType[]>()
                    )
                )
            .Returns(Task.FromResult(new Suggestion[0]));

            // The search return doesn't matter for this test, so don't capture it.
            await controller.GetSuggestions(searchString);

            querySvc.Verify(
                svc => svc.GetSuggestions(
                    searchString,
                    It.IsAny <MatchType>(),
                    It.IsAny <int>(),
                    It.IsAny <DrugResourceType[]>(),
                    It.IsAny <TermNameType[]>(),
                    It.IsAny <TermNameType[]>()
                    ),
                Times.Once
                );
        }
コード例 #3
0
        public async void Autosuggest(BaseAutosuggestControllerScenario data)
        {
            // Sanity check for test data.  The expected result array should never
            // be larger than the value of the Size property. (Smaller is fine.)
            Assert.InRange(data.ExpectedResult.Length, 0, data.Size);

            // Set up the mock query service
            Mock <IAutosuggestQueryService> querySvc   = new Mock <IAutosuggestQueryService>();
            AutosuggestController           controller = new AutosuggestController(new NullLogger <AutosuggestController>(), querySvc.Object);

            querySvc.Setup(
                autoSuggestQSvc => autoSuggestQSvc.GetSuggestions(
                    It.IsAny <string>(),
                    It.IsAny <MatchType>(),
                    It.IsAny <int>(),
                    It.IsAny <DrugResourceType[]>(),
                    It.IsAny <TermNameType[]>(),
                    It.IsAny <TermNameType[]>()
                    )
                )
            .Returns(Task.FromResult(data.Data));

            // The search text doesn't matter.
            Suggestion[] actual = await controller.GetSuggestions("chicken", data.MatchType, data.Size);

            Assert.Equal(data.ExpectedResult, actual, new ArrayComparer <Suggestion, SuggestionComparer>());
        }
コード例 #4
0
        public async void GetSuggestions_ErrorMessage_AudienceType()
        {
            Mock <IAutosuggestQueryService> querySvc   = new Mock <IAutosuggestQueryService>();
            AutosuggestController           controller = new AutosuggestController(querySvc.Object);
            APIErrorException exception = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.GetSuggestions("Dictionary", (AudienceType)(-20937), "EN", "Query", true, 20, 0)
                );

            Assert.Equal("You must supply a valid dictionary, audience and language.", exception.Message);
        }
コード例 #5
0
        public async void GetSuggestions_ErrorMessage_LanguageBad()
        {
            Mock <IAutosuggestQueryService> querySvc   = new Mock <IAutosuggestQueryService>();
            AutosuggestController           controller = new AutosuggestController(querySvc.Object);
            APIErrorException exception = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.GetSuggestions("glossary", AudienceType.Patient, "invalid", "suggest", true, 20, 0)
                );

            Assert.Equal("Unsupported Language. Valid values are 'en' and 'es'.", exception.Message);
        }
コード例 #6
0
        public async void GetSuggestions_ErrorMessage_LanguageMissing()
        {
            Mock <IAutosuggestQueryService> querySvc   = new Mock <IAutosuggestQueryService>();
            AutosuggestController           controller = new AutosuggestController(querySvc.Object);
            APIErrorException exception = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.GetSuggestions("glossary", AudienceType.HealthProfessional, "", "suggest", false, 20, 0)
                );

            Assert.Equal("You must supply a valid dictionary, audience and language.", exception.Message);
        }
コード例 #7
0
        public async void Verify_Negative_Value_Handling()
        {
            const string       dictionary  = "Cancer.gov";
            const AudienceType audience    = AudienceType.Patient;
            const string       language    = "en";
            const string       queryText   = "chicken";
            const bool         contains    = true;
            const int          invalidSize = -200;
            const int          invalidFrom = -100;

            const int expecedSizeRequest  = 20;
            const int expectedFromRequest = 0;

            Mock <IAutosuggestQueryService> querySvc   = new Mock <IAutosuggestQueryService>();
            AutosuggestController           controller = new AutosuggestController(querySvc.Object);

            // Set up the mock query service to return an empty array.
            querySvc.Setup(
                autoSuggestQSvc => autoSuggestQSvc.GetSuggestions(
                    It.IsAny <string>(),
                    It.IsAny <AudienceType>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <bool>(),
                    It.IsAny <int>(),
                    It.IsAny <int>()
                    )
                )
            .Returns(Task.FromResult(new Suggestion[] { }));

            Suggestion[] result = await controller.GetSuggestions(dictionary, audience, language, queryText, contains, invalidSize, invalidFrom);

            // Verify that the service layer is called:
            //  a) with the expected values.
            //  b) exactly once.
            querySvc.Verify(
                svc => svc.GetSuggestions(dictionary, audience, language, queryText, contains, expecedSizeRequest, expectedFromRequest),
                Times.Once
                );

            Assert.Empty(result);
        }
コード例 #8
0
        public async void Verify_Zero_Size_Handling()
        {
            const string    queryText   = "chicken";
            const MatchType matchType   = MatchType.Begins;
            const int       invalidSize = 0;

            const int expecedSizeRequest = 20;

            DrugResourceType[] expectedResourceTypes     = DEFAULT_DRUG_RESOURCE_TYPE_LIST;
            TermNameType[]     expectedIncludedTermTypes = DEFAULT_INCLUDED_TERM_TYPE_LIST;
            TermNameType[]     expectedExclusionList     = DEFAULT_EXCLUDED_TERM_TYPE_LIST;

            Mock <IAutosuggestQueryService> querySvc   = new Mock <IAutosuggestQueryService>();
            AutosuggestController           controller = new AutosuggestController(NullLogger <AutosuggestController> .Instance, querySvc.Object);

            // Set up the mock query service to return an empty array.
            querySvc.Setup(
                autoSuggestQSvc => autoSuggestQSvc.GetSuggestions(
                    It.IsAny <string>(),
                    It.IsAny <MatchType>(),
                    It.IsAny <int>(),
                    It.IsAny <DrugResourceType[]>(),
                    It.IsAny <TermNameType[]>(),
                    It.IsAny <TermNameType[]>()
                    )
                )
            .Returns(Task.FromResult(new Suggestion[] { }));

            Suggestion[] result = await controller.GetSuggestions(queryText, matchType, invalidSize);

            // Verify that the service layer is called:
            //  a) with the expected values.
            //  b) exactly once.
            querySvc.Verify(
                svc => svc.GetSuggestions(queryText, matchType, expecedSizeRequest, expectedResourceTypes, expectedIncludedTermTypes, expectedExclusionList),
                Times.Once
                );

            Assert.Empty(result);
        }
コード例 #9
0
        public async void Verify_Default_Values_Passed_to_Service()
        {
            const string       dictionary = "Cancer.gov";
            const AudienceType audience   = AudienceType.Patient;
            const string       language   = "en";
            const string       queryText  = "chicken";

            const MatchType expectedMatchType  = MatchType.Begins;
            const int       expecedSizeRequest = 20;

            Mock <IAutosuggestQueryService> querySvc   = new Mock <IAutosuggestQueryService>();
            AutosuggestController           controller = new AutosuggestController(querySvc.Object);

            // Set up the mock query service to return an empty array.
            querySvc.Setup(
                autoSuggestQSvc => autoSuggestQSvc.GetSuggestions(
                    It.IsAny <string>(),
                    It.IsAny <AudienceType>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <MatchType>(),
                    It.IsAny <int>()
                    )
                )
            .Returns(Task.FromResult(new Suggestion[] { }));

            Suggestion[] result = await controller.GetSuggestions(dictionary, audience, language, queryText);

            // Verify that the service layer is called:
            //  a) with the expected values.
            //  b) exactly once.
            querySvc.Verify(
                svc => svc.GetSuggestions(dictionary, audience, language, queryText, expectedMatchType, expecedSizeRequest),
                Times.Once
                );

            Assert.Empty(result);
        }