public static DbAccessor CreateDbAccessor(string name) { var connectionString = MyConfiguration.Get().GetConnectionString(name); var providerName = MyConfiguration.Get().GetConnectionStringProviderName(name); if (string.IsNullOrEmpty(connectionString)) { throw new Exception(string.Format("请检查配置文件的数据库连接配置,找不到名称为{0}的ConnectionString!", name)); } return(CreateDbAccessor(connectionString, providerName)); }
public void ReadMyConfiguration() { IMyConfiguration configuration = MyConfiguration.Get(); Assert.Equal(25, configuration.Age); Assert.Equal("Name", configuration.Name); Assert.Equal(DayOfWeek.Monday, configuration.DayOfBirth); Assert.Equal(3, configuration.MyStrings.Count()); Assert.Equal("Value1", configuration.MyStrings.ElementAt(0)); Assert.Equal("Value2", configuration.MyStrings.ElementAt(1)); Assert.Equal("Value3", configuration.MyStrings.ElementAt(2)); Assert.Equal(2, configuration.MyConnections.Count); Assert.Equal("Server1", configuration.MyConnections[0].Server); Assert.Equal(80, configuration.MyConnections[0].Port); Assert.Equal("Server2", configuration.MyConnections[1].Server); Assert.Equal(88, configuration.MyConnections[1].Port); }