public static async Task ClassInitialize(TestContext tc) { UserController.Instance.isTestMode = true; ServerConfig.Instance.serverAddress = "http://csse-s302g3.canterbury.ac.nz:80/testing/api/v1"; loginAPI = new LoginAPI(); drugAPI = new DrugInteractionAPI(); await UnitTestUtils.resetResample(); }
/* * Event handler to handle when a user selects medications and * wishes to compare them, sending a call off to the interactions API. */ async void Handle_ComparePressed(object sender, EventArgs e) { Console.WriteLine("Compare pressed!"); DrugInteractionAPI drugInteractionAPI = new DrugInteractionAPI(); User loggedInUser = UserController.Instance.LoggedInUser; DrugInteractionResult retrievedDrugInteractions = await drugInteractionAPI.RetrieveDrugInteractions(selectedItem1.Text, selectedItem2.Text); if (!retrievedDrugInteractions.gotInteractions) { switch (retrievedDrugInteractions.resultStatusCode) { case HttpStatusCode.Accepted: await DisplayAlert("Failed to get Interactions", "Interactions yet to be researched", "OK"); return; case HttpStatusCode.NotFound: await DisplayAlert("Failed to get Interactions", "One or both of the drugs are invalid", "OK"); return; case HttpStatusCode.BadGateway: await DisplayAlert("Failed to get Interactions", "The Drug Interactions API is currently down", "OK"); return; case HttpStatusCode.BadRequest: await DisplayAlert("Failed to get Interactions", "Please ensure you are connected to the internet", "OK"); return; } } string interactionsBody = String.Format("{0}y/o {1}\n\n{2}\n\n{3}\n\n{4}", loggedInUser.Age, loggedInUser.gender, string.Join("\r\n", retrievedDrugInteractions.genderInteractions), string.Join("\r\n", retrievedDrugInteractions.ageInteractions), string.Join("\r\n", retrievedDrugInteractions.durationInteractions)); await DisplayAlert(String.Format("Interactions between {0} and {1}", selectedItem1.Text, selectedItem2.Text), interactionsBody, "OK"); }