public void ConnectionStringAttribute_ResolvesCorrectly()
        {
            ConnectionStrings attr = new ConnectionStrings
            {
                Connection                = "key",
                ConnectionAtRoot          = "rootKey",
                ConnectionWithNestedPath  = "nested:path:key",
                ConnectionOverrideDefault = "overridden"
            };

            var config = TestHelpers.CreateInMemoryCollection()
                         .AddSetting("key", "unused")
                         .AddSetting("rootKey", "rootValue")
                         .AddSetting("connectionStrings:key", "connectionStringsValue")
                         .AddSetting("nested:path:key", "nestedPathValue")
                         .AddSetting("nested:path:defaultKey", "nestedPathDefaultValue")
                         .AddSetting("connectionStrings:overridden", "connectionStringsOverriddenValue")
                         .AddSetting("connectionStrings:defaultSetting", "fromConnStr")
                         .AddSetting("defaultSetting", "fromRoot")
                         .BuildConfiguration();

            var nameResolver = new FakeNameResolver();
            var cloner       = new AttributeCloner <ConnectionStrings>(attr, emptyContract, config, nameResolver);
            var cloned       = cloner.GetNameResolvedAttribute();

            Assert.Equal("connectionStringsValue", cloned.Connection);
            Assert.Equal("rootValue", cloned.ConnectionAtRoot);
            Assert.Equal("nestedPathValue", cloned.ConnectionWithNestedPath);
            Assert.Equal("connectionStringsOverriddenValue", cloned.ConnectionOverrideDefault);
            Assert.Equal("nestedPathDefaultValue", cloned.ConnectionWithNestedDefaultPath);
            Assert.Equal("fromConnStr", cloned.ConnectionWithDefault);
            Assert.Equal("fromRoot", cloned.AppSettingWithDefault);
        }
        public void AppSettingAttribute_Resolves_IfDefaultMatched()
        {
            Attr3 a3 = new Attr3()
            {
                Required = "req"
            };
            var nameResolver = new FakeNameResolver().Add("default", "defaultval").Add("req", "reqval");
            var cloner       = new AttributeCloner <Attr3>(a3, emptyContract, nameResolver);
            var cloned       = cloner.GetNameResolvedAttribute();

            Assert.Equal("reqval", cloned.Required);
            Assert.Equal("defaultval", cloned.Default);
        }
        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);
        }
Пример #4
0
        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 AppSettingAttribute_DoesNotThrowIfNullValueAndNoDefault()
        {
            Attr4 a4 = new Attr4();

            a4.AutoResolve = "auto";
            a4.AppSetting  = null;

            var nameResolver = new FakeNameResolver();
            var cloner       = new AttributeCloner <Attr4>(a4, emptyContract, nameResolver);
            var cloned       = cloner.GetNameResolvedAttribute();

            Assert.Equal("auto", cloned.AutoResolve);
            Assert.Equal(null, cloned.AppSetting);
        }
        public void AppSettingAttribute_ResolvesWholeValueAsSetting()
        {
            Attr4 a4   = new Attr4();
            var   name = "test{x}and%y%";

            a4.AppSetting = a4.AutoResolve = name;

            var nameResolver = new FakeNameResolver()
                               .Add("y", "Setting")
                               .Add(name, "AppSetting");
            var cloner = new AttributeCloner <Attr4>(a4, GetBindingContract("x"), nameResolver);
            var cloned = cloner.GetNameResolvedAttribute();

            // autoresolve resolves tokens
            Assert.Equal("test{x}andSetting", cloned.AutoResolve);
            // appsetting treats entire string as app setting name
            Assert.Equal("AppSetting", cloned.AppSetting);
        }
Пример #7
0
        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);
        }
Пример #8
0
        public void AppSettingAttribute_Resolves_IfDefaultMatched()
        {
            Attr3 a3 = new Attr3()
            {
                Required = "req"
            };
            var nameResolver = new FakeNameResolver();

            var config = TestHelpers.CreateInMemoryCollection()
                         .AddSetting("default", "defaultval")
                         .AddSetting("req", "reqval")
                         .BuildConfiguration();

            var cloner = new AttributeCloner <Attr3>(a3, emptyContract, config, nameResolver);
            var cloned = cloner.GetNameResolvedAttribute();

            Assert.Equal("reqval", cloned.Required);
            Assert.Equal("defaultval", cloned.Default);
        }
Пример #9
0
        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 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);
        }
        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 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.ResolveFromBindingDataAsync(ctx);

            Assert.Equal("xABCy-v", attr2.Path);
        }