public void GenericTests_CanResolve() { using var container = new StashboxContainer(); container.Register(typeof(ITest1 <,>), typeof(Test1 <,>)); Assert.True(container.CanResolve(typeof(ITest1 <,>))); Assert.True(container.CanResolve(typeof(ITest1 <int, int>))); }
public void ContainerExtensionTests_AddSignalR() { var container = new StashboxContainer().AddSignalR(); Assert.IsInstanceOfType(GlobalHost.DependencyResolver, typeof(StashboxDependencyResolver)); Assert.IsTrue(container.CanResolve <Microsoft.AspNet.SignalR.IDependencyResolver>()); Assert.IsTrue(container.CanResolve <IHubActivator>()); }
public void ContainerExtensionTests_AddSignalR_WithTypes() { var container = new StashboxContainer().AddSignalRWithTypes(typeof(TestHub), typeof(TestConnection)); Assert.IsTrue(container.CanResolve <TestHub>()); Assert.IsTrue(container.CanResolve <Hub>()); Assert.IsTrue(container.CanResolve <IHub>()); Assert.IsTrue(container.CanResolve <TestConnection>()); Assert.IsTrue(container.CanResolve <PersistentConnection>()); }
public void ContainerTests_CanResolve() { var container = new StashboxContainer(); container.RegisterType <ITest1, Test1>(); container.RegisterType <ITest2, Test2>(); var child = container.CreateChildContainer(); Assert.IsTrue(container.CanResolve <ITest1>()); Assert.IsTrue(container.CanResolve(typeof(ITest2))); Assert.IsTrue(container.CanResolve <IEnumerable <ITest2> >()); Assert.IsTrue(container.CanResolve <Lazy <ITest2> >()); Assert.IsTrue(container.CanResolve <Func <ITest2> >()); Assert.IsTrue(container.CanResolve <Tuple <ITest2> >()); Assert.IsTrue(child.CanResolve <ITest1>()); Assert.IsTrue(child.CanResolve(typeof(ITest2))); Assert.IsTrue(child.CanResolve <IEnumerable <ITest2> >()); Assert.IsTrue(child.CanResolve <Lazy <ITest2> >()); Assert.IsTrue(child.CanResolve <Func <ITest2> >()); Assert.IsTrue(child.CanResolve <Tuple <ITest2> >()); Assert.IsFalse(container.CanResolve <ITest3>()); Assert.IsFalse(container.CanResolve <ITest1>("test")); Assert.IsFalse(container.CanResolve(typeof(ITest1), "test")); }
public void ContainerTests_Throws_Disposed_Exceptions() { var container = new StashboxContainer(); container.Dispose(); Assert.Throws <ObjectDisposedException>(() => container.Activate(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.BeginScope()); Assert.Throws <ObjectDisposedException>(() => container.BuildUp(new object())); Assert.Throws <ObjectDisposedException>(() => container.CanResolve(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.ComposeAssemblies(new[] { this.GetType().GetTypeInfo().Assembly })); Assert.Throws <ObjectDisposedException>(() => container.ComposeAssembly(this.GetType().GetTypeInfo().Assembly)); Assert.Throws <ObjectDisposedException>(() => container.ComposeBy(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.Configure(c => { })); Assert.Throws <ObjectDisposedException>(() => container.CreateChildContainer()); Assert.Throws <ObjectDisposedException>(() => container.GetRegistrationMappings()); #if HAS_SERVICEPROVIDER Assert.Throws <ObjectDisposedException>(() => container.GetService(this.GetType())); #endif Assert.Throws <ObjectDisposedException>(() => container.IsRegistered(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.PutInstanceInScope(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.Register(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.RegisterAssemblies(new[] { this.GetType().GetTypeInfo().Assembly })); Assert.Throws <ObjectDisposedException>(() => container.RegisterAssembly(this.GetType().GetTypeInfo().Assembly)); Assert.Throws <ObjectDisposedException>(() => container.RegisterAssemblyContaining <ITest1>()); Assert.Throws <ObjectDisposedException>(() => container.RegisterDecorator(this.GetType(), this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.RegisterFunc <ITest1>(r => new Test1())); Assert.Throws <ObjectDisposedException>(() => container.RegisterInstance(new object())); Assert.Throws <ObjectDisposedException>(() => container.RegisterInstances(new object())); Assert.Throws <ObjectDisposedException>(() => container.RegisterResolver(null)); Assert.Throws <ObjectDisposedException>(() => container.RegisterScoped <ITest1, Test1>()); Assert.Throws <ObjectDisposedException>(() => container.RegisterSingleton <ITest1, Test1>()); Assert.Throws <ObjectDisposedException>(() => container.RegisterTypes(new [] { this.GetType() })); Assert.Throws <ObjectDisposedException>(() => container.RegisterTypesAs <ITest1>(this.GetType().GetTypeInfo().Assembly)); Assert.Throws <ObjectDisposedException>(() => container.ReMap <ITest1, Test1>()); Assert.Throws <ObjectDisposedException>(() => container.ReMapDecorator(this.GetType(), this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.Resolve(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.ResolveAll(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.ResolveFactory(this.GetType())); Assert.Throws <ObjectDisposedException>(() => container.Validate()); Assert.Throws <ObjectDisposedException>(() => container.WireUp(new object())); }