public void Can_Create_Container() { using (var container = new NancyContainer()) { container.ShouldNotBeNull(); } }
public void Cannot_Resolve_Interface_That_Was_Not_Registered() { using (var c = new NancyContainer()) { var foo = c.Resolve(typeof(IFoo)); foo.ShouldBeNull(); } }
public void Can_Resolve_Concrete_Type_That_Was_Not_Registered() { using (var c = new NancyContainer()) { var foo = c.Resolve(typeof(Foo)); foo.ShouldNotBeNull(); foo.ShouldBeOfType<Foo>(); } }
public void Can_Register_And_Resolve_Multiple_Types() { using (var container = new NancyContainer()) { container.Register(typeof(IBar), c => new Bar()); container.Register(typeof(IFoo), c => new Foo()); var foo = container.Resolve(null, typeof(IFoo)); var bar = container.Resolve(null, typeof(IBar)); } }
public void Can_Resolve_Unamed_Instance() { using (var c = new NancyContainer()) { var originalFoo = new Foo(); c.Register(typeof(IFoo), originalFoo); var foo = c.Resolve(typeof(IFoo)); foo.ShouldNotBeNull(); foo.ShouldBeSameAs(originalFoo); } }
public void Can_Resolve_Unnamed_Type() { using (var c = new NancyContainer()) { c.Register(typeof(IFoo), typeof(Foo)); var foo = c.Resolve(typeof(IFoo)); foo.ShouldNotBeNull(); foo.ShouldBeOfType<IFoo>(); foo.ShouldBeOfType<Foo>(); } }
public void Can_Resolve_Nameless_NonGeneric_Factory() { using (var container = new NancyContainer()) { container.Register(typeof(IFoo), c => new Foo()); var foo = container.Resolve(null, typeof(IFoo)); foo.ShouldNotBeNull(); foo.ShouldBeOfType<IFoo>(); foo.ShouldBeOfType<Foo>(); } }
public void Can_Resolve_IEnumerable_Of_Services() { using (var c = new NancyContainer()) { c.Register(typeof(IFoo), typeof(Foo)); c.Register(typeof(IFoo), typeof(Foo2)); var fooEnum = c.Resolve(typeof(IEnumerable<IFoo>)); fooEnum.ShouldNotBeNull(); fooEnum.ShouldBeOfType(typeof(IEnumerable<IFoo>)); var foo = (IEnumerable<IFoo>)fooEnum; foo.Count().ShouldEqual(2); } }
public void Can_Resolve_Array_Of_Services() { using (var c = new NancyContainer()) { c.Register(typeof(IFoo), typeof(Foo)); c.Register(typeof(IFoo), typeof(Foo2)); var fooArray = c.Resolve(typeof(IFoo[])); fooArray.ShouldNotBeNull(); fooArray.ShouldBeOfType(typeof(IFoo[])); var foo = (IFoo[])fooArray; foo.Length.ShouldEqual(2); } }
public void Can_Resolve_Func_Of_Registered_Service() { using (var c = new NancyContainer()) { c.Register(typeof(IFoo), container => new Foo()); var fooFunc = c.Resolve(typeof(Func<IFoo>)); fooFunc.ShouldNotBeNull(); fooFunc.ShouldBeOfType(typeof(Func<IFoo>)); var fooResult = ((Func<IFoo>)fooFunc)(); fooResult.ShouldNotBeNull(); fooResult.ShouldBeOfType<IFoo>(); fooResult.ShouldBeOfType<Foo>(); } }
public void Can_Resolve_Unnamed_Type_With_Dependencies() { using (var c = new NancyContainer()) { c.Register(typeof(IFoo), container => new Foo()); c.Register(typeof(IBar), typeof(FooBar)); var fooBar = c.Resolve(typeof(IBar)) as FooBar; fooBar.ShouldNotBeNull(); fooBar.Foo.ShouldNotBeNull(); } }
public void WhenResolve_Is_Called_For_Strong_Factory_Strong_Object_Is_Returned() { using (var container = new NancyContainer()) { container.Register<IFoo>(c => new Foo()); var foo = container.Resolve<IFoo>(); foo.ShouldNotBeNull(); foo.ShouldBeOfType<IFoo>(); foo.ShouldBeOfType<Foo>(); } }
public void Resolve_With_Singleton_Scope_Returns_Same_Instance() { using (var c = new NancyContainer()) { c.Register(string.Empty, typeof(IFoo), container => new Foo()).WithinScope(new SingletonScope()); var foo1 = c.Resolve(typeof(IFoo)); var foo2 = c.Resolve(typeof(IFoo)); foo1.ShouldNotBeNull(); foo1.ShouldBeOfType<Foo>(); foo2.ShouldNotBeNull(); foo2.ShouldBeOfType<Foo>(); foo1.ShouldBeSameAs(foo2); } }
public void Resolve_Without_Name_Returns_Named_Instance() { using (var container = new NancyContainer()) { container.Register("foo1", typeof(IFoo), c => new Foo()); var foo = container.Resolve(typeof(IFoo)); foo.ShouldNotBeNull(); foo.ShouldBeOfType<IFoo>(); foo.ShouldBeOfType<Foo>(); } }
public void Last_Registered_Instance_Is_Resolved() { using (var container = new NancyContainer()) { container.Register(typeof(IFoo), c => new Foo()); container.Register(typeof(IFoo), c => new Foo2()); var foo = container.Resolve(typeof(IFoo)); foo.ShouldNotBeNull(); foo.ShouldBeOfType<IFoo>(); foo.ShouldBeOfType<Foo2>(); } }
public void Different_Named_Registrations_Resolve_To_Different_Types() { using (var container = new NancyContainer()) { container.Register("foo1", typeof(IFoo), c => new Foo()); container.Register("foo2", typeof(IFoo), c => new Foo2()); var foo1 = container.Resolve("foo1", typeof(IFoo)); var foo2 = container.Resolve("foo2", typeof(IFoo)); foo1.ShouldNotBeNull(); foo1.ShouldBeOfType<Foo>(); foo2.ShouldNotBeNull(); foo2.ShouldBeOfType<Foo2>(); } }