Exemplo n.º 1
0
        public void TryLoadFromConfig_throws_if_type_cannot_be_loaded()
        {
            var mockConfig = new Mock<AppConfig>(new ConnectionStringSettingsCollection());
            mockConfig.Setup(m => m.ConfigurationTypeName).Returns("I.Is.Not.A.Type");

            var loader = new DbConfigurationLoader();
            Assert.Equal(
                Strings.DbConfigurationTypeNotFound("I.Is.Not.A.Type"),
                Assert.Throws<InvalidOperationException>(() => loader.TryLoadFromConfig(mockConfig.Object)).Message);
        }
Exemplo n.º 2
0
        public void TryLoadFromConfig_throws_if_type_does_not_extend_DbConfiguration()
        {
            var mockConfig = new Mock<AppConfig>(new ConnectionStringSettingsCollection());
            mockConfig.Setup(m => m.ConfigurationTypeName).Returns(typeof(Random).AssemblyQualifiedName);

            var loader = new DbConfigurationLoader();
            Assert.Equal(
                Strings.CreateInstance_BadDbConfigurationType(typeof(Random).ToString(), typeof(DbConfiguration).ToString()),
                Assert.Throws<InvalidOperationException>(() => loader.TryLoadFromConfig(mockConfig.Object)).Message);
        }
Exemplo n.º 3
0
 public DbConfigurationManager(DbConfigurationLoader loader, DbConfigurationFinder finder)
 {
     this._loader        = loader;
     this._finder        = finder;
     this._configuration = new Lazy <InternalConfiguration>((Func <InternalConfiguration>)(() =>
     {
         DbConfiguration dbConfiguration = this._newConfiguration ?? this._newConfigurationType.CreateInstance <DbConfiguration>(new Func <string, string, string>(Strings.CreateInstance_BadDbConfigurationType), (Func <string, Exception>)null);
         dbConfiguration.InternalConfiguration.Lock();
         return(dbConfiguration.InternalConfiguration);
     }));
 }
Exemplo n.º 4
0
        public void TryLoadFromConfig_throws_if_type_does_not_extend_DbConfiguration()
        {
            var mockConfig = new Mock <AppConfig>(new ConnectionStringSettingsCollection());

            mockConfig.Setup(m => m.ConfigurationTypeName).Returns(typeof(Random).AssemblyQualifiedName);

            var loader = new DbConfigurationLoader();

            Assert.Equal(
                Strings.CreateInstance_BadDbConfigurationType(typeof(Random).ToString(), typeof(DbConfiguration).ToString()),
                Assert.Throws <InvalidOperationException>(() => loader.TryLoadFromConfig(mockConfig.Object)).Message);
        }
Exemplo n.º 5
0
        public void TryLoadFromConfig_throws_if_type_cannot_be_loaded()
        {
            var mockConfig = new Mock <AppConfig>(new ConnectionStringSettingsCollection());

            mockConfig.Setup(m => m.ConfigurationTypeName).Returns("I.Is.Not.A.Type");

            var loader = new DbConfigurationLoader();

            Assert.Equal(
                Strings.DbConfigurationTypeNotFound("I.Is.Not.A.Type"),
                Assert.Throws <InvalidOperationException>(() => loader.TryLoadFromConfig(mockConfig.Object)).Message);
        }
        public DbConfigurationManager(DbConfigurationLoader loader, DbConfigurationFinder finder)
        {
            DebugCheck.NotNull(loader);
            DebugCheck.NotNull(finder);

            _loader        = loader;
            _finder        = finder;
            _configuration = new Lazy <InternalConfiguration>(
                () =>
            {
                var configuration = _newConfiguration
                                    ?? _newConfigurationType.CreateInstance <DbConfiguration>(
                    Strings.CreateInstance_BadDbConfigurationType);
                configuration.InternalConfiguration.Lock();
                return(configuration.InternalConfiguration);
            });
        }
        public DbConfigurationManager(DbConfigurationLoader loader, DbConfigurationFinder finder)
        {
            DebugCheck.NotNull(loader);
            DebugCheck.NotNull(finder);

            _loader = loader;
            _finder = finder;
            _configuration = new Lazy<InternalConfiguration>(
                () =>
                    {
                        var configuration = _newConfiguration
                                            ?? _newConfigurationType.CreateInstance<DbConfiguration>(
                                                Strings.CreateInstance_BadDbConfigurationType);
                        configuration.InternalConfiguration.Lock();
                        return configuration.InternalConfiguration;
                    });
        }
Exemplo n.º 8
0
        public DbConfigurationManager(DbConfigurationLoader loader, DbConfigurationFinder finder)
        {
            DebugCheck.NotNull(loader);
            DebugCheck.NotNull(finder);

            _loader        = loader;
            _finder        = finder;
            _configuration = new Lazy <InternalConfiguration>(
                () =>
            {
                var configuration = _newConfiguration
                                    ?? _newConfigurationType.CreateInstance <DbConfiguration>(
                    Strings.CreateInstance_BadDbConfigurationType);

                foreach (var handler in _loader.GetOnLoadedHandlers(AppConfig.DefaultInstance))
                {
                    configuration.InternalConfiguration.AddOnLoadedHandler(handler);
                }

                configuration.InternalConfiguration.Lock();
                return(configuration.InternalConfiguration);
            });
        }