public void When_AllExpressionsAreSupplied_AllExpressions_Are_Initialized() { var contentTemplate = new JsonPathContentTemplate { TypeName = "heartrate", TypeMatchExpression = "$..[?(@heartrate)]", DeviceIdExpression = "$.device", TimestampExpression = "$.date", PatientIdExpression = "$.patientId", CorrelationIdExpression = "$.corId", EncounterIdExpression = "$.encounterId", Values = new List <JsonPathValueExpression> { new JsonPathValueExpression { ValueName = "hr1", ValueExpression = "$.heartrate", Required = false }, new JsonPathValueExpression { ValueName = "hr2", ValueExpression = "$.heartrate2", Required = true }, }, }; var facade = new JsonPathCalculatedFunctionContentTemplateAdapter <JsonPathContentTemplate>(contentTemplate); Assert.Equal("heartrate", facade.TypeName); Assert.Equal("$..[?(@heartrate)]", facade.TypeMatchExpression.Value); Assert.Equal("$.device", facade.DeviceIdExpression.Value); Assert.Equal(TemplateExpressionLanguage.JsonPath, facade.DeviceIdExpression.Language); Assert.Equal("$.date", facade.TimestampExpression.Value); Assert.Equal(TemplateExpressionLanguage.JsonPath, facade.TimestampExpression.Language); Assert.Equal("$.patientId", facade.PatientIdExpression.Value); Assert.Equal(TemplateExpressionLanguage.JsonPath, facade.PatientIdExpression.Language); Assert.Equal("$.corId", facade.CorrelationIdExpression.Value); Assert.Equal(TemplateExpressionLanguage.JsonPath, facade.CorrelationIdExpression.Language); Assert.Equal("$.encounterId", facade.EncounterIdExpression.Value); Assert.Equal(TemplateExpressionLanguage.JsonPath, facade.EncounterIdExpression.Language); Assert.Collection( facade.Values, item => { Assert.Equal("hr1", item.ValueName); Assert.Equal("$.heartrate", item.ValueExpression.Value); Assert.False(item.Required); }, item => { Assert.Equal("hr2", item.ValueName); Assert.Equal("$.heartrate2", item.ValueExpression.Value); Assert.True(item.Required); }); }
public override IContentTemplate Create(TemplateContainer jsonTemplate) { EnsureArg.IsNotNull(jsonTemplate, nameof(jsonTemplate)); const string targetTypeName = "IotCentralJsonPathContent"; if (!jsonTemplate.MatchTemplateName(targetTypeName)) { return(null); } if (jsonTemplate.Template?.Type != JTokenType.Object) { throw new InvalidTemplateException($"Expected an object for the template property value for template type {targetTypeName}."); } var facade = new JsonPathCalculatedFunctionContentTemplateAdapter <IotCentralJsonPathContentTemplate>( jsonTemplate.Template.ToValidTemplate <IotCentralJsonPathContentTemplate>()); return(new LegacyMeasurementExtractor(facade, new JsonPathExpressionEvaluatorFactory())); }