public void ResolveSimpleImplementation() { var resolver = new DefaultServiceBusResolver(); resolver.Register<IContract, SimpleImplementation>(); var result = resolver.Resolve<IContract>(); Assert.That(result, Is.InstanceOf<SimpleImplementation>()); }
public void ShouldResolveDifferentInstance() { var resolver = new DefaultServiceBusResolver(); resolver.Register<IContract, SimpleImplementation>(); var resultA = resolver.Resolve<IContract>(); var resultB = resolver.Resolve<IContract>(); Assert.That(resultA, Is.Not.SameAs(resultB)); }
public void IgnoreSubsequentRegistrationOfSimpleImplementation() { var resolver = new DefaultServiceBusResolver(); resolver.Register<IContract, AlternateSimpleImplementation>(); resolver.Register<IContract, SimpleImplementation>(); var result = resolver.Resolve<IContract>(); Assert.That(result, Is.InstanceOf<AlternateSimpleImplementation>()); }
public void ResolveTwoLevels() { var resolver = new DefaultServiceBusResolver(); resolver.Register<IContract, SimpleImplementation>(); resolver.Register<IAnotherContract, ContractAdapterImplementation>(); var result = resolver.Resolve<IAnotherContract>(); Assert.That(result, Is.InstanceOf<ContractAdapterImplementation>()); Assert.That(((ContractAdapterImplementation)result).Contract, Is.InstanceOf<SimpleImplementation>()); }
public void IgnoreSubsequentRegistrationOfInstance() { var resolver = new DefaultServiceBusResolver(); var simpleImplementation = new AlternateSimpleImplementation(); resolver.Register<IContract>(simpleImplementation); resolver.Register<IContract>(new SimpleImplementation()); var result = resolver.Resolve<IContract>(); Assert.That(result, Is.SameAs(simpleImplementation)); }
public void ShouldResolveSameInstance() { var resolver = new DefaultServiceBusResolver(); var simpleImplementation = new SimpleImplementation(); resolver.Register<IContract>(simpleImplementation); var resultA = resolver.Resolve<IContract>(); var resultB = resolver.Resolve<IContract>(); Assert.That(resultA, Is.SameAs(simpleImplementation)); Assert.That(resultB, Is.SameAs(simpleImplementation)); }
public void ThrowExceptionIfComponentNotRegistered() { var resolver = new DefaultServiceBusResolver(); Assert.That(() => resolver.Resolve<IContract>(), Throws.InstanceOf<ArgumentException>().With.Message.EqualTo("Failed to resolve IContract; no implementation has been registered")); }
public void ThrowExceptionIfComponentHasMultipleConstructors() { var resolver = new DefaultServiceBusResolver(); Assert.That(resolver.Register<IContract, MultipleConstructorImplementation>, Throws.InstanceOf<ArgumentException>().With.Message.EqualTo("Failed to register IContract; MultipleConstructorImplementation has multiple constructors")); }