コード例 #1
0
        /// <summary>
        /// Loads a SynonymTestData object based on a JSON file.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>SynonymTestData.</returns>
        public static SynonymTestData LoadTestData(string path)
        {
            string content = File.ReadAllText(
                TestingTools.GetPathToTestFile("SynonymTestData/" + path)
                );

            return(JsonConvert.DeserializeObject <SynonymTestData>(content));
        }
コード例 #2
0
        public async void GetByNameTerms()
        {
            Mock <ITermsQueryService> termsQueryService = new Mock <ITermsQueryService>();
            TermsController           controller        = new TermsController(NullLogger <TermsController> .Instance, termsQueryService.Object);

            GlossaryTerm glossaryTerm = 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[] { }
            };

            termsQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.IsAny <string>(),
                    It.IsAny <AudienceType>(),
                    It.IsAny <string>(),
                    It.IsAny <string>()
                    )
                )
            .Returns(Task.FromResult(glossaryTerm));

            GlossaryTerm term = await controller.GetByName("Cancer.gov", AudienceType.Patient, "en", "s-phase-fraction");

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

            // Verify that the service layer is called:
            //  a) with the expected values.
            //  b) exactly once.
            termsQueryService.Verify(
                svc => svc.GetByName("cancer.gov", AudienceType.Patient, "en", "s-phase-fraction"),
                Times.Once
                );

            Assert.Equal(glossaryTerm, term, new GlossaryTermComparer());
            Assert.Equal(expected, actual, new JTokenEqualityComparer());
        }
コード例 #3
0
        public async void GetByName_WithFallback_TermsPatient_NotTitleCase()
        {
            Mock <ITermsQueryService> termQueryService = new Mock <ITermsQueryService>();
            GlossaryTerm glossaryTerm = 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[] { }
            };

            // "cancer.gov" (not the requested "Cancer.gov") and Patient would be the only call to the terms query service, returning the term.
            termQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.Is <String>(dictionary => dictionary == "cancer.gov"),
                    It.Is <AudienceType>(audience => audience == AudienceType.Patient),
                    It.Is <string>(language => language == "en"),
                    It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction")
                    )
                )
            .Returns(Task.FromResult(glossaryTerm));

            TermsController controller = new TermsController(NullLogger <TermsController> .Instance, termQueryService.Object);
            GlossaryTerm    gsTerm     = await controller.GetByName("Cancer.gov", AudienceType.Patient, "en", "s-phase-fraction", true);

            // Verify that the expected and actual Term are the same.
            JObject actual   = JObject.Parse(JsonConvert.SerializeObject(gsTerm));
            JObject expected = JObject.Parse(File.ReadAllText(TestingTools.GetPathToTestFile("TermsControllerData/TestData_GetWithFallback_TermsPatient.json")));

            Assert.Equal(expected, actual, new JTokenEqualityComparer());

            // Verify that the service layer is called correctly with the lowercased-dictionary fallback combination:
            termQueryService.Verify(
                svc => svc.GetByName("cancer.gov", AudienceType.Patient, "en", "s-phase-fraction"),
                Times.Once
                );
        }
コード例 #4
0
        public async void GetById()
        {
            Mock <ITermQueryService> termQueryService = new Mock <ITermQueryService>();

            string[]      requestedFields = { "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"
                    }
                }
            };

            termQueryService.Setup(
                termQSvc => termQSvc.GetById(
                    It.IsAny <String>(),
                    It.IsAny <AudienceType>(),
                    It.IsAny <string>(),
                    It.IsAny <long>(),
                    It.IsAny <string[]>()
                    )
                )
            .Returns(Task.FromResult(glossaryTerm));

            TermController controller = new TermController(termQueryService.Object);
            GlossaryTerm   gsTerm     = await controller.GetById("Dictionary", AudienceType.Patient, "EN", 1234L, requestedFields);

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

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

            Assert.Equal(expectedJsonValue, actualJsonValue);
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        public async void GetByName_WithFallback_TermsPatient()
        {
            Mock <ITermsQueryService> termQueryService = new Mock <ITermsQueryService>();
            GlossaryTerm glossaryTerm = 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[] { }
            };

            int callOrder = 0;

            // NotSet and Patient would be the first call to the terms query service, returning nothing.
            termQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.Is <String>(dictionary => dictionary == "notset"),
                    It.Is <AudienceType>(audience => audience == AudienceType.Patient),
                    It.Is <string>(language => language == "en"),
                    It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction")
                    )
                )
            .Callback(() => Assert.Equal(1, callOrder++))
            .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'notset', audience 'Patient', language 'en', pretty URL name 's-phase-fraction'."));

            // NotSet and HealthProfessional would be the second call to the terms query service, returning nothing.
            termQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.Is <String>(dictionary => dictionary == "notset"),
                    It.Is <AudienceType>(audience => audience == AudienceType.HealthProfessional),
                    It.Is <string>(language => language == "en"),
                    It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction")
                    )
                )
            .Callback(() => Assert.Equal(2, callOrder++))
            .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'notset', audience 'HealthProfessional', language 'en', pretty URL name 's-phase-fraction'."));

            // Genetics and Patient would be the third call to the terms query service, returning nothing.
            termQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.Is <String>(dictionary => dictionary == "genetics"),
                    It.Is <AudienceType>(audience => audience == AudienceType.Patient),
                    It.Is <string>(language => language == "en"),
                    It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction")
                    )
                )
            .Callback(() => Assert.Equal(3, callOrder++))
            .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'genetics', audience 'Patient', language 'en', pretty URL name 's-phase-fraction'."));

            // Genetics and HealthProfessional would be the fourth call to the terms query service, returning nothing.
            termQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.Is <String>(dictionary => dictionary == "genetics"),
                    It.Is <AudienceType>(audience => audience == AudienceType.HealthProfessional),
                    It.Is <string>(language => language == "en"),
                    It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction")
                    )
                )
            .Callback(() => Assert.Equal(4, callOrder++))
            .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'genetics', audience 'HealthProfessional', language 'en', pretty URL name 's-phase-fraction'."));

            // Cancer.gov and Patient would be the last call to the terms query service, returning the term.
            termQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.Is <String>(dictionary => dictionary == "cancer.gov"),
                    It.Is <AudienceType>(audience => audience == AudienceType.Patient),
                    It.Is <string>(language => language == "en"),
                    It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction")
                    )
                )
            .Returns(Task.FromResult(glossaryTerm));

            TermsController controller = new TermsController(NullLogger <TermsController> .Instance, termQueryService.Object);
            GlossaryTerm    gsTerm     = await controller.GetByName("NotSet", AudienceType.Patient, "en", "s-phase-fraction", true);

            // Verify that the expected and actual Term are the same.
            JObject actual   = JObject.Parse(JsonConvert.SerializeObject(gsTerm));
            JObject expected = JObject.Parse(File.ReadAllText(TestingTools.GetPathToTestFile("TermsControllerData/TestData_GetWithFallback_TermsPatient.json")));

            Assert.Equal(expected, actual, new JTokenEqualityComparer());

            // Verify that the service layer is called correctly with the fallback logic:
            // 1) Empty dictionary, Patient
            termQueryService.Verify(
                svc => svc.GetByName("notset", AudienceType.Patient, "en", "s-phase-fraction"),
                Times.Once
                );
            // 2) Empty dictionary, HealthProfessional
            termQueryService.Verify(
                svc => svc.GetByName("notset", AudienceType.HealthProfessional, "en", "s-phase-fraction"),
                Times.Once
                );
            // 3) Genetics, Patient
            termQueryService.Verify(
                svc => svc.GetByName("genetics", AudienceType.Patient, "en", "s-phase-fraction"),
                Times.Once
                );
            // 4) Genetics, HealthProfessional
            termQueryService.Verify(
                svc => svc.GetByName("genetics", AudienceType.HealthProfessional, "en", "s-phase-fraction"),
                Times.Once
                );
            // 5) Cancer.gov, Patient
            termQueryService.Verify(
                svc => svc.GetByName("cancer.gov", AudienceType.Patient, "en", "s-phase-fraction"),
                Times.Once
                );
        }
コード例 #7
0
        public async void GetByName_WithFallback_GeneticsHP()
        {
            Mock <ITermsQueryService> termQueryService = new Mock <ITermsQueryService>();
            GlossaryTerm glossaryTerm = new GlossaryTerm
            {
                TermId        = 556486,
                Language      = "en",
                Dictionary    = "Genetics",
                Audience      = AudienceType.HealthProfessional,
                TermName      = "deleterious mutation",
                FirstLetter   = "d",
                PrettyUrlName = "deleterious-mutation",
                Pronunciation = new Pronunciation()
                {
                    Key   = "(DEH-leh-TEER-ee-us myoo-TAY-shun)",
                    Audio = "https://nci-media-dev.cancer.gov/pdq/media/audio/736913.mp3"
                },
                Definition = new Definition()
                {
                    Html = "A genetic alteration that increases an individual’s susceptibility or predisposition to a certain disease or disorder. When such a variant (or mutation) is inherited, development of symptoms is more likely, but not certain.  Also called disease-causing mutation, pathogenic variant, predisposing mutation,  and susceptibility gene mutation.",
                    Text = "A genetic alteration that increases an individual’s susceptibility or predisposition to a certain disease or disorder. When such a variant (or mutation) is inherited, development of symptoms is more likely, but not certain.  Also called disease-causing mutation, pathogenic variant, predisposing mutation,  and susceptibility gene mutation."
                },
                RelatedResources = new IRelatedResource[] {},
                Media            = new IMedia[] {}
            };

            int callOrder = 0;

            // Cancer.gov and HealthProfessional would be the first call to the terms query service, returning nothing.
            termQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.Is <String>(dictionary => dictionary == "cancer.gov"),
                    It.Is <AudienceType>(audience => audience == AudienceType.HealthProfessional),
                    It.Is <string>(language => language == "en"),
                    It.Is <string>(prettyUrlName => prettyUrlName == "deleterious-mutation")
                    )
                )
            .Callback(() => Assert.Equal(1, callOrder++))
            .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'cancer.gov', audience 'HealthProfessional', language 'en', pretty URL name 'deleterious-mutation'."));

            // Cancer.gov and Patient would be the second call to the terms query service, returning nothing.
            termQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.Is <String>(dictionary => dictionary == "cancer.gov"),
                    It.Is <AudienceType>(audience => audience == AudienceType.Patient),
                    It.Is <string>(language => language == "en"),
                    It.Is <string>(prettyUrlName => prettyUrlName == "deleterious-mutation")
                    )
                )
            .Callback(() => Assert.Equal(2, callOrder++))
            .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'cancer.gov', audience 'Patient', language 'en', pretty URL name 'deleterious-mutation'."));

            // NotSet and HealthProfessional would be the third call to the terms query service, returning nothing.
            termQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.Is <String>(dictionary => dictionary == "notset"),
                    It.Is <AudienceType>(audience => audience == AudienceType.HealthProfessional),
                    It.Is <string>(language => language == "en"),
                    It.Is <string>(prettyUrlName => prettyUrlName == "deleterious-mutation")
                    )
                )
            .Callback(() => Assert.Equal(3, callOrder++))
            .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'notset', audience 'HealthProfessional', language 'en', pretty URL name 'deleterious-mutation'."));

            // NotSet and Patient would be the fourth call to the terms query service, returning nothing.
            termQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.Is <String>(dictionary => dictionary == "notset"),
                    It.Is <AudienceType>(audience => audience == AudienceType.Patient),
                    It.Is <string>(language => language == "en"),
                    It.Is <string>(prettyUrlName => prettyUrlName == "deleterious-mutation")
                    )
                )
            .Callback(() => Assert.Equal(4, callOrder++))
            .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'notset', audience 'Patient', language 'en', pretty URL name 'deleterious-mutation'."));

            // Genetics and HealthProfessional would be the last call to the terms query service, returning the term.
            termQueryService.Setup(
                termQSvc => termQSvc.GetByName(
                    It.Is <String>(dictionary => dictionary == "genetics"),
                    It.Is <AudienceType>(audience => audience == AudienceType.HealthProfessional),
                    It.Is <string>(language => language == "en"),
                    It.Is <string>(prettyUrlName => prettyUrlName == "deleterious-mutation")
                    )
                )
            .Returns(Task.FromResult(glossaryTerm));

            TermsController controller = new TermsController(NullLogger <TermsController> .Instance, termQueryService.Object);
            GlossaryTerm    gsTerm     = await controller.GetByName("Cancer.gov", AudienceType.HealthProfessional, "en", "deleterious-mutation", true);

            // Verify that the expected and actual Term are the same.
            JObject actual   = JObject.Parse(JsonConvert.SerializeObject(gsTerm));
            JObject expected = JObject.Parse(File.ReadAllText(TestingTools.GetPathToTestFile("TermsControllerData/TestData_GetWithFallback_GeneticsHP.json")));

            Assert.Equal(expected, actual, new JTokenEqualityComparer());

            // Verify that the service layer is called correctly with the fallback logic:
            // 1) Cancer.gov, HealthProfessional
            termQueryService.Verify(
                svc => svc.GetByName("cancer.gov", AudienceType.HealthProfessional, "en", "deleterious-mutation"),
                Times.Once
                );
            // 2) Cancer.gov, Patient
            termQueryService.Verify(
                svc => svc.GetByName("cancer.gov", AudienceType.Patient, "en", "deleterious-mutation"),
                Times.Once
                );
            // 3) Empty dictionary, HealthProfessional
            termQueryService.Verify(
                svc => svc.GetByName("notset", AudienceType.HealthProfessional, "en", "deleterious-mutation"),
                Times.Once
                );
            // 4) Empty dictionary, Patient
            termQueryService.Verify(
                svc => svc.GetByName("notset", AudienceType.Patient, "en", "deleterious-mutation"),
                Times.Once
                );
            // 5) Genetics, HealthProfessional
            termQueryService.Verify(
                svc => svc.GetByName("genetics", AudienceType.HealthProfessional, "en", "deleterious-mutation"),
                Times.Once
                );
        }