public DbConfigurationManager(DbConfigurationLoader loader, DbConfigurationFinder finder)
        {
            Contract.Requires(loader != null);
            Contract.Requires(finder != null);

            _loader = loader;
            _finder = finder;
        }
        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);
        }
        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 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);
        }
        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);
        }
예제 #6
0
        public DbConfigurationManager(DbConfigurationLoader loader, DbConfigurationFinder finder)
        {
            DebugCheck.NotNull(loader);
            DebugCheck.NotNull(finder);

            _loader        = loader;
            _finder        = finder;
            _configuration = new Lazy <InternalConfiguration>(
                () =>
            {
                _newConfiguration.InternalConfiguration.Lock();
                return(_newConfiguration.InternalConfiguration);
            });
        }
        public DbConfigurationManager(DbConfigurationLoader loader, DbConfigurationFinder finder)
        {
            //Contract.Requires(loader != null);
            //Contract.Requires(finder != null);

            _loader = loader;
            _finder = finder;
            _configuration = new Lazy<DbConfiguration>(
                () =>
                    {
                        _newConfiguration.Lock();
                        return _newConfiguration;
                    });
        }
예제 #8
0
        public DbConfigurationManager(DbConfigurationLoader loader, DbConfigurationFinder finder)
        {
            DebugCheck.NotNull(loader);
            DebugCheck.NotNull(finder);

            _loader = loader;
            _finder = finder;
            _configuration = new Lazy<InternalConfiguration>(
                () =>
                    {
                        _newConfiguration.InternalConfiguration.Lock();
                        return _newConfiguration.InternalConfiguration;
                    });
        }
예제 #9
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);
                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;
                    });
        }