Esempio n. 1
0
        public void TestGet()
        {
            string baseUrl = "https://example.org/v1/";
            string trialID = "NCT02194738";

            string trialFilePath = TestFileTools.GetPathToTestFile(typeof(ClinicalTrialsAPIClientTests), Path.Combine(new string[] { "TrialExamples", trialID + ".json" }));

            HttpClient mockedClient = HttpClientMockHelper.GetClientMockForURLWithFileResponse(String.Format("{0}clinical-trial/{1}", baseUrl, trialID), trialFilePath);

            mockedClient.BaseAddress = new Uri(baseUrl);

            ClinicalTrialsAPIClient client = new ClinicalTrialsAPIClient(mockedClient);


            ClinicalTrial trial = client.Get(trialID);

            Assert.Equal(trialID, trial.NCTID);
        }
Esempio n. 2
0
 /// <summary>
 /// Checks whether the given trial ID exists in the API.
 /// </summary>
 /// <param name="idString">NCT ID</param>
 /// <returns>True if trial is found in API.</returns>
 private bool IsValidTrial(string idString)
 {
     // If the ID is a valid NCTID, go to web service and see if trial exists
     try
     {
         ClinicalTrialsAPIClient client = APIClientHelper.GetV1ClientInstance();
         ClinicalTrial           trial  = client.Get(idString);
         if (trial != null)
         {
             return(true);
         }
     }
     catch (ArgumentNullException nx)
     {
         log.DebugFormat("Error retrieving trial - value cannot be null. idString = " + idString, nx);
         return(false);
     }
     catch (Exception ex)
     {
         log.Error("Error retrieving trial object from API", ex);
         return(false);
     }
     return(false);
 }