public async Task <bool> SendData <T>(IEnumerable <T> data) { var message = new CaliperMessage <T> { SensorId = _sensorId, SendTime = SystemClock.Instance.GetCurrentInstant(), Data = data }; var jsonString = JsonConvert.SerializeObject(message, _serializerSettings); var jsonObject = JsonSerializeUtils.clean(JObject.Parse(jsonString)); var content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json"); using (var client = new HttpClient()) { client.BaseAddress = _options.Host; try { HttpResponseMessage response = await client.PostAsync("", content); response.EnsureSuccessStatusCode(); } catch (HttpRequestException ex) { var msg = String.Format("Failed to send data: {0}", ex.Message); Trace.WriteLine(msg); return(false); } } return(true); }
public static void AssertSameObjectJson(object obj, string eventReferenceFile, bool clean) { var eventJObject = JsonSerializeUtils.toJobject(obj); if (clean) { eventJObject = JsonSerializeUtils.clean(eventJObject); } var refJsonString = TestUtils.LoadReferenceJsonFixture(eventReferenceFile); var refJObject = JObject.Parse(refJsonString); bool equals = JToken.DeepEquals(refJObject, eventJObject); if (!equals) { var jdp = new JsonDiffPatchDotNet.JsonDiffPatch(); JToken patch = jdp.Diff(eventJObject, refJObject); Console.WriteLine("diff:"); Console.WriteLine(patch); Console.WriteLine("fixture:"); Console.WriteLine(refJObject); Console.WriteLine("created:"); Console.WriteLine(eventJObject); } Assert.True(equals); }