public async void Search_ErrorMessage_AudienceType()
        {
            Mock <ITermsQueryService> termsQueryService = new Mock <ITermsQueryService>();
            TermsController           controller        = new TermsController(NullLogger <TermsController> .Instance, termsQueryService.Object);
            APIErrorException         exception         = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.Search("Cancer.gov", (AudienceType)(-18), "en", "chicken", MatchType.Begins, 10, 0)
                );

            Assert.Equal("You must supply a valid dictionary, audience and language.", exception.Message);
        }
        public async void Search_ErrorMessage_InvalidLanguage()
        {
            Mock <ITermsQueryService> termQueryService = new Mock <ITermsQueryService>();
            TermsController           controller       = new TermsController(NullLogger <TermsController> .Instance, termQueryService.Object);
            var exception = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.Search("Cancer.gov", AudienceType.Patient, "chicken", "chicken", MatchType.Begins, 10, 0)
                );

            Assert.Equal("Unsupported Language. Valid values are 'en' and 'es'.", exception.Message);
        }
示例#3
0
        public async void SearchForTerms_ErrorMessage_AudienceType()
        {
            Mock <ITermsQueryService> termsQueryService = new Mock <ITermsQueryService>();
            TermsController           controller        = new TermsController(termsQueryService.Object);
            APIErrorException         exception         = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.Search("Dictionary", (AudienceType)(-18), "EN", "Query", "contains", 0, 1, new string[] {})
                );

            Assert.Equal("You must supply a valid dictionary, audience and language.", exception.Message);
        }
示例#4
0
        public async void SearchForTerms_ErrorMessage_MatchType()
        {
            Mock <ITermsQueryService> termsQueryService = new Mock <ITermsQueryService>();
            TermsController           controller        = new TermsController(termsQueryService.Object);
            APIErrorException         exception         = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.Search("Dictionary", AudienceType.Patient, "EN", "Query", "doesnotcontain", 1, 1, new string[] {})
                );

            Assert.Equal("'matchType' can only be 'begins' or 'contains'", exception.Message);
        }
        public async void Search_InvalidMatchType()
        {
            // Create a mock query that always returns the same result.
            Mock <ITermsQueryService> querySvc = getDumbSearchSvcMock();

            // Call the controller, we don't care about the actual return value.
            TermsController controller = new TermsController(NullLogger <TermsController> .Instance, querySvc.Object);
            var             exception  = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.Search("Cancer.gov", AudienceType.Patient, "en", "chicken", (MatchType)5, -1, 0)
                );

            Assert.Equal("Invalid value for the 'matchType' parameter.", exception.Message);
        }
        public async void Search_RequiredParametersOnly()
        {
            // Create a mock query that always returns the same result.
            Mock <ITermsQueryService> querySvc = getDumbSearchSvcMock();

            // Call the controller, we don't care about the actual return value.
            TermsController controller = new TermsController(NullLogger <TermsController> .Instance, querySvc.Object);
            await controller.Search("Cancer.gov", AudienceType.Patient, "en", "chicken");

            // Verify that the query layer is called:
            //  a) with the expected updated values for size, from, and requestedFields.
            //  b) exactly once.
            querySvc.Verify(
                svc => svc.Search("Cancer.gov", AudienceType.Patient, "en", "chicken", MatchType.Begins, 100, 0, false),
                Times.Once,
                "ITermsQueryService::Search() should be called once, with the updated value for size"
                );
        }
        public async void Search_HandlesResults()
        {
            GlossaryTermResults glossaryTermResults = new GlossaryTermResults()
            {
                Results = new GlossaryTerm[] {
                    new GlossaryTerm()
                    {
                        TermId        = 46716,
                        Language      = "en",
                        Dictionary    = "Cancer.gov",
                        Audience      = AudienceType.Patient,
                        TermName      = "S-1",
                        FirstLetter   = "s",
                        PrettyUrlName = "s-1",
                        Definition    = new Definition()
                        {
                            Text = "A drug that is being studied for its ability to enhance the effectiveness of fluorouracil and prevent gastrointestinal side effects caused by fluorouracil. It belongs to the family of drugs called antimetabolites.",
                            Html = "A drug that is being studied for its ability to enhance the effectiveness of fluorouracil and prevent gastrointestinal side effects caused by fluorouracil. It belongs to the family of drugs called antimetabolites."
                        },
                        Pronunciation    = null,
                        Media            = new IMedia[] {},
                        RelatedResources = new IRelatedResource[] { }
                    },
                    new GlossaryTerm()
                    {
                        TermId        = 44771,
                        Language      = "en",
                        Dictionary    = "Cancer.gov",
                        Audience      = AudienceType.Patient,
                        TermName      = "S-phase fraction",
                        FirstLetter   = "s",
                        PrettyUrlName = "s-phase-fraction",
                        Definition    = new Definition()
                        {
                            Text = "A measure of the percentage of cells in a tumor that are in the phase of the cell cycle during which DNA is synthesized. The S-phase fraction may be used with the proliferative index to give a more complete understanding of how fast a tumor is growing.",
                            Html = "A measure of the percentage of cells in a tumor that are in the phase of the cell cycle during which DNA is synthesized. The S-phase fraction may be used with the proliferative index to give a more complete understanding of how fast a tumor is growing."
                        },
                        Pronunciation = new Pronunciation()
                        {
                            Key   = "(... fayz FRAK-shun)",
                            Audio = "https://nci-media-dev.cancer.gov/audio/pdq/705947.mp3"
                        },
                        Media            = new IMedia[] {},
                        RelatedResources = new IRelatedResource[] { }
                    },
                    new GlossaryTerm()
                    {
                        TermId        = 572148,
                        Language      = "en",
                        Dictionary    = "Cancer.gov",
                        Audience      = AudienceType.Patient,
                        TermName      = "S100 calcium binding protein A8",
                        FirstLetter   = "s",
                        PrettyUrlName = "s100-calcium-binding-protein-a8",
                        Definition    = new Definition()
                        {
                            Text = "A protein that is made by many different types of cells and is involved in processes that take place both inside and outside of the cell. It is made in larger amounts in inflammatory diseases such as rheumatoid arthritis, and in some types of cancer. It is being studied as a biomarker for breast cancer. Also called calgranulin A.",
                            Html = "A protein that is made by many different types of cells and is involved in processes that take place both inside and outside of the cell. It is made in larger amounts in inflammatory diseases such as rheumatoid arthritis, and in some types of cancer. It is being studied as a biomarker for breast cancer. Also called calgranulin A."
                        },
                        Pronunciation = new Pronunciation()
                        {
                            Key   = "(… KAL-see-um … PROH-teen …)",
                            Audio = "https://nci-media-dev.cancer.gov/audio/pdq/720720.mp3"
                        },
                        Media            = new IMedia[] {},
                        RelatedResources = new IRelatedResource[] { }
                    },
                    new GlossaryTerm()
                    {
                        TermId        = 572151,
                        Language      = "en",
                        Dictionary    = "Cancer.gov",
                        Audience      = AudienceType.Patient,
                        TermName      = "S100 calcium binding protein A9",
                        FirstLetter   = "s",
                        PrettyUrlName = "s100-calcium-binding-protein-a9",
                        Definition    = new Definition()
                        {
                            Text = "A protein that is made by many different types of cells and is involved in processes that take place both inside and outside of the cell. It is made in larger amounts in inflammatory diseases such as rheumatoid arthritis, and in some types of cancer. It is being studied as a biomarker for breast cancer. Also called calgranulin B.",
                            Html = "A protein that is made by many different types of cells and is involved in processes that take place both inside and outside of the cell. It is made in larger amounts in inflammatory diseases such as rheumatoid arthritis, and in some types of cancer. It is being studied as a biomarker for breast cancer. Also called calgranulin B."
                        },
                        Pronunciation = new Pronunciation()
                        {
                            Key   = "(… KAL-see-um … PROH-teen …)",
                            Audio = "https://nci-media-dev.cancer.gov/audio/pdq/720722.mp3"
                        },
                        Media            = new IMedia[] {},
                        RelatedResources = new IRelatedResource[] { }
                    },
                    new GlossaryTerm()
                    {
                        TermId        = 651217,
                        Language      = "en",
                        Dictionary    = "Cancer.gov",
                        Audience      = AudienceType.Patient,
                        TermName      = "SAB",
                        FirstLetter   = "s",
                        PrettyUrlName = "sab",
                        Definition    = new Definition()
                        {
                            Text = "A temporary loss of feeling in the abdomen and/or the lower part of the body. Special drugs called anesthetics are injected into the fluid in the lower part of the spinal column to cause the loss of feeling. The patient stays awake during the procedure.  It is a type of regional anesthesia. Also called spinal anesthesia, spinal block,  and subarachnoid block.",
                            Html = "A temporary loss of feeling in the abdomen and/or the lower part of the body. Special drugs called anesthetics are injected into the fluid in the lower part of the spinal column to cause the loss of feeling. The patient stays awake during the procedure.  It is a type of regional anesthesia. Also called spinal anesthesia, spinal block,  and subarachnoid block."
                        },
                        Pronunciation    = null,
                        Media            = new IMedia[] {},
                        RelatedResources = new IRelatedResource[] { }
                    }
                },
                Meta = new ResultsMetadata()
                {
                    TotalResults = 854,
                    From         = 0
                },
                Links = null
            };

            Mock <ITermsQueryService> termsQueryService = getDumbSearchSvcMock(glossaryTermResults);
            TermsController           controller        = new TermsController(NullLogger <TermsController> .Instance, termsQueryService.Object);


            GlossaryTermResults termResults = await controller.Search("Cancer.gov", AudienceType.Patient, "en", "chicken", MatchType.Begins, 5, 0, true);

            JObject actual   = JObject.Parse(JsonConvert.SerializeObject(termResults));
            JObject expected = JObject.Parse(File.ReadAllText(TestingTools.GetPathToTestFile("TermsControllerData/TestData_Expand.json")));

            // Verify that the service layer is called:
            //  a) with the expected values.
            //  b) exactly once.
            termsQueryService.Verify(
                svc => svc.Search("Cancer.gov", AudienceType.Patient, "en", "chicken", MatchType.Begins, 5, 0, true),
                Times.Once
                );

            Assert.Equal(glossaryTermResults.Results, termResults.Results, new GlossaryTermComparer());
            Assert.Equal(glossaryTermResults.Meta.TotalResults, termResults.Meta.TotalResults);
            Assert.Equal(glossaryTermResults.Meta.From, termResults.Meta.From);
            Assert.Equal(expected, actual, new JTokenEqualityComparer());
        }
示例#8
0
        public async void ExpandTerms()
        {
            Mock <ITermsQueryService> termsQueryService = new Mock <ITermsQueryService>();
            TermsController           controller        = new TermsController(termsQueryService.Object);

            string[]      requestedFields = new string[] { "TermName", "Pronunciation", "Definition" };
            Pronunciation pronunciation   = new Pronunciation("Pronunciation Key", "pronunciation");
            Definition    definition      = new Definition("<html><h1>Definition</h1></html>", "Sample definition");
            GlossaryTerm  glossaryTerm    = new GlossaryTerm
            {
                TermId           = 1234L,
                Language         = "EN",
                Dictionary       = "Dictionary",
                Audience         = AudienceType.Patient,
                TermName         = "TermName",
                FirstLetter      = "t",
                PrettyUrlName    = "www.glossary-api.com",
                Pronunciation    = pronunciation,
                Definition       = definition,
                RelatedResources = new IRelatedResource[] {
                    new LinkResource()
                    {
                        Type = RelatedResourceType.External,
                        Text = "Link to Google",
                        Url  = new System.Uri("https://www.google.com")
                    },
                    new LinkResource()
                    {
                        Type = RelatedResourceType.DrugSummary,
                        Text = "Bevacizumab",
                        Url  = new System.Uri("https://www.cancer.gov/about-cancer/treatment/drugs/bevacizumab")
                    },
                    new LinkResource()
                    {
                        Type = RelatedResourceType.Summary,
                        Text = "Lung cancer treatment",
                        Url  = new System.Uri("https://www.cancer.gov/types/lung/patient/small-cell-lung-treatment-pdq")
                    },
                    new GlossaryResource()
                    {
                        Type          = RelatedResourceType.GlossaryTerm,
                        Text          = "stage II cutaneous T-cell lymphoma",
                        TermId        = 43966,
                        Audience      = AudienceType.Patient,
                        PrettyUrlName = "stage-ii-cutaneous-t-cell-lymphoma"
                    }
                }
            };
            List <GlossaryTerm> glossaryTermList = new List <GlossaryTerm>();

            glossaryTermList.Add(glossaryTerm);
            termsQueryService.Setup(
                termQSvc => termQSvc.Search(
                    It.IsAny <string>(),
                    It.IsAny <AudienceType>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <int>(),
                    It.IsAny <int>(),
                    It.IsAny <string[]>()
                    )
                )
            .Returns(Task.FromResult(glossaryTermList));

            GlossaryTerm[] gsTerm = await controller.Search("Dictionary", AudienceType.Patient, "EN", "Query", "contains", 1, 0, requestedFields);

            string actualJsonValue   = JsonConvert.SerializeObject(gsTerm);
            string expectedJsonValue = File.ReadAllText(TestingTools.GetPathToTestFile("TestData_SearchForTerms.json"));

            // Verify that the service layer is called:
            //  a) with the expected values.
            //  b) exactly once.
            termsQueryService.Verify(
                svc => svc.Search("Dictionary", AudienceType.Patient, "EN", "Query", "contains", 1, 0, new string[] { "TermName", "Pronunciation", "Definition" }),
                Times.Once
                );

            Assert.Equal(expectedJsonValue, actualJsonValue);
        }