public void ResolveServicesUsing(Func <Type, IEnumerable <object> > servicesLocator, Func <Type, object> singleServiceLocator = null) { if (servicesLocator == null) { throw new ArgumentNullException("servicesLocator"); } ExternalServiceLocator = new ExternalServiceLocator(servicesLocator, singleServiceLocator); }
public void Should_not_throw_when_servicessource_is_null() { var expectedInstance = new MyClass1(); var expectedInstances = new List<object> { new MyClass1(), new MyClass1() }; Func<Type, object> validSingleSource = t => expectedInstance; Func<Type, IEnumerable<object>> validServicesSource = t => expectedInstances; var serviceLocator = new ExternalServiceLocator(validServicesSource, validSingleSource); Assert.That(serviceLocator.Resolve(typeof(MyClass1)), Is.EqualTo(expectedInstance)); Assert.That(serviceLocator.ResolveAll(typeof(MyClass1)), Is.EqualTo(expectedInstances)); }
public void Should_not_throw_when_servicessource_is_null() { var expectedInstance = new MyClass1(); var expectedInstances = new List <object> { new MyClass1(), new MyClass1() }; Func <Type, object> validSingleSource = t => expectedInstance; Func <Type, IEnumerable <object> > validServicesSource = t => expectedInstances; var serviceLocator = new ExternalServiceLocator(validServicesSource, validSingleSource); Assert.That(serviceLocator.Resolve(typeof(MyClass1)), Is.EqualTo(expectedInstance)); Assert.That(serviceLocator.ResolveAll(typeof(MyClass1)), Is.EqualTo(expectedInstances)); }