public void GivenTemplateAndSingleMultiValueValidToken_WhenGetMeasurements_ThenSingleMeasurementReturned_Test(string eventJson) { var evt = EventDataTestHelper.BuildEventFromJson(eventJson); var token = new EventDataWithJsonBodyToJTokenConverter().Convert(evt); var result = MultiValueTemplate.GetMeasurements(token).ToArray(); Assert.NotNull(result); Assert.Collection(result, m => { Assert.Equal("bloodpressure", m.Type); Assert.Equal(evt.Properties["iothub-creation-time-utc"], m.OccurrenceTimeUtc); Assert.Equal(evt.SystemProperties["iothub-connection-device-id"], m.DeviceId); Assert.Collection( m.Properties, p => { Assert.Equal("systolic", p.Name); Assert.Equal("111", p.Value); }, p => { Assert.Equal("diastolic", p.Name); Assert.Equal("75", p.Value); }); }); }
public void GivenIoTCentralPopulatedEvent_WhenConvert_ThenTokenWithNonSerializedBodyAndPropertiesReturned_Test(string json) { var evt = EventDataTestHelper.BuildEventFromJson(json); var token = new EventDataWithJsonBodyToJTokenConverter().Convert(evt); Assert.NotNull(token); Assert.NotNull(token["Body"]); Assert.NotNull(token["Properties"]); Assert.NotNull(token["SystemProperties"]); // Verify Body is correctly turned into a JToken instead of a base 64 encoded array Assert.Equal("203", token["Body"]["heartrate"].ToString()); // Verify EventData.Properties are present on the returned JToken Assert.Equal("2019-01-30T22:45:02.6073744Z", token["Properties"]["iothub-creation-time-utc"].ToObject <DateTime>().ToString("o")); Assert.Equal("America/Los_Angeles", token["Properties"]["tz"].ToString()); Assert.Equal("55b1e26f-9c83-4264-a0dd-3567afd633d6", token["Properties"]["batchid"].ToString()); Assert.Equal("60", token["Properties"]["batchsize"].ToString()); // Verify EventData.SystemProperties are present on the returned JToken Assert.Equal("ev-d795-1d04-55ae", token["SystemProperties"]["iothub-connection-device-id"].ToString()); Assert.Equal("{\"scope\":\"device\",\"type\":\"sas\",\"issuer\":\"iothub\",\"acceptingIpFilterRule\":null}", token["SystemProperties"]["iothub-connection-auth-method"].ToString()); Assert.Equal("636845741198574895", token["SystemProperties"]["iothub-connection-auth-generation-id"].ToString()); Assert.Equal("2019-02-01T22:46:01.8750000Z", token["SystemProperties"]["iothub-enqueuedtime"].ToObject <DateTime>().ToString("o")); }
public void GivenTemplateAndSingleValidTokenWithoutCreationTime_WhenGetMeasurements_ThenSingleMeasurementReturned_Test(string eventJson) { var evt = EventDataTestHelper.BuildEventFromJson(eventJson); var token = new EventDataWithJsonBodyToJTokenConverter().Convert(evt); var result = SingleValueTemplate.GetMeasurements(token).ToArray(); Assert.NotNull(result); Assert.Collection(result, m => { Assert.Equal("heartrate", m.Type); Assert.Equal(evt.SystemProperties["iothub-enqueuedtime"], m.OccurrenceTimeUtc); Assert.Equal(evt.SystemProperties["iothub-connection-device-id"], m.DeviceId); Assert.Collection(m.Properties, p => { Assert.Equal("hr", p.Name); Assert.Equal("203", p.Value); }); }); }