async public void SendJSON(NotificationData data) { httpWebRequest.Method = "POST"; httpWebRequest.ContentType = "application/json"; using (StreamWriter writer = new StreamWriter(await httpWebRequest.GetRequestStreamAsync())) { string jsonString = data.FormatJSONtoString(); writer.Write(jsonString); writer.Flush(); } WebResponse httpWebResponse = await httpWebRequest.GetResponseAsync(); }
async public Task<bool> SendJSON(NotificationData data) { httpWebRequest.Method = "POST"; httpWebRequest.ContentType = "application/json"; try { Task<Stream> task = httpWebRequest.GetRequestStreamAsync(); Stream stream = task.Result; using (StreamWriter writer = new StreamWriter(stream)) { string jsonString = data.FormatJSONtoString(); writer.Write(jsonString); writer.Flush(); } WebResponse httpWebResponse = await httpWebRequest.GetResponseAsync(); return true; } catch { return false; } }
public void TestMethod() { NotificationData data = new NotificationData(new Person("Zbigniew", "Boniek"), NotificationLevel.High, new GpsLocationAndroid(50.02341678941, 20.5673452123)); TestContext.WriteLine(data.FormatJSONtoString()); Assert.Pass("Your first passing test"); }