public void Setting_WithNoValueInResolver_Throws() { Attr2 a2 = new Attr2(string.Empty, string.Empty) { ResolvedSetting = "appsetting" }; Assert.Throws <InvalidOperationException>(() => new AttributeCloner <Attr2>(a2, EmptyContract, null)); }
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 void Setting_WithNoValueInResolver_ThrowsIfNoDefault() { Attr2 a2 = new Attr2(string.Empty, string.Empty) { ResolvedSetting = "appsetting" }; var exc = Assert.Throws <InvalidOperationException>(() => new AttributeCloner <Attr2>(a2, emptyContract)); Assert.Equal($"Unable to resolve app setting for property 'Attr2.ResolvedSetting'. Make sure the app setting exists and has a valid value.", exc.Message); }
public async Task Setting_Null() { Attr2 a2 = new Attr2(string.Empty, string.Empty); var cloner = new AttributeCloner <Attr2>(a2, EmptyContract, null); Attr2 a2Clone = await cloner.ResolveFromBindingDataAsync(GetCtx(null)); Assert.Null(a2Clone.ResolvedSetting); }
public void Setting_WithNoValueInResolver_UsesDefault() { Attr2 a2 = new Attr2(string.Empty, string.Empty) { ResolvedSetting = "appsetting" }; var nameResolver = new FakeNameResolver().Add("appsetting", "ABC").Add("default", "default"); var cloner = new AttributeCloner <Attr2>(a2, emptyContract, nameResolver); var a2Cloned = cloner.GetNameResolvedAttribute(); Assert.Equal("default", a2Cloned.DefaultSetting); }
public void Setting() { Attr2 a2 = new Attr2(string.Empty, string.Empty) { ResolvedSetting = "appsetting" }; var nameResolver = new FakeNameResolver().Add("appsetting", "ABC"); var cloner = new AttributeCloner <Attr2>(a2, EmptyContract, nameResolver); var a2Cloned = cloner.GetNameResolvedAttribute(); Assert.Equal("ABC", a2Cloned.ResolvedSetting); }
public void TryAutoResolveValue_UnresolvedValue_ThrowsExpectedException() { var resolver = new FakeNameResolver(); var attribute = new Attr2(string.Empty, string.Empty) { ResolvedSetting = "MySetting" }; var prop = attribute.GetType().GetProperty("ResolvedSetting"); string resolvedValue = null; var ex = Assert.Throws <InvalidOperationException>(() => AttributeCloner <Attr2> .TryAutoResolveValue(attribute, prop, resolver, out resolvedValue)); Assert.Equal("Unable to resolve value for property 'Attr2.ResolvedSetting'.", ex.Message); }
public void TryAutoResolveValue_UnresolvedValue_ThrowsExpectedException() { var resolver = new FakeNameResolver(); var attribute = new Attr2(string.Empty, string.Empty) { ResolvedSetting = "MySetting" }; var prop = attribute.GetType().GetProperty("ResolvedSetting"); var attr = prop.GetCustomAttribute <AppSettingAttribute>(); string resolvedValue = "MySetting"; var ex = Assert.Throws <InvalidOperationException>(() => AttributeCloner <Attr2> .GetAppSettingResolver(resolvedValue, attr, resolver, prop, skipValidation)); Assert.Contains("Unable to resolve app setting for property 'Attr2.ResolvedSetting'.", ex.Message); }
public void Setting_WithNoValueInResolver_UsesDefault() { Attr2 a2 = new Attr2(string.Empty, string.Empty) { ResolvedSetting = "appsetting" }; var nameResolver = new FakeNameResolver(); var config = TestHelpers.CreateInMemoryCollection() .AddSetting("appsetting", "ABC") .AddSetting("default", "default") .BuildConfiguration(); var cloner = new AttributeCloner <Attr2>(a2, emptyContract, config, nameResolver); var a2Cloned = cloner.GetNameResolvedAttribute(); Assert.Equal("default", a2Cloned.DefaultSetting); }
public void Setting() { Attr2 a2 = new Attr2(string.Empty, string.Empty) { ResolvedSetting = "appsetting" }; var nameResolver = new FakeNameResolver(); var config = TestHelpers.CreateInMemoryCollection() .AddSetting("appsetting", "ABC") .AddSetting("connectionStrings:default", "fromConnStr") .BuildConfiguration(); var cloner = new AttributeCloner <Attr2>(a2, emptyContract, config, nameResolver); var a2Cloned = cloner.GetNameResolvedAttribute(); Assert.Equal("ABC", a2Cloned.ResolvedSetting); Assert.Equal("fromConnStr", a2Cloned.Connection); }
public async Task InvokeStringMultipleResolvedProperties() { Attr2 attr = new Attr2("{p2}", "constant") { ResolvedProp1 = "{p1}" }; var cloner = new AttributeCloner <Attr2>(attr, GetBindingContract("p1", "p2")); Attr2 attrResolved = cloner.ResolveFromBindings(new Dictionary <string, object> { { "p1", "v1" }, { "p2", "v2" } }); Assert.Equal("v1", attrResolved.ResolvedProp1); Assert.Equal("v2", attrResolved.ResolvedProp2); Assert.Equal(attr.ConstantProp, attrResolved.ConstantProp); var invokeString = cloner.GetInvokeString(attrResolved); var attr2 = await cloner.ResolveFromInvokeString(invokeString); Assert.Equal(attrResolved.ResolvedProp1, attr2.ResolvedProp1); Assert.Equal(attrResolved.ResolvedProp2, attr2.ResolvedProp2); Assert.Equal(attrResolved.ConstantProp, attr2.ConstantProp); }
public void Fail_MalformedPath_CtorArg() { var attr = new Attr2("%bad", "constant"); Assert.Throws <InvalidOperationException>(() => new AttributeCloner <Attr2>(attr, EmptyContract)); }
public void Fail_MalformedPath_CtorArg() { var attr = new Attr2("%bad", "constant"); Assert.Throws<InvalidOperationException>(() => new AttributeCloner<Attr2>(attr, EmptyContract)); }
public async Task Setting_Null() { Attr2 a2 = new Attr2(string.Empty, string.Empty); var cloner = new AttributeCloner<Attr2>(a2, EmptyContract, null); Attr2 a2Clone = await cloner.ResolveFromBindingDataAsync(GetCtx(null)); Assert.Null(a2Clone.ResolvedSetting); }
public void Setting_WithNoValueInResolver_Throws() { Attr2 a2 = new Attr2(string.Empty, string.Empty) { ResolvedSetting = "appsetting" }; Assert.Throws<InvalidOperationException>(() => new AttributeCloner<Attr2>(a2, EmptyContract, null)); }
public void Setting() { Attr2 a2 = new Attr2(string.Empty, string.Empty) { ResolvedSetting = "appsetting" }; var nameResolver = new FakeNameResolver().Add("appsetting", "ABC"); var cloner = new AttributeCloner<Attr2>(a2, EmptyContract, nameResolver); var a2Cloned = cloner.GetNameResolvedAttribute(); Assert.Equal("ABC", a2Cloned.ResolvedSetting); }
public async Task InvokeStringMultipleResolvedProperties() { Attr2 attr = new Attr2("{p2}", "constant") { ResolvedProp1 = "{p1}" }; var cloner = new AttributeCloner<Attr2>(attr, GetBindingContract("p1", "p2")); Attr2 attrResolved = cloner.ResolveFromBindings(new Dictionary<string, object> { { "p1", "v1" }, { "p2", "v2" }}); Assert.Equal("v1", attrResolved.ResolvedProp1); Assert.Equal("v2", attrResolved.ResolvedProp2); Assert.Equal(attr.ConstantProp, attrResolved.ConstantProp); var invokeString = cloner.GetInvokeString(attrResolved); var attr2 = await cloner.ResolveFromInvokeStringAsync(invokeString); Assert.Equal(attrResolved.ResolvedProp1, attr2.ResolvedProp1); Assert.Equal(attrResolved.ResolvedProp2, attr2.ResolvedProp2); Assert.Equal(attrResolved.ConstantProp, attr2.ConstantProp); }