public void RegisterConfiguredComponents_ExternalOwnership() { var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ComponentRegistrar_ExternalOwnership.json"); var container = builder.Build(); Assert.True(container.ComponentRegistry.TryGetRegistration(new TypedService(typeof(SimpleComponent)), out IComponentRegistration registration), "The expected component was not registered."); Assert.Equal(InstanceOwnership.ExternallyOwned, registration.Ownership); }
public void RegisterConfiguredComponents_LifetimeScope_InstancePerDependency() { var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ComponentRegistrar_InstancePerDependency.json"); var container = builder.Build(); Assert.NotSame(container.Resolve <SimpleComponent>(), container.Resolve <SimpleComponent>()); }
public void RegisterConfiguredComponents_RegistersMetadata() { var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ComponentRegistrar_ComponentWithMetadata.json"); var container = builder.Build(); Assert.True(container.ComponentRegistry.TryGetRegistration(new KeyedService("a", typeof(object)), out IComponentRegistration registration), "The expected service wasn't registered."); Assert.Equal(42.42, (double)registration.Metadata["answer"]); }
public void RegisterConfiguredComponents_AutoActivationNotEnabledOnComponent() { var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ComponentRegistrar_EnableAutoActivation.json"); var container = builder.Build(); Assert.True(container.ComponentRegistry.TryGetRegistration(new KeyedService("b", typeof(object)), out IComponentRegistration registration), "The expected component was not registered."); Assert.False(registration.Services.Any(a => a.GetType().Name == "AutoActivateService"), "Auto activate service was registered on the component when it shouldn't be."); }
public void GetParameters_ParameterConversionUsesTypeConverterAttribute() { var container = EmbeddedConfiguration.ConfigureContainerWithJson("ConfigurationExtensions_Parameters.json").Build(); var obj = container.Resolve <HasConvertibleParametersAndProperties>(); Assert.NotNull(obj.Parameter); Assert.Equal(1, obj.Parameter.Value); }
public void GetProperties_DictionaryPropertyUsesTypeConverterAttribute() { var container = EmbeddedConfiguration.ConfigureContainerWithJson("ConfigurationExtensions_Parameters.json").Build(); var obj = container.Resolve <HasDictionaryProperty>(); Assert.NotNull(obj.Convertible); Assert.Equal(2, obj.Convertible.Count); Assert.Equal(1, obj.Convertible["a"].Value); Assert.Equal(2, obj.Convertible["b"].Value); }
public void RegisterConfiguredComponents_PropertyInjectionEnabledOnComponent() { var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ComponentRegistrar_EnablePropertyInjection.json"); builder.RegisterType <SimpleComponent>().As <ITestComponent>(); var container = builder.Build(); var e = container.Resolve <ComponentConsumer>(); Assert.NotNull(e.Component); }
public void RegisterConfiguredModules_ComplexPropertyType() { var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ModuleConfiguration_ComplexType.json"); var container = builder.Build(); var poco = container.Resolve <ComplexPropertyComponent>(); Assert.Equal(2, poco.List.Count()); Assert.Equal("Val3", poco.List[0]); Assert.Equal("Val4", poco.List[1]); }
public void RegisterConfiguredComponents_AllowsMultipleRegistrationsOfSameType() { var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ComponentRegistrar_SameTypeRegisteredMultipleTimes.json"); var container = builder.Build(); var collection = container.Resolve<IEnumerable<SimpleComponent>>(); Assert.Equal(2, collection.Count()); // Test using Any() because we aren't necessarily guaranteed the order of resolution. Assert.True(collection.Any(a => a.Input == 5.123), "The first registration (5.123) wasn't found."); Assert.True(collection.Any(a => a.Input == 10.234), "The second registration (10.234) wasn't found."); }
public void RegisterConfiguredComponents_MemberOf() { var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ComponentRegistrar_MemberOf.json"); builder.RegisterCollection <ITestComponent>("named-collection").As <IList <ITestComponent> >(); var container = builder.Build(); var collection = container.Resolve <IList <ITestComponent> >(); var first = collection[0]; Assert.IsType <SimpleComponent>(first); }
public void GetProperties_ListConversionUsesTypeConverterAttribute() { var container = EmbeddedConfiguration.ConfigureContainerWithJson("ConfigurationExtensions_Parameters.json").Build(); var obj = container.Resolve <HasEnumerableProperty>(); Assert.NotNull(obj.Convertible); var convertible = obj.Convertible.ToArray(); Assert.Equal(2, convertible.Length); Assert.Equal(1, convertible[0].Value); Assert.Equal(2, convertible[1].Value); }
public void RegisterConfiguredComponents_PropertyInjectionEnabledOnComponent() { var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ComponentRegistrar_EnablePropertyInjection.json"); builder.RegisterType<SimpleComponent>().As<ITestComponent>(); builder.RegisterInstance("hello").As<string>(); var container = builder.Build(); var e = container.Resolve<ComponentConsumer>(); Assert.NotNull(e.Component); // Issue #2 - Ensure properties in base classes can be set by config. Assert.Equal("hello", e.Message); }
public void RegisterConfiguredModules_AllowsMultipleModulesOfSameTypeWithDifferentParameters() { // Issue #271: Could not register more than one module with the same type but different parameters in XmlConfiguration. var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ModuleRegistrar_SameModuleRegisteredMultipleTimes.json"); var container = builder.Build(); var collection = container.Resolve <IEnumerable <SimpleComponent> >(); Assert.Equal(2, collection.Count()); // Test using Any() because we aren't necessarily guaranteed the order of resolution. Assert.True(collection.Any(a => a.Message == "First"), "The first registration wasn't found."); Assert.True(collection.Any(a => a.Message == "Second"), "The second registration wasn't found."); }
public void RegisterConfiguredComponents_ModuleWithNoPublicConstructor_ThrowsInvalidOperation() { var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ModuleRegistrar_ModuleWithNoPublicConstructor.json"); Assert.Throws <NoConstructorsFoundException>(() => builder.Build()); }