当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationBuilder.Build方法代码示例

本文整理汇总了C#中ConfigurationBuilder.Build方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.Build方法的具体用法?C# ConfigurationBuilder.Build怎么用?C# ConfigurationBuilder.Build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigurationBuilder的用法示例。


在下文中一共展示了ConfigurationBuilder.Build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WithAllLinkedResources_maps_properly

        public void WithAllLinkedResources_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            builder
                .WithConvention(new DefaultPropertyScanningConvention())
                .WithConvention(new CamelCaseLinkNameConvention())
                .WithConvention(new PluralizedCamelCaseTypeConvention())
                .WithConvention(new SimpleLinkedIdConvention());

            //Act
            builder
                .Resource<Post>()
                .WithAllLinkedResources();

            builder.Resource<Author>();
            builder.Resource<Comment>();

            var configuration = builder.Build();
            var postMapping = configuration.GetMapping(typeof(Post));

            //Assert
            postMapping.Relationships.Count.ShouldEqual(2);
            postMapping.Relationships.SingleOrDefault(l => l.RelatedBaseResourceType == "authors").ShouldNotBeNull();
            postMapping.Relationships.SingleOrDefault(l => l.RelatedBaseResourceType == "comments").ShouldNotBeNull();
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:26,代码来源:ConfigurationBuilderTest.cs

示例2: NewConfigurationProviderOverridesOldOneWhenKeyIsDuplicated

        public void NewConfigurationProviderOverridesOldOneWhenKeyIsDuplicated()
        {
            // Arrange
            var dic1 = new Dictionary<string, string>()
                {
                    {"Key1:Key2", "ValueInMem1"}
                };
            var dic2 = new Dictionary<string, string>()
                {
                    {"Key1:Key2", "ValueInMem2"}
                };
            var memConfigSrc1 = new MemoryConfigurationProvider(dic1);
            var memConfigSrc2 = new MemoryConfigurationProvider(dic2);

            var configurationBuilder = new ConfigurationBuilder();

            // Act
            configurationBuilder.Add(memConfigSrc1, load: false);
            configurationBuilder.Add(memConfigSrc2, load: false);

            var config = configurationBuilder.Build();

            // Assert
            Assert.Equal("ValueInMem2", config["Key1:Key2"]);
        }
开发者ID:leloulight,项目名称:Configuration,代码行数:25,代码来源:ConfigurationTest.cs

示例3: OnCreate

		protected override void OnCreate(Bundle bundle)
		{
			base.OnCreate(bundle);

			// Set our view from the "main" layout resource
			SetContentView(Resource.Layout.Autorize);

			// Get our button from the layout resource,
			// and attach an event to it
			Button button = FindViewById<Button>(Resource.Id.sumbit);

			button.Click += delegate {
				EditText textLogin = FindViewById<EditText> (Resource.Id.login);
				EditText textPass = FindViewById<EditText> (Resource.Id.password);
				string login = textLogin.Text.ToString ();
				string pass = textPass.Text.ToString ();
				// TODO change OAuth keys and tokens and username and password 

				config = new ConfigurationBuilder ();
				config.SetOAuthConsumerKey ("nz2FD8IELdrglLbNMJ1WeMsze");
				config.SetOAuthConsumerSecret ("Q5ZGt7Bc2McY3xdfjks3AU4yw5DKKSv0h3oXCTpjYhV25qwKL0");
				config.SetOAuthAccessToken ("4359603449-6z2CXsqmH4REQayCNgqwq71wM49PjbkSmNIUJil");
				config.SetOAuthAccessTokenSecret ("nAvebHjYLn1JXnO4PwqtmTBhPoet5rhIRUnlKghtmT8Ns");
				config.SetUser (login);
				config.SetPassword (pass);

				factory = new TwitterFactory (config.Build ());
				twitter = factory.Instance;

				GetInfo ();
			};
		}
开发者ID:okrotowa,项目名称:Mosigra.Yorsh,代码行数:32,代码来源:ShareToTwitterActivity.cs

示例4: WithSimpleProperty_maps_properly

        public void WithSimpleProperty_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            var post = new Post() { Title = "test" };

            //Act
            builder
                .Resource<Post, PostsController>()
                .WithSimpleProperty(p => p.Title);

            var configuration = builder.Build();
            var mapping = configuration.GetMapping(typeof(Post));

            //Assert
            Assert.Equal(mapping.PropertyGetters.Count, 1);
            Assert.Equal(mapping.PropertySetters.Count, 1);

            var getter = mapping.PropertyGetters.Single().Value;
            var setter = mapping.PropertySetters.Single().Value;

            Assert.Equal(((string)getter(post)), "test");

            setter(post, "works");
            Assert.Equal(post.Title, "works");
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:26,代码来源:ConfigurationBuilderTest.cs

示例5: ArrayMerge

        public void ArrayMerge()
        {
            var json1 = @"{
                'ip': [
                    '1.2.3.4',
                    '7.8.9.10',
                    '11.12.13.14'
                ]
            }";

            var json2 = @"{
                'ip': {
                    '3': '15.16.17.18'
                }
            }";

            var jsonConfigSource1 = new JsonConfigurationProvider(TestStreamHelpers.ArbitraryFilePath);
            jsonConfigSource1.Load(TestStreamHelpers.StringToStream(json1));

            var jsonConfigSource2 = new JsonConfigurationProvider(TestStreamHelpers.ArbitraryFilePath);
            jsonConfigSource2.Load(TestStreamHelpers.StringToStream(json2));

            var builder = new ConfigurationBuilder();
            builder.Add(jsonConfigSource1, load: false);
            builder.Add(jsonConfigSource2, load: false);
            var config = builder.Build();

            Assert.Equal(4, config.GetSection("ip").GetChildren().Count());
            Assert.Equal("1.2.3.4", config["ip:0"]);
            Assert.Equal("7.8.9.10", config["ip:1"]);
            Assert.Equal("11.12.13.14", config["ip:2"]);
            Assert.Equal("15.16.17.18", config["ip:3"]);
        }
开发者ID:Gavinshi,项目名称:Configuration,代码行数:33,代码来源:ArrayTest.cs

示例6: DifferentConfigSources_Merged_KeysAreSorted

        public void DifferentConfigSources_Merged_KeysAreSorted()
        {
            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddJsonFile(_json1ConfigFilePath);
            configurationBuilder.AddIniFile(_iniConfigFilePath);
            configurationBuilder.AddJsonFile(_json2ConfigFilePath);
            configurationBuilder.AddXmlFile(_xmlConfigFilePath);

            var config = configurationBuilder.Build();

            var configurationSection = config.GetSection("address");
            var indexConfigurationSections = configurationSection.GetChildren().ToArray();

            Assert.Equal(8, indexConfigurationSections.Length);
            Assert.Equal("0", indexConfigurationSections[0].Key);
            Assert.Equal("1", indexConfigurationSections[1].Key);
            Assert.Equal("2", indexConfigurationSections[2].Key);
            Assert.Equal("3", indexConfigurationSections[3].Key);
            Assert.Equal("4", indexConfigurationSections[4].Key);
            Assert.Equal("i", indexConfigurationSections[5].Key);
            Assert.Equal("j", indexConfigurationSections[6].Key);
            Assert.Equal("x", indexConfigurationSections[7].Key);

            Assert.Equal("address:0", indexConfigurationSections[0].Path);
            Assert.Equal("address:1", indexConfigurationSections[1].Path);
            Assert.Equal("address:2", indexConfigurationSections[2].Path);
            Assert.Equal("address:3", indexConfigurationSections[3].Path);
            Assert.Equal("address:4", indexConfigurationSections[4].Path);
            Assert.Equal("address:i", indexConfigurationSections[5].Path);
            Assert.Equal("address:j", indexConfigurationSections[6].Path);
            Assert.Equal("address:x", indexConfigurationSections[7].Path);
        }
开发者ID:leloulight,项目名称:Configuration,代码行数:32,代码来源:ArrayTests.cs

示例7: SerializeObject

        public object SerializeObject(ConfigurationBuilder serializerConfig, object obj)
        {
            var config = serializerConfig.Build();
            var sut = new JsonApiTransformer() { TransformationHelper = new TransformationHelper() };
            CompoundDocument result = sut.Transform(obj, new Context() { Configuration = config, RoutePrefix = _routePrefix });

            return result;
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:8,代码来源:JsonApiSerializer.cs

示例8: AddUserSecrets_Does_Not_Fail_On_Non_Existing_File

        public void AddUserSecrets_Does_Not_Fail_On_Non_Existing_File()
        {
            var projectPath = UserSecretHelper.GetTempSecretProject();

            var builder = new ConfigurationBuilder().SetBasePath(projectPath).AddUserSecrets();
            var configuration = builder.Build();
            Assert.Equal(null, configuration["Facebook:AppSecret"]);

            UserSecretHelper.DeleteTempSecretProject(projectPath);
        }
开发者ID:leloulight,项目名称:UserSecrets,代码行数:10,代码来源:ConfigurationExtensionTests.cs

示例9: CanReadStaticProperty

 public void CanReadStaticProperty()
 {
     var dic = new Dictionary<string, string>
     {
         {"StaticProperty", "stuff"},
     };
     var builder = new ConfigurationBuilder(new MemoryConfigurationSource(dic));
     var config = builder.Build();
     var options = ConfigurationBinder.Bind<ComplexOptions>(config);
     Assert.Equal("stuff", ComplexOptions.StaticProperty);
 }
开发者ID:rhwy,项目名称:Configuration,代码行数:11,代码来源:ConfigurationBinderTests.cs

示例10: Resource_creates_mapping

        public void Resource_creates_mapping()
        {
            //Arrange
            var builder = new ConfigurationBuilder();

            //Act
            builder.Resource<Post>();

            var result = builder.Build();

            //Assert
            result.IsMappingRegistered(typeof(Post)).ShouldBeTrue();
            result.GetMapping(typeof(Post)).ShouldNotBeNull();
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:14,代码来源:ConfigurationBuilderTest.cs

示例11: Resource_creates_mapping

        public void Resource_creates_mapping()
        {
            //Arrange
            var builder = new ConfigurationBuilder();

            //Act
            builder.Resource<Post, PostsController>();

            var result = builder.Build();

            //Assert
            Assert.True(result.IsMappingRegistered(typeof(Post)));
            Assert.NotNull(result.GetMapping(typeof(Post)));
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:14,代码来源:ConfigurationBuilderTest.cs

示例12: CanGetConfigurationSection

        public void CanGetConfigurationSection()
        {
            // Arrange
            var dic1 = new Dictionary<string, string>()
                {
                    {"Data:DB1:Connection1", "MemVal1"},
                    {"Data:DB1:Connection2", "MemVal2"}
                };
            var dic2 = new Dictionary<string, string>()
                {
                    {"DataSource:DB2:Connection", "MemVal3"}
                };
            var dic3 = new Dictionary<string, string>()
                {
                    {"Data", "MemVal4"}
                };
            var memConfigSrc1 = new MemoryConfigurationSource(dic1);
            var memConfigSrc2 = new MemoryConfigurationSource(dic2);
            var memConfigSrc3 = new MemoryConfigurationSource(dic3);

            var builder = new ConfigurationBuilder();
            builder.Add(memConfigSrc1, load: false);
            builder.Add(memConfigSrc2, load: false);
            builder.Add(memConfigSrc3, load: false);

            var config = builder.Build();

            string memVal1, memVal2, memVal3, memVal4, memVal5;

            // Act
            var configFocus = config.GetSection("Data");

            memVal1 = configFocus["DB1:Connection1"];
            memVal2 = configFocus["DB1:Connection2"];
            memVal3 = configFocus["DB2:Connection"];
            memVal4 = configFocus["Source:DB2:Connection"];
            memVal5 = configFocus.Value;

            // Assert
            Assert.Equal("MemVal1", memVal1);
            Assert.Equal("MemVal2", memVal2);
            Assert.Equal("MemVal4", memVal5);

            Assert.Equal("MemVal1", configFocus["DB1:Connection1"]);
            Assert.Equal("MemVal2", configFocus["DB1:Connection2"]);
            Assert.Null(configFocus["DB2:Connection"]);
            Assert.Null(configFocus["Source:DB2:Connection"]);
            Assert.Equal("MemVal4", configFocus.Value);
        }
开发者ID:pgrudzien12,项目名称:Configuration,代码行数:49,代码来源:ConfigurationTest.cs

示例13: CanReadComplexProperties

 public void CanReadComplexProperties()
 {
     var dic = new Dictionary<string, string>
     {
         {"Integer", "-2"},
         {"Boolean", "TRUe"},
         {"Nested:Integer", "11"}
     };
     var builder = new ConfigurationBuilder(new MemoryConfigurationSource(dic));
     var config = builder.Build();
     var options = ConfigurationBinder.Bind<ComplexOptions>(config);
     Assert.True(options.Boolean);
     Assert.Equal(-2, options.Integer);
     Assert.Equal(11, options.Nested.Integer);
 }
开发者ID:rhwy,项目名称:Configuration,代码行数:15,代码来源:ConfigurationBinderTests.cs

示例14: ExceptionIncludesKeyOfFailedBinding

        public void ExceptionIncludesKeyOfFailedBinding()
        {
            var input = new Dictionary<string, string>
            {
                {"NestedOptionsProperty:NestedOptions2Property:ISomeInterfaceProperty:subkey", "x"}
            };

            var builder = new ConfigurationBuilder(new MemoryConfigurationSource(input));
            var config = builder.Build();

            var exception = Assert.Throws<InvalidOperationException>(
                () => ConfigurationBinder.Bind<TestOptions>(config));
            Assert.Equal(
                Resources.FormatError_CannotActivateAbstractOrInterface(typeof(ISomeInterface)),
                exception.Message);
        }
开发者ID:rhwy,项目名称:Configuration,代码行数:16,代码来源:ConfigurationBinderTests.cs

示例15: AddUserSecrets_With_An_Existing_Secret_File

        public void AddUserSecrets_With_An_Existing_Secret_File()
        {
            string userSecretsId;
            var projectPath = UserSecretHelper.GetTempSecretProject(out userSecretsId);

            var logger = new TestLogger(_runtimeEnv);
            var secretManager = new Program(_runtimeEnv) { Logger = logger };

            secretManager.Main(new string[] { "set", "Facebook:AppSecret", "value1", "-p", projectPath });

            var builder = new ConfigurationBuilder().SetBasePath(projectPath).AddUserSecrets();
            var configuration = builder.Build();
            Assert.Equal("value1", configuration["Facebook:AppSecret"]);

            UserSecretHelper.DeleteTempSecretProject(projectPath);
        }
开发者ID:leloulight,项目名称:UserSecrets,代码行数:16,代码来源:ConfigurationExtensionTests.cs


注:本文中的ConfigurationBuilder.Build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。