public void All_interceptors_registered_in_DbConfiguration_are_added_when_the_config_is_locked() { var mockAppConfigChain = new Mock <ResolverChain>(); var mockNormalChain = new Mock <ResolverChain>(); var interceptor1 = new Mock <IDbInterceptor>().Object; var interceptor2 = new Mock <IDbInterceptor>().Object; mockNormalChain .Setup(m => m.GetServices(typeof(IDbInterceptor), null)) .Returns(new[] { interceptor1, interceptor2 }); var mockDispatchers = new Mock <DbDispatchers>(); var config = new InternalConfiguration( mockAppConfigChain.Object, mockNormalChain.Object, new RootDependencyResolver(), new Mock <AppConfigDependencyResolver>().Object, () => mockDispatchers.Object); config.Lock(); mockNormalChain.Verify(m => m.GetServices(typeof(IDbInterceptor), null)); mockDispatchers.Verify(m => m.AddInterceptor(interceptor1)); mockDispatchers.Verify(m => m.AddInterceptor(interceptor2)); }
public virtual void SetConfiguration(InternalConfiguration configuration) { DebugCheck.NotNull(configuration); var configurationType = _loader.TryLoadFromConfig(AppConfig.DefaultInstance); if (configurationType != null) { configuration = configurationType .CreateInstance <DbConfiguration>(Strings.CreateInstance_BadDbConfigurationType) .InternalConfiguration; } _newConfiguration = configuration.Owner; if (_configuration.Value.Owner.GetType() != configuration.Owner.GetType()) { if (_configuration.Value.Owner.GetType() == typeof(DbConfiguration)) { throw new InvalidOperationException(Strings.DefaultConfigurationUsedBeforeSet(configuration.Owner.GetType().Name)); } throw new InvalidOperationException( Strings.ConfigurationSetTwice(configuration.Owner.GetType().Name, _configuration.Value.Owner.GetType().Name)); } }
public AppConfigDependencyResolver( AppConfig appConfig, InternalConfiguration internalConfiguration, ProviderServicesFactory providerServicesFactory = null) { this._appConfig = appConfig; this._internalConfiguration = internalConfiguration; this._providerServicesFactory = providerServicesFactory ?? new ProviderServicesFactory(); }
public virtual void OnLoaded(InternalConfiguration configuration) { DbConfigurationLoadedEventArgs configurationLoadedEventArgs = new DbConfigurationLoadedEventArgs(configuration); EventHandler <DbConfigurationLoadedEventArgs> loadedHandler = this._loadedHandler; if (loadedHandler != null) { loadedHandler((object)configuration.Owner, configurationLoadedEventArgs); } configuration.DispatchLoadedInterceptors(configurationLoadedEventArgs); }
public virtual void OnLoaded(InternalConfiguration configuration) { DebugCheck.NotNull(configuration); var handler = _loadedHandler; if (handler != null) { handler(configuration.Owner, new DbConfigurationLoadedEventArgs(configuration)); } }
public AppConfigDependencyResolver( AppConfig appConfig, InternalConfiguration internalConfiguration, ProviderServicesFactory providerServicesFactory = null) { DebugCheck.NotNull(appConfig); _appConfig = appConfig; _internalConfiguration = internalConfiguration; _providerServicesFactory = providerServicesFactory ?? new ProviderServicesFactory(); }
public void RootResolver_returns_the_root_resolver() { var rootResolver = new RootDependencyResolver(); var config = new InternalConfiguration( new Mock <ResolverChain>().Object, new Mock <ResolverChain>().Object, rootResolver, new Mock <AppConfigDependencyResolver>().Object); Assert.Same(rootResolver, config.RootResolver); }
public void AddDefaultResolver_throws_if_the_configuation_is_locked() { var internalConfiguration = new InternalConfiguration(); internalConfiguration.Lock(); Assert.Equal( Strings.ConfigurationLocked("AddDefaultResolver"), Assert.Throws <InvalidOperationException>( () => new DbConfigurationLoadedEventArgs(internalConfiguration) .AddDefaultResolver(new Mock <IDbDependencyResolver>().Object)).Message); }
public void DependencyResolver_returns_the_dependency_resolver_in_use() { var mockAppConfigChain = new Mock <ResolverChain>(); var mockNormalChain = new Mock <ResolverChain>(); var config = new InternalConfiguration( mockAppConfigChain.Object, mockNormalChain.Object, new RootDependencyResolver(), new Mock <AppConfigDependencyResolver>().Object); var resolver = (CompositeResolver <ResolverChain, ResolverChain>)config.DependencyResolver; Assert.Same(mockAppConfigChain.Object, resolver.First); Assert.Same(mockNormalChain.Object, resolver.Second); }
public void All_interceptors_are_added_and_Loaded_interceptors_are_called_when_config_is_locked() { var mockAppConfigChain = new Mock <ResolverChain>(); var interceptor1 = new Mock <IDbInterceptor>().Object; var interceptor2 = new Mock <IDbConfigurationInterceptor>().Object; var mockNormalResolver = new Mock <IDbDependencyResolver>(); mockNormalResolver .Setup(m => m.GetServices(typeof(IDbInterceptor), null)) .Returns(new[] { interceptor1, interceptor2 }); var normalChain = new ResolverChain(); normalChain.Add(mockNormalResolver.Object); var interceptor3 = new Mock <IDbConfigurationInterceptor>().Object; var mockLoadedResolver = new Mock <IDbDependencyResolver>(); mockLoadedResolver .Setup(m => m.GetServices(typeof(IDbInterceptor), null)) .Returns(new[] { interceptor3 }); var mockDispatchers = new Mock <DbDispatchers>(); var mockDispatcher = new Mock <DbConfigurationDispatcher>(); mockDispatchers.Setup(m => m.Configuration).Returns(mockDispatcher.Object); mockDispatcher .Setup(m => m.Loaded(It.IsAny <DbConfigurationLoadedEventArgs>(), It.IsAny <DbInterceptionContext>())) .Callback <DbConfigurationLoadedEventArgs, DbInterceptionContext>( (a, _) => a.AddDependencyResolver(mockLoadedResolver.Object, false)); var config = new InternalConfiguration( mockAppConfigChain.Object, normalChain, new RootDependencyResolver(), new Mock <AppConfigDependencyResolver>().Object, () => mockDispatchers.Object); config.Lock(); mockNormalResolver.Verify(m => m.GetServices(typeof(IDbInterceptor), null), Times.Exactly(2)); mockLoadedResolver.Verify(m => m.GetServices(typeof(IDbInterceptor), null), Times.Once()); mockDispatchers.Verify(m => m.AddInterceptor(interceptor1), Times.Once()); mockDispatchers.Verify(m => m.AddInterceptor(interceptor2), Times.Once()); mockDispatchers.Verify(m => m.AddInterceptor(interceptor3), Times.Once()); mockDispatcher.Verify( m => m.Loaded(It.IsAny <DbConfigurationLoadedEventArgs>(), It.IsAny <DbInterceptionContext>())); }
public virtual void OnLoaded(InternalConfiguration configuration) { DebugCheck.NotNull(configuration); var eventArgs = new DbConfigurationLoadedEventArgs(configuration); var handler = _loadedHandler; if (handler != null) { handler(configuration.Owner, eventArgs); } configuration.DispatchLoadedInterceptors(eventArgs); }
public virtual void OnLoaded(InternalConfiguration configuration) { DebugCheck.NotNull(configuration); var eventArgs = new DbConfigurationLoadedEventArgs(configuration); var handler = _loadedHandler; if (handler != null) { handler(configuration.Owner, eventArgs); } foreach (var handlerFromConfigFile in configuration.OnLoadedHandlers) { handlerFromConfigFile(configuration.Owner, eventArgs); } }
public virtual void SetConfiguration(InternalConfiguration configuration) { Type type = this._loader.TryLoadFromConfig(AppConfig.DefaultInstance); if (type != (Type)null) { configuration = type.CreateInstance <DbConfiguration>(new Func <string, string, string>(Strings.CreateInstance_BadDbConfigurationType), (Func <string, Exception>)null).InternalConfiguration; } this._newConfiguration = configuration.Owner; if (!(this._configuration.Value.Owner.GetType() != configuration.Owner.GetType())) { return; } if (this._configuration.Value.Owner.GetType() == typeof(DbConfiguration)) { throw new InvalidOperationException(Strings.DefaultConfigurationUsedBeforeSet((object)configuration.Owner.GetType().Name)); } throw new InvalidOperationException(Strings.ConfigurationSetTwice((object)configuration.Owner.GetType().Name, (object)this._configuration.Value.Owner.GetType().Name)); }
public virtual bool PushConfiguration(AppConfig config, Type contextType) { if (config == AppConfig.DefaultInstance && (contextType == typeof(DbContext) || this._knownAssemblies.ContainsKey(contextType.Assembly()))) { return(false); } Type type = this._loader.TryLoadFromConfig(config); if ((object)type == null) { Type configurationType = this._finder.TryFindConfigurationType(contextType, (IEnumerable <Type>)null); type = (object)configurationType != null ? configurationType : typeof(DbConfiguration); } InternalConfiguration internalConfiguration = type.CreateInstance <DbConfiguration>(new Func <string, string, string>(Strings.CreateInstance_BadDbConfigurationType), (Func <string, Exception>)null).InternalConfiguration; internalConfiguration.SwitchInRootResolver(this._configuration.Value.RootResolver); internalConfiguration.AddAppConfigResolver((IDbDependencyResolver) new AppConfigDependencyResolver(config, internalConfiguration, (ProviderServicesFactory)null)); lock (this._lock) this._configurationOverrides.Value.Add(Tuple.Create <AppConfig, InternalConfiguration>(config, internalConfiguration)); internalConfiguration.Lock(); return(true); }
private static void AssertIsLocked(InternalConfiguration internalConfiguration) { Assert.Throws <InvalidOperationException>(() => internalConfiguration.CheckNotLocked("Foo")); }
internal DbConfigurationLoadedEventArgs(InternalConfiguration configuration) { this._internalConfiguration = configuration; }
private static void AssertIsNotLocked(InternalConfiguration internalConfiguration) { internalConfiguration.CheckNotLocked("Foo"); }
internal DbConfigurationLoadedEventArgs(InternalConfiguration configuration) { DebugCheck.NotNull(configuration); _internalConfiguration = configuration; }
private static void AssertIsNotLocked(InternalConfiguration internalConfiguration) { Assert.DoesNotThrow(() => internalConfiguration.CheckNotLocked("Foo")); }