public void Validation_Late() { // with { } , can't determine if it's valid until after resolution. ValidationWithAutoResolveAttribute attr = new ValidationWithAutoResolveAttribute { Value = "a{name}" }; // Can't fail yet. var cloner = new AttributeCloner <ValidationWithAutoResolveAttribute>(attr, GetBindingContract("name")); // Valid { Dictionary <string, object> values = new Dictionary <string, object>() { { "name", "aa" }, // Ok }; var ctx = GetCtx(values); var attr2 = cloner.ResolveFromBindingData(ctx); Assert.Equal("aaa", attr2.Value); } // Invalid { Dictionary <string, object> values = new Dictionary <string, object>() { { "name", "b" }, // regex failure }; var ctx = GetCtx(values); Assert.Throws <InvalidOperationException>(() => cloner.ResolveFromBindingData(ctx)); } }
public void DefaultMethodName(string propValue, string expectedValue) { Attr5 attr = new Attr5 { AutoResolve = propValue }; // Pick method name var nameResolver = new FakeNameResolver() .Add("empty2", "") .Add("value2", "456"); Dictionary <string, object> values = new Dictionary <string, object>() { { "empty", "" }, { "value", "123" } }; new SystemBindingData { MethodName = "MyMethod" }.AddToBindingData(values); var ctx = GetCtx(values); var cloner = new AttributeCloner <Attr5>(attr, GetBindingContract(values), nameResolver); var attr2 = cloner.ResolveFromBindingData(ctx); Assert.Equal(expectedValue, attr2.AutoResolve); }
public void Setting_Null() { Attr2 a2 = new Attr2(string.Empty, string.Empty); var cloner = new AttributeCloner <Attr2>(a2, emptyContract); Attr2 a2Clone = cloner.ResolveFromBindingData(GetCtx(null)); Assert.Null(a2Clone.ResolvedSetting); }
public async Task CloneNoDefaultCtor() { var a1 = new BlobAttribute("container/{name}.txt", FileAccess.Write); Dictionary <string, object> values = new Dictionary <string, object>() { { "name", "green" }, }; var ctx = GetCtx(values); var cloner = new AttributeCloner <BlobAttribute>(a1, GetBindingContract("name")); var attr2 = await cloner.ResolveFromBindingData(ctx); Assert.Equal("container/green.txt", attr2.BlobPath); Assert.Equal(a1.Access, attr2.Access); }
public void CloneNoDefaultCtorShortList() { // Use shorter parameter list. var a1 = new BlobAttribute("container/{name}.txt"); Dictionary <string, object> values = new Dictionary <string, object>() { { "name", "green" }, }; var ctx = GetCtx(values); var cloner = new AttributeCloner <BlobAttribute>(a1, GetBindingContract("name")); var attr2 = cloner.ResolveFromBindingData(ctx); Assert.Equal("container/green.txt", attr2.BlobPath); Assert.Equal(a1.Access, attr2.Access); }
public void Validation_Early_Succeed() { ValidationWithAutoResolveAttribute attr = new ValidationWithAutoResolveAttribute { Value = "aaa" }; Dictionary <string, object> values = new Dictionary <string, object>() { { "name", "green" }, }; var ctx = GetCtx(values); var cloner = new AttributeCloner <ValidationWithAutoResolveAttribute>(attr, GetBindingContract("name")); var attr2 = cloner.ResolveFromBindingData(ctx); Assert.Equal("aaa", attr2.Value); }
public async Task Easy() { Attr1 a1 = new Attr1 { Path = "{key1}-{key2}" }; Dictionary <string, object> values = new Dictionary <string, object>() { { "key1", "val1" }, { "key2", "val2" } }; var ctx = GetCtx(values); var cloner = new AttributeCloner <Attr1>(a1, GetBindingContract("key1", "key2")); var attr2 = await cloner.ResolveFromBindingData(ctx); Assert.Equal("val1-val2", attr2.Path); }
public void Easy() { Attr1 a1 = new Attr1 { Path = "{request.headers.authorization}-{key2}" }; Dictionary <string, object> values = new Dictionary <string, object>() { { "request", new { headers = new { authorization = "ey123" } } }, { "key2", "val2" } }; var ctx = GetCtx(values); var cloner = new AttributeCloner <Attr1>(a1, GetBindingContract("request", "key2")); var attr2 = cloner.ResolveFromBindingData(ctx); Assert.Equal("ey123-val2", attr2.Path); }
public async Task NameResolver() { Attr1 a1 = new Attr1 { Path = "x%appsetting%y-{k}" }; var nameResolver = new FakeNameResolver().Add("appsetting", "ABC"); var cloner = new AttributeCloner <Attr1>(a1, GetBindingContract("k"), nameResolver); // Get the attribute with %% resolved (happens at indexing time), but not {} (not resolved until runtime) var attrPre = cloner.GetNameResolvedAttribute(); Assert.Equal("xABCy-{k}", attrPre.Path); Dictionary <string, object> values = new Dictionary <string, object>() { { "k", "v" } }; var ctx = GetCtx(values); var attr2 = await cloner.ResolveFromBindingData(ctx); Assert.Equal("xABCy-v", attr2.Path); }