public void When_type_not_registerd_IsRegistered_returns_false() { var container = new AcrylicContainer(); container.Register <BaseClass, ConcreteClass>(); container.Register <ITextStream, TextStream>(); Assert.False(container.IsRegistered(typeof(ICalculator))); }
public void Resolve_provides_dependencies_for_registered_constructor_parameters() { IContainer container = new AcrylicContainer(); container.Register <ViewController, ViewController>(Lifetime.Transient); container.Register <ICalculator, Calculator>(); container.Register <IEmail, EmailService>(Lifetime.Singleton); ViewController instance = container.Resolve <ViewController>(); Assert.NotNull(instance); Assert.IsType <ViewController>(instance); Assert.NotNull(instance.Calculator); Assert.NotNull(instance.EmailService); }
public void Container_allows_type_registration_multiple_times_last_is_winner() { //There is a choice here to throw or to overwrite existing registration //Need to pick one way of the other. This test is just a declaration of //that choice and since it is somewhat passive agressive behavior //if the something changes the test will fail. var container = new AcrylicContainer(); container.Register <ITextStream, TextStream>(); container.Register <ITextStream, AsciiStream>(); var instance = container.Resolve <ITextStream>(); Assert.IsType <AsciiStream>(instance); }
public void Container_allows_type_registration_of_Generic() { var container = new AcrylicContainer(); container.Register <IList <string>, List <string> >(); Assert.True(container.IsRegistered(typeof(IList <string>))); }
public void Container_allows_type_registration_of_abstract_class() { var container = new AcrylicContainer(); container.Register <BaseClass, ConcreteClass>(); Assert.True(container.IsRegistered(typeof(BaseClass))); }
public void Container_allows_type_registration() { var container = new AcrylicContainer(); container.Register <ITextStream, TextStream>(); Assert.True(container.IsRegistered(typeof(ITextStream))); }
public void Container_allows_registration_an_instance() { var instance = new ConcreteClass(); var container = new AcrylicContainer(); container.Register <BaseClass>(instance); Assert.True(container.IsRegistered(typeof(BaseClass))); }
public void Resolve_returns_different_instance_for_each_invocation_when_DefaultLifetime() { IContainer container = new AcrylicContainer(); container.Register <ICalculator, Calculator>(); var instance1 = container.Resolve <ICalculator>(); var instance2 = container.Resolve <ICalculator>(); Assert.NotNull(instance1); Assert.NotNull(instance2); Assert.NotSame(instance1, instance2); }
public void Resolve_returns_singleton_instance_for_each_invocation_when_SingletonLifetime() { IContainer container = new AcrylicContainer(); container.Register <ICalculator, Calculator>(Lifetime.Singleton); var instance1 = container.Resolve <ICalculator>(); var instance2 = container.Resolve <ICalculator>(); Assert.NotNull(instance1); Assert.NotNull(instance2); Assert.Same(instance1, instance2); }
public void GetService_returns_singleton_instance_for_each_invocation_when_SingletonLifetime() { IContainer container = new AcrylicContainer(); container.Register <ICalculator, Calculator>(Lifetime.Singleton); IServiceProvider servieProvider = new AcrylicServiceProvider(container); var instance1 = servieProvider.GetService(typeof(ICalculator)); var instance2 = servieProvider.GetService(typeof(ICalculator)); Assert.IsAssignableFrom <ICalculator>(instance1); Assert.NotNull(instance1); Assert.NotNull(instance2); Assert.Same(instance1, instance2); }
public void Resolve_returns_provided_singleton_instance_for_each_invocation() { var calculator = new Calculator(); IContainer container = new AcrylicContainer(); container.Register <ICalculator>(calculator); var instance1 = container.Resolve <ICalculator>(); var instance2 = container.Resolve <ICalculator>(); Assert.NotNull(instance1); Assert.NotNull(instance2); Assert.Same(instance1, instance2); Assert.Same(calculator, instance1); Assert.Same(calculator, instance2); }