public void Bind_should_apply_global_expression_context_and_local_expression_context() { var opts = new PropertyTreeBinderOptions { ExpressionContext = new ExpressionContext { Data = { { "element", 30 } } } }; const string text = @"<fileTarget u='${a + q + element}'> </fileTarget>"; var f = PropertyTree.FromStreamContext(StreamContext.FromText(text)).Bind <F>(opts); Assert.Equal(60, f.Properties.GetInt32("u")); }
public void Bind_should_apply_collection_aggregation_on_readwrite_untyped_values_from_IProperties() { const string text = @"<d d='a b c' />"; var item = PropertyTree.FromStreamContext(StreamContext.FromText(text)).Bind <D>(); // We are using the indexer on D to provide an indirection to Delta.D, which is itself // a List<string>. This should mean that aggregation using space-delimited list // is allowed. // var list = (IList<string>) item["D"]; var list = item.U.D; Assert.Equal(new object[] { "a", "b", "c" }, list); }
public void Bind_should_use_properties_for_expressions_even_for_reflection() { var opts = new PropertyTreeBinderOptions { ExpressionContext = new ExpressionContext { Data = { { "element", 20 } } } }; const string text = @"<fileTarget s='${element}'> </fileTarget>"; var f = PropertyTree.FromStreamContext(StreamContext.FromText(text)).Bind <F>(opts); Assert.Equal(0, f.S); // Shouldn't be available to reflection Assert.Equal(20, f.Properties.GetInt32("s")); Assert.IsInstanceOf <CallExpression>(f.Properties.GetProperty <Expression>("s")); }
public void Bind_should_apply_property_type_conversion() { var opts = new PropertyTreeBinderOptions { ExpressionContext = new ExpressionContext { Data = { { "m", "https://" }, { "b", "example.org" }, } } }; const string text = @"<fileTarget u='${m}${b}/yas'> </fileTarget>"; var f = PropertyTree.FromStreamContext(StreamContext.FromText(text)).Bind <F>(opts); Assert.Equal(new Uri("https://example.org/yas"), f.Properties.GetProperty <Uri>("u")); }
public void bind_template_properties_object() { var pp = PropertyTree.FromStreamContext(StreamContext.FromText(@" <iotaChi xmlns='https://ns.example.com/'> <add> <template> <foxtrot target='some'></foxtrot> </template> <a provider='properties' /> </add> </iotaChi>")); var col = pp.Bind <IotaChi>().B; // Assert.IsAssignableFrom<Template<Foxtrot>>(col.Template); var template = (Template <Foxtrot>)col.Template; Assert.Equal("some", template.CreateInstance().Properties.GetProperty("target")); }