public string GetConnectionString()
        {
            var adminConnectionString = AdminConnectionString();

            if (string.IsNullOrEmpty(adminConnectionString))
            {
                throw new ArgumentException($"No connection string named '{ConnectionStringName}' was found in the 'connectionStrings' section of the application configuration file.");
            }

            var connectionStringBuilder = _connectionStringBuilderFactory.Get();

            connectionStringBuilder.ConnectionString = adminConnectionString;

            // Override the Database Name, format if string coming in has a format replacement token,
            // otherwise use database name set in the Initial Catalog.
            connectionStringBuilder.DatabaseName = connectionStringBuilder.DatabaseName.IsFormatString()
                ? string.Format(
                connectionStringBuilder.DatabaseName,
                _adminDatabaseNameReplacementTokenProvider.GetReplacementToken())
                : connectionStringBuilder.DatabaseName;

            return(connectionStringBuilder.ConnectionString);

            string AdminConnectionString()
            {
                if (_configConnectionStringsProvider.Count == 0)
                {
                    throw new ArgumentException("No connection strings were found in the configuration file.");
                }

                return(_configConnectionStringsProvider.GetConnectionString(ConnectionStringName));
            }
        }
예제 #2
0
        protected override void Arrange()
        {
            // Set up mocked dependencies and supplied values
            _adminDatabaseNameReplacementTokenProvider = A.Fake <IAdminDatabaseNameReplacementTokenProvider>();

            A.CallTo(() => _adminDatabaseNameReplacementTokenProvider.GetReplacementToken()).Returns("OneDatabase").Once();

            A.CallTo(() => _adminDatabaseNameReplacementTokenProvider.GetReplacementToken()).Returns("AnotherDatabase").Once();

            A.CallTo(() => _adminDatabaseNameReplacementTokenProvider.GetReplacementToken()).Returns("OneDatabase").Once();

            _configConnectionStringsProvider = A.Fake <IConfigConnectionStringsProvider>();

            A.CallTo(() => _configConnectionStringsProvider.Count).Returns(1);

            A.CallTo(() => _configConnectionStringsProvider.GetConnectionString("EdFi_Admin"))
            .Returns("Server=SomeServer; Database=EdFi_{0}; UID=SomeUser; Password=SomePassword");

            _dbConnectionStringBuilderAdapterFactory = A.Fake <IDbConnectionStringBuilderAdapterFactory>();

            A.CallTo(() => _dbConnectionStringBuilderAdapterFactory.Get()).Returns(new SqlConnectionStringBuilderAdapter());
        }
예제 #3
0
 protected override void Act()
 {
     _adminDatabaseNameReplacementTokenProvider.GetReplacementToken();
 }