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 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); }
public void CanCreateOnePublicConstructorClassWithMultiPrivateConstructors() { var container = new InjectContainer(); var instance = container.Resolve <MultiplePrivateOnePublicConstructorClass>(); Assert.NotNull(instance); }
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 ResolveNonConcreteTypeThrows() { var container = new InjectContainer(); var exception = Record.Exception(() => container.Resolve <IInterface1>()); Assert.IsType <ResolutionFailedException>(exception); }
public void CanCreateConcreteArgumentClass() { var container = new InjectContainer(); var instance = container.Resolve <ConcreteParameterClass>(); Assert.NotNull(instance); Assert.NotNull(instance.Arg); }
public void CreatingNoPublicConstructorClassThrows() { var container = new InjectContainer(); var exception = Record.Exception(() => container.Resolve <NoConstructorClass>()); Assert.IsType <ResolutionFailedException>(exception); }
public void ResolveStaticTypeThrows() { var container = new InjectContainer(); var exception = Record.Exception(() => container.Resolve(typeof(StaticClass))); Assert.IsType <ResolutionFailedException>(exception); }
public void ResolveAbstractTypeThrows() { var container = new InjectContainer(); var exception = Record.Exception(() => container.Resolve <AbstractClass1>()); Assert.IsType <ResolutionFailedException>(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 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); }