Ejemplo n.º 1
0
        public async void GetBestBetForDisplay_DataLoading(BaseTermQueryTestData data)
        {
            IElasticClient client = GetElasticClientWithData(data);

            // Setup the mocked Options
            IOptions <GlossaryAPIOptions> gTermClientOptions = GetMockOptions();

            ESTermQueryService termClient = new ESTermQueryService(client, gTermClientOptions, new NullLogger <ESTermQueryService>());

            GlossaryTerm glossaryTerm = await termClient.GetById("cancer.gov", AudienceType.Patient, "en", 43966L, new string[] {});

            Assert.Equal(data.ExpectedData, glossaryTerm, new GlossaryTermComparer());
        }
Ejemplo n.º 2
0
        public async void GetByIdForGlossaryTerm(BaseTermQueryTestData data)
        {
            Uri esURI = null;

            ElasticsearchInterceptingConnection conn = new ElasticsearchInterceptingConnection();

            conn.RegisterRequestHandlerForType <Nest.GetResponse <GlossaryTerm> >((req, res) =>
            {
                //Get the file name for this round
                res.Stream = TestingTools.GetTestFileAsStream("ESTermQueryData/" + data.ESTermID + ".json");

                res.StatusCode = 200;

                esURI = req.Uri;
            });

            //While this has a URI, it 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 <GlossaryAPIOptions> gTermClientOptions = GetMockOptions();

            ESTermQueryService termClient = new ESTermQueryService(client, gTermClientOptions, new NullLogger <ESTermQueryService>());

            // We don't actually care that this returns anything - only that the intercepting connection
            // sets up the request URI correctly.
            GlossaryTerm actDisplay = await termClient.GetById(
                data.DictionaryName,
                data.Audience,
                data.Language,
                data.TermID,
                new string[] {}
                );


            Assert.Equal(
                esURI.Segments,
                new string[] { "/", "glossaryv1/", "terms/", data.ESTermID },
                new ArrayComparer()
                );
        }
Ejemplo n.º 3
0
        public async void GetByIdForGlossaryTerm_TestInvalidResponse()
        {
            ElasticsearchInterceptingConnection conn = new ElasticsearchInterceptingConnection();

            conn.RegisterRequestHandlerForType <Nest.GetResponse <GlossaryTerm> >((req, res) =>
            {
            });

            //While this has a URI, it 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 <GlossaryAPIOptions> gTermClientOptions = GetMockOptions();

            ESTermQueryService termClient = new ESTermQueryService(client, gTermClientOptions, new NullLogger <ESTermQueryService>());
            APIErrorException  ex         = await Assert.ThrowsAsync <APIErrorException>(() => termClient.GetById("cancer.gov", AudienceType.Patient, "en", 43966L, new string[] {}));

            Assert.Equal(500, ex.HttpStatusCode);
        }