public void CanCreatePrivateNestedClass()
        {
            var container = new InjectContainer();
            var instance  = container.Resolve <PrivateClass>();

            Assert.NotNull(instance);
        }
        public void CanResolveConcreteClassWithoutRegistering()
        {
            var container = new InjectContainer();
            var instance  = container.Resolve <Class1>();

            Assert.NotNull(instance);
        }
        public void CanCreateOnePublicConstructorClassWithMultiPrivateConstructors()
        {
            var container = new InjectContainer();
            var instance  = container.Resolve <MultiplePrivateOnePublicConstructorClass>();

            Assert.NotNull(instance);
        }
        public void CreatingNoPublicConstructorClassThrows()
        {
            var container = new InjectContainer();

            var exception = Record.Exception(() => container.Resolve <NoConstructorClass>());

            Assert.IsType <ResolutionFailedException>(exception);
        }
        public void ResolveNonConcreteTypeThrows()
        {
            var container = new InjectContainer();

            var exception = Record.Exception(() => container.Resolve <IInterface1>());

            Assert.IsType <ResolutionFailedException>(exception);
        }
        public void ResolveAbstractTypeThrows()
        {
            var container = new InjectContainer();

            var exception = Record.Exception(() => container.Resolve <AbstractClass1>());

            Assert.IsType <ResolutionFailedException>(exception);
        }
        public void RegisterNullTypeThrows()
        {
            var container = new InjectContainer();

            var exception = Record.Exception(() => container.Register(null !, typeof(object)));

            Assert.IsType <ArgumentNullException>(exception);
        }
        public void ResolveNullTypeThrows()
        {
            var container = new InjectContainer();

            var exception = Record.Exception(() => container.Resolve(null !));

            Assert.IsType <ArgumentNullException>(exception);
        }
        public void RegisteredInstanceDoesntInheritThrows()
        {
            var container = new InjectContainer();

            var exception = Record.Exception(() => container.Register(typeof(IInterface1), new Class2()));

            Assert.IsType <ArgumentException>(exception);
        }
        public void RegisterInstanceNullThrows()
        {
            var container = new InjectContainer();

            var exception = Record.Exception(() => container.Register(null !, new object()));

            Assert.IsType <ArgumentNullException>(exception);
        }
        public void RegisterInstanceWithNullInstanceThrows()
        {
            var container = new InjectContainer();

            var exception = Record.Exception(() => container.Register <object>(null));

            Assert.IsType <ArgumentNullException>(exception);
        }
        public void CanCreateConcreteArgumentClass()
        {
            var container = new InjectContainer();
            var instance  = container.Resolve <ConcreteParameterClass>();

            Assert.NotNull(instance);
            Assert.NotNull(instance.Arg);
        }
        public void ResolveStaticTypeThrows()
        {
            var container = new InjectContainer();

            var exception = Record.Exception(() => container.Resolve(typeof(StaticClass)));

            Assert.IsType <ResolutionFailedException>(exception);
        }
        public void RegisterSameTypeThrows()
        {
            var container = new InjectContainer();

            container.Register <IInterface1, Class1>();

            var exception = Record.Exception(() => container.Register <IInterface1, Class1>());

            Assert.IsType <ArgumentException>(exception);
        }
        public void ExceptionInConstructorThrowsInnerException()
        {
            var container = new InjectContainer();

            var exception = Record.Exception(() => container.Resolve <ConstructorExceptionClass>());

            Assert.NotNull(exception);
            Assert.NotNull(exception.InnerException);
            Assert.IsType <InvalidOperationException>(exception.InnerException);
        }
        public void CannotResolveInterface()
        {
            var container = new InjectContainer();

            container.Register <IInterface1, IInherited1>();

            var exception = Record.Exception(() => container.Resolve <IInterface1>());

            Assert.IsType <ResolutionFailedException>(exception);
        }
        public void CannotResolveAbstractClass()
        {
            var container = new InjectContainer();

            container.Register <IInterface1, AbstractClass1>();

            var exception = Record.Exception(() => container.Resolve <AbstractClass1>());

            Assert.IsType <ResolutionFailedException>(exception);
        }
        public void CanRegisterTypeAsSingleton()
        {
            var container = new InjectContainer();

            container.Register <IInterface1, Class1>();

            var instance1 = container.Resolve <IInterface1>();
            var instance2 = container.Resolve <IInterface1>();

            Assert.Same(instance1, instance2);
        }
        public void ResolveCircularReferenceThrows()
        {
            var container = new InjectContainer();

            container.Register <IInterface1, CircularReference1>();
            container.Register <IInterface2, CircularReference2>();

            var exception = Record.Exception(() => container.Resolve <IInterface1>());

            Assert.IsType <ResolutionFailedException>(exception);
        }
        public void ResolvesConstructorParameters()
        {
            var container = new InjectContainer();

            container.Register <IInterfaceWithProperty, Class1WithProperty>();
            container.Register <IInterface2, Class2>();

            var instance = container.Resolve <IInterfaceWithProperty>();

            Assert.NotNull(instance);
            Assert.NotNull(instance.Arg);
        }
        public void ResolvesInstanceAsSingleton()
        {
            var container = new InjectContainer();

            var instance = new Class1();

            container.Register <IInterface1>(instance);

            var instance1 = container.Resolve <IInterface1>();
            var instance2 = container.Resolve <IInterface1>();

            Assert.Same(instance, instance1);
            Assert.Same(instance, instance2);
        }