public void GivenValidTemplateJsonWithOptionalExpressions_WhenFactoryCreate_ThenTemplateCreated_Test(string json) { var templateContainer = JsonConvert.DeserializeObject <TemplateContainer>(json); var factory = new JsonPathContentTemplateFactory(); var template = factory.Create(templateContainer); Assert.NotNull(template); var jsonPathTemplate = template as JsonPathContentTemplate; Assert.NotNull(jsonPathTemplate); Assert.Equal("heartrate", jsonPathTemplate.TypeName); Assert.Equal("$..[?(@heartrate)]", jsonPathTemplate.TypeMatchExpression); Assert.Equal("$.device", jsonPathTemplate.DeviceIdExpression); Assert.Equal("$.date", jsonPathTemplate.TimestampExpression); Assert.Equal("$.patient", jsonPathTemplate.PatientIdExpression); Assert.Collection(jsonPathTemplate.Values, v => { Assert.True(v.Required); Assert.Equal("hr", v.ValueName); Assert.Equal("$.heartrate", v.ValueExpression); }); }
public void GivenValidTemplateJsonWithOptionalExpressions_WhenFactoryCreate_ThenTemplateCreated_Test(string json) { var templateContainer = JsonConvert.DeserializeObject <TemplateContainer>(json); var factory = new JsonPathContentTemplateFactory(); var contentTemplate = factory.Create(templateContainer); Assert.NotNull(contentTemplate); Assert.IsType <LegacyMeasurementExtractor>(contentTemplate); var extractor = contentTemplate as MeasurementExtractor; Assert.IsType <JsonPathCalculatedFunctionContentTemplateAdapter <JsonPathContentTemplate> >(extractor.Template); var jsonPathTemplate = (extractor.Template as JsonPathCalculatedFunctionContentTemplateAdapter <JsonPathContentTemplate>).InnerTemplate; Assert.Equal("heartrate", jsonPathTemplate.TypeName); Assert.Equal("$..[?(@heartrate)]", jsonPathTemplate.TypeMatchExpression); Assert.Equal("$.device", jsonPathTemplate.DeviceIdExpression); Assert.Equal("$.date", jsonPathTemplate.TimestampExpression); Assert.Equal("$.patient", jsonPathTemplate.PatientIdExpression); Assert.Equal("$.sessionid", jsonPathTemplate.CorrelationIdExpression); Assert.Collection(jsonPathTemplate.Values, v => { Assert.True(v.Required); Assert.Equal("hr", v.ValueName); Assert.Equal("$.heartrate", v.ValueExpression); }); }
public void GivenInvalidTemplateTargetType_WhenFactoryCreate_ThenNullReturned_Test() { var templateContainer = new TemplateContainer(); var factory = new JsonPathContentTemplateFactory(); var template = factory.Create(templateContainer); Assert.Null(template); }
public void GivenInvalidTemplateJsonMissingExpressions_WhenFactoryCreate_ThenTemplateErrorReturned_Test(string json) { var templateContainer = JsonConvert.DeserializeObject <TemplateContainer>(json); var factory = new JsonPathContentTemplateFactory(); var ex = Assert.Throws <InvalidTemplateException>(() => factory.Create(templateContainer)); Assert.NotNull(ex); Assert.Contains("DeviceIdExpression", ex.Message); Assert.Contains("TimestampExpression", ex.Message); }
public void GivenInvalidTemplateBody_WhenFactoryCreate_ThenInvalidTemplateExceptionThrown_Test() { var templateContainer = new TemplateContainer { TemplateType = "JsonPathContentTemplate", Template = null, }; var factory = new JsonPathContentTemplateFactory(); var ex = Assert.Throws <InvalidTemplateException>(() => factory.Create(templateContainer)); Assert.NotNull(ex); }