public static async Task testStuff() { HttpClientWrapper httpClient = new HttpClientWrapper(new HttpClient()); KegbotHttpRESTClient c = new KegbotHttpRESTClient("http://192.168.1.101:30080/api/", "5b94a95f58e4e371c8ee4c466740e2cc", httpClient); try { User adminUser = await c.GetUser("admin"); List<Drink> adminDrinks = await c.GetUserDrinks("admin"); //List<Drink> allDrinks = await c.GetDrinks(); List<Keg> allKegs = await c.GetKegs(); foreach(Keg k in allKegs) { Keg k1 = await c.GetKeg(k.Id); List<Drink> k1Drinks = await c.GetKegDrinks(k.Id); List<Session> k1Sessions = await c.GetKegSessions(k.Id); } List<KegTap> taps = await c.GetTaps(); foreach(KegTap t in taps) { KegTap k = await c.GetTap(t.MeterName); RecordedDrink rd = await c.RecordDrink(t.MeterName, 0, 568.26, "admin", null, null, null, "test"); Drink d = await c.GetDrink(rd.Id); //bool success = await c.CancelDrink(d.Id, false); } } catch (KegbotAPIException e) { } }
public async Task TestGetDrinkErrorResponse() { // Arrange string testURL = "http://test.org:8080/api/"; string getURL = "drinks/42"; string testAPIKey = "test12345"; int drinkId = 42; HttpResponseMessage responseMessage = new HttpResponseMessage(HttpStatusCode.InternalServerError); ErrorResponse payload = new ErrorResponse(); payload.MetaData = new Meta() { Result = "error" }; payload.Error = new Error() { Code = "ServerError", Message = "Something bad happened!" }; string content = JsonConvert.SerializeObject(payload); Mock<IHttpClient> httpClient = SetupClient(testURL, testAPIKey); responseMessage.Content = new StringContent(content, System.Text.Encoding.UTF8, "application/json"); httpClient.Setup(c => c.GetAsync(It.Is<string>(s => s == getURL))).Returns(Task.FromResult(responseMessage)).Verifiable(); KegbotHttpRESTClient client = new KegbotHttpRESTClient(testURL, testAPIKey, httpClient.Object); // Act try { Drink d = await client.GetDrink(drinkId); } catch (KegbotAPIException e) { // Assert Assert.IsNotNull(e.Error); Assert.AreEqual(e.Error.Code.ToString(), payload.Error.Code); Assert.AreEqual(e.Error.Message.ToString(), payload.Error.Message); } httpClient.VerifyAll(); }
public async Task TestGetDrinkSuccess() { // Arrange string testURL = "http://test.org:8080/api/"; string getURL = "drinks/42"; string testAPIKey = "test12345"; int drinkId = 42; HttpResponseMessage responseMessage = new HttpResponseMessage(HttpStatusCode.OK); DrinkPayload payload = new DrinkPayload(); payload.MetaData = new Meta() { Result = "ok" }; payload.Drink = new Drink(); string content = JsonConvert.SerializeObject(payload); responseMessage.Content = new StringContent(content, System.Text.Encoding.UTF8, "application/json"); Mock<IHttpClient> httpClient = SetupClient(testURL, testAPIKey); httpClient.Setup(c => c.GetAsync(It.Is<string>(s => s == getURL))).Returns(Task.FromResult(responseMessage)).Verifiable(); KegbotHttpRESTClient client = new KegbotHttpRESTClient(testURL, testAPIKey, httpClient.Object); // Act Drink d = await client.GetDrink(drinkId); // Assert Assert.AreEqual(payload.Drink, d); httpClient.VerifyAll(); }