Exemplo n.º 1
0
        public async void GetById_ErrorMessage_Id()
        {
            Mock <ITermQueryService> termQueryService = new Mock <ITermQueryService>();
            TermController           controller       = new TermController(termQueryService.Object);
            var exception = await Assert.ThrowsAsync <APIErrorException>(() => controller.GetById("Dictionary", AudienceType.Patient, "EN", 0L, new string[] {}));

            Assert.Equal("You must supply a valid dictionary, audience, language and id", exception.Message);
        }
Exemplo n.º 2
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);
        }