public async void GetByName_ValidName()
        {
            const string theName = "iodinated-contrast-agent";

            DrugTerm testTerm = new DrugTerm()
            {
                Aliases = new TermAlias[] {
                    new TermAlias()
                    {
                        Type = TermNameType.Synonym,
                        Name = "contrast dye, iodinated"
                    },
                    new TermAlias()
                    {
                        Type = TermNameType.LexicalVariant,
                        Name = "Iodinated Contrast Agent"
                    }
                },
                Definition = new Definition()
                {
                    Html = "A contrast agent containing an iodine-based dye used in many diagnostic imaging examinations, including computed tomography, angiography, and myelography. Check for <a ref=\"https://www.cancer.gov/about-cancer/treatment/clinical-trials/intervention/C28500\">active clinical trials</a> using this agent. (<a ref=\"https://ncit.nci.nih.gov/ncitbrowser/ConceptReport.jsp?dictionary=NCI%20Thesaurus&code=C28500\">NCI Thesaurus</a>)",
                    Text = "A contrast agent containing an iodine-based dye used in many diagnostic imaging examinations, including computed tomography, angiography, and myelography. Check for active clinical trials using this agent. (NCI Thesaurus)"
                },
                DrugInfoSummaryLink = null,
                FirstLetter         = 'i',
                Name           = "iodinated contrast dye",
                NCIConceptId   = "C28500",
                NCIConceptName = "Iodinated Contrast Agent",
                PrettyUrlName  = "iodinated-contrast-agent",
                TermId         = 37780,
                TermNameType   = TermNameType.PreferredName,
                Type           = DrugResourceType.DrugTerm
            };

            Mock <IDrugsQueryService> querySvc = new Mock <IDrugsQueryService>();

            querySvc.Setup(
                svc => svc.GetByName(
                    It.IsAny <string>()
                    )
                )
            .Returns(Task.FromResult(testTerm));

            // Call the controller, we don't care about the actual return value.
            DrugsController controller = new DrugsController(NullLogger <DrugsController> .Instance, querySvc.Object);
            DrugTerm        actual     = await controller.GetByName(theName);

            Assert.Equal(testTerm, actual);

            // Verify that the query layer is called:
            //  a) with the ID value.
            //  b) exactly once.
            querySvc.Verify(
                svc => svc.GetByName(theName),
                Times.Once,
                $"ITermsQueryService::GetByName() should be called once, with id = '{theName}"
                );
        }
Пример #2
0
        public async Task <DrugTerm> GetById(long id)
        {
            if (id <= 0)
            {
                throw new APIErrorException(400, $"Not a valid ID '{id}'.");
            }

            DrugTerm res = await _termsQueryService.GetById(id);

            return(res);
        }
        public async void GetByName_TestRequestSetup(BaseGetByNameSvcRequestScenario data)
        {
            Uri esURI = null;
            string esContentType = String.Empty;
            HttpMethod esMethod = HttpMethod.DELETE; // Basically, something other than the expected value.

            JObject requestBody = null;

            ElasticsearchInterceptingConnection conn = new ElasticsearchInterceptingConnection();
            conn.RegisterRequestHandlerForType<Nest.SearchResponse<DrugTerm>>((req, res) =>
            {
                // We don't really care about the response for this test.
                res.Stream = MockSingleTermResponse;
                res.StatusCode = 200;

                esURI = req.Uri;
                esContentType = req.ContentType;
                esMethod = req.Method;
                requestBody = conn.GetRequestPost(req);
            });

            // The URI does not matter, an InMemoryConnection never requests from the server.
            var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));

            var connectionSettings = new ConnectionSettings(pool, conn);
            IElasticClient client = new ElasticClient(connectionSettings);

            // Setup the mocked Options
            IOptions<DrugDictionaryAPIOptions> clientOptions = GetMockOptions();

            ESDrugsQueryService query = new ESDrugsQueryService(client, clientOptions, new NullLogger<ESDrugsQueryService>());

            // We don't really care that this returns anything (for this test), only that the intercepting connection
            // sets up the request correctly.
            DrugTerm result = await query.GetByName(data.PrettyUrlName);

            Assert.Equal("/drugv1/terms/_search", esURI.AbsolutePath);
            Assert.Equal("application/json", esContentType);
            Assert.Equal(HttpMethod.POST, esMethod);
            Assert.Equal(data.ExpectedData, requestBody, new JTokenEqualityComparer());
        }