Exemplo n.º 1
0
        public void GivenInvalidTypeMatchExpression_WhenGetMeasurements_ThenExceptionIsThrown_Test(string typeMatchExpression)
        {
            var time  = DateTime.UtcNow;
            var token = JToken.FromObject(new JsonWidget {
                MyProperty = "data", Time = time
            });

            var template = new JsonPathContentTemplate
            {
                TypeName            = "space",
                TypeMatchExpression = typeMatchExpression,
                DeviceIdExpression  = "$.['My Property']",
                TimestampExpression = "$.Time",
                Values = new List <JsonPathValueExpression>
                {
                    new JsonPathValueExpression {
                        ValueName = "prop", ValueExpression = "$.['My Property']", Required = false
                    },
                },
            };

            var ex = Assert.Throws <IncompatibleDataException>(() => BuildMeasurementExtractor(template).GetMeasurements(token).ToArray());

            Assert.Equal("An expression must be set for [TypeMatchExpression]", ex.Message);
        }
Exemplo n.º 2
0
        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);
            });
        }
Exemplo n.º 3
0
        public void GivenPropertyWithSpace_WhenGetMeasurements_ThenSingleMeasurementReturned_Test()
        {
            var time  = DateTime.UtcNow;
            var token = JToken.FromObject(new JsonWidget {
                MyProperty = "data", Time = time
            });

            var template = new JsonPathContentTemplate
            {
                TypeName            = "space",
                TypeMatchExpression = "$..[?(@['My Property'])]",
                DeviceIdExpression  = "$.['My Property']",
                TimestampExpression = "$.Time",
                Values = new List <JsonPathValueExpression>
                {
                    new JsonPathValueExpression {
                        ValueName = "prop", ValueExpression = "$.['My Property']", Required = false
                    },
                },
            };

            var result = BuildMeasurementExtractor(template).GetMeasurements(token).ToArray();

            Assert.NotNull(result);
            Assert.Collection(result, m =>
            {
                Assert.Equal("space", m.Type);
                Assert.Equal(time, m.OccurrenceTimeUtc);
                Assert.Equal("data", m.DeviceId);
                Assert.Null(m.PatientId);
                Assert.Null(m.EncounterId);
                Assert.Null(m.CorrelationId);
                Assert.Collection(m.Properties, p =>
                {
                    Assert.Equal("prop", p.Name);
                    Assert.Equal("data", p.Value);
                });
            });
        }
Exemplo n.º 4
0
 private static IContentTemplate BuildMeasurementExtractor(JsonPathContentTemplate template)
 {
     return(new LegacyMeasurementExtractor(
                new JsonPathCalculatedFunctionContentTemplateAdapter <JsonPathContentTemplate>(template),
                new JsonPathExpressionEvaluatorFactory()));
 }