public void AfterResolvingAdapterType_AddingAnAdapter_AddsAdaptingComponents() { var registry = new ComponentRegistry(); registry.Register(RegistrationBuilder.ForType<object>().CreateRegistration()); var adapterService = new TypedService(typeof(Func<object>)); var pre = registry.RegistrationsFor(adapterService); Assert.AreEqual(0, pre.Count()); registry.AddRegistrationSource(new GeneratedFactoryRegistrationSource()); var post = registry.RegistrationsFor(adapterService); Assert.AreEqual(1, post.Count()); }
public void WhenNoImplementationsRegistered_RegistrationsForServiceIncludeDynamicSources() { var registry = new ComponentRegistry(); registry.AddRegistrationSource(new ObjectRegistrationSource()); Assert.False(registry.Registrations.Where( r => r.Services.Contains(new TypedService(typeof(object)))).Any()); Assert.Equal(1, registry.RegistrationsFor(new TypedService(typeof(object))).Count()); }
public void AddingConcreteImplementationWhenAdapterImplementationsExist_AddsChainedAdapters() { var registry = new ComponentRegistry(); registry.AddRegistrationSource(new GeneratedFactoryRegistrationSource()); registry.AddRegistrationSource(new MetaRegistrationSource()); registry.Register(RegistrationBuilder.ForType<object>().CreateRegistration()); var chainedService = new TypedService(typeof(Meta<Func<object>>)); var pre = registry.RegistrationsFor(chainedService); Assert.AreEqual(1, pre.Count()); Func<object> func = () => new object(); registry.Register(RegistrationBuilder.ForDelegate((c, p) => func).CreateRegistration()); var post = registry.RegistrationsFor(chainedService); Assert.AreEqual(2, post.Count()); }
public void AdaptingAGeneratedServiceYieldsASingleAdapter() { var registry = new ComponentRegistry(); registry.AddRegistrationSource(new MetaRegistrationSource()); registry.AddRegistrationSource(new CollectionRegistrationSource()); var metaCollections = registry.RegistrationsFor( new TypedService(typeof(Meta<IEnumerable<object>>))); Assert.AreEqual(1, metaCollections.Count()); }
public void AdaptingAnAdapterYieldsASingleAdapter() { var registry = new ComponentRegistry(); registry.Register(RegistrationBuilder.ForType<object>().CreateRegistration()); registry.AddRegistrationSource(new MetaRegistrationSource()); registry.AddRegistrationSource(new GeneratedFactoryRegistrationSource()); var metaCollections = registry.RegistrationsFor( new TypedService(typeof(Meta<Func<object>>))); Assert.AreEqual(1, metaCollections.Count()); }
public void AfterResolvingAdapter_AddingMoreAdaptees_AddsMoreAdapters() { var registry = new ComponentRegistry(); registry.AddRegistrationSource(new MetaRegistrationSource()); var metaService = new TypedService(typeof(Meta<object>)); var first = RegistrationBuilder.ForType<object>().CreateRegistration(); registry.Register(first); var meta1 = registry.RegistrationsFor(metaService); var firstMeta = meta1.First(); var second = RegistrationBuilder.ForType<object>().CreateRegistration(); registry.Register(second); var meta2 = registry.RegistrationsFor(metaService); Assert.That(meta2.Count(), Is.EqualTo(2)); Assert.That(meta2.Contains(firstMeta)); Assert.That(meta2.Select(m => m.Target), Is.EquivalentTo(new[] { first, second })); }
public void WhenRegistrationsAddedBeforeAndAfterSource_BothAreSeenBySource() { var r1 = Factory.CreateSingletonObjectRegistration(); var r2 = Factory.CreateSingletonObjectRegistration(); var registry = new ComponentRegistry(); registry.Register(r1); registry.AddRegistrationSource(new GeneratedFactoryRegistrationSource()); registry.Register(r2); var wrappedObjects = registry.RegistrationsFor(new TypedService(typeof(Func<object>))); Assert.AreEqual(2, wrappedObjects.Count()); }
public void WhenRegistrationProvidedExplicitlyAndThroughRegistrationSource_Reordered_BothAreReturnedFromRegistrationsFor() { var r = Factory.CreateSingletonObjectRegistration(); var registry = new ComponentRegistry(); registry.AddRegistrationSource(new ObjectRegistrationSource()); registry.Register(r); var forObject = registry.RegistrationsFor(new TypedService(typeof(object))); Assert.AreEqual(2, forObject.Count()); }
public void WhenAdaptersAreAppliedButNoRegistrationsCreated_AddingAdapteesAddsAdapters() { var registry = new ComponentRegistry(); registry.AddRegistrationSource(new GeneratedFactoryRegistrationSource()); var adapterService = new TypedService(typeof(Func<object>)); registry.RegistrationsFor(adapterService); registry.Register(RegistrationBuilder.ForType<object>().CreateRegistration()); var adapters = registry.RegistrationsFor(adapterService); Assert.AreEqual(1, adapters.Count()); }
public void WhenRegistrationProvidedExplicitlyAndThroughRegistrationSource_BothAreReturnedFromRegistrationsFor() { var r = Factory.CreateSingletonObjectRegistration(); var registry = new ComponentRegistry(); registry.Register(r); registry.AddRegistrationSource(new ObjectRegistrationSource()); var forObject = registry.RegistrationsFor(new TypedService(typeof(object))); Assert.Equal(2, forObject.Count()); // Just paranoia - make sure we don't regenerate forObject = registry.RegistrationsFor(new TypedService(typeof(object))); Assert.Equal(2, forObject.Count()); }