public void RegisterConfiguredComponents_MetadataMissingName()
        {
            var builder   = EmbeddedConfiguration.ConfigureContainerWithXml("ComponentRegistrar_MetadataMissingName.xml");
            var exception = Assert.Throws <InvalidOperationException>(() => builder.Build());

            Assert.Equal("The 'metadata' collection should be ordinal (like an array) with items that have numeric names to indicate the index in the collection. 'components:0:metadata' didn't have a numeric name so couldn't be parsed. Check https://autofac.readthedocs.io/en/latest/configuration/xml.html for configuration examples.", exception.Message);
        }
        public void RegisterConfiguredComponents_LifetimeScope_Singleton()
        {
            var builder   = EmbeddedConfiguration.ConfigureContainerWithXml("ComponentRegistrar_SingletonWithTwoServices.xml");
            var container = builder.Build();

            Assert.Same(container.Resolve <ITestComponent>(), container.Resolve <ITestComponent>());
        }
 public void RegisterConfiguredComponents_ConstructorInjection()
 {
     var builder = EmbeddedConfiguration.ConfigureContainerWithXml("ComponentRegistrar_SingletonWithTwoServices.xml");
     var container = builder.Build();
     var cpt = (SimpleComponent)container.Resolve<ITestComponent>();
     Assert.Equal(1.234, cpt.Input);
 }
        public void InjectsSingleValueWithConversion()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_EnumerableParameters.xml").Build();

            var poco = container.Resolve <D>();

            Assert.True(poco.Num == 123);
        }
 public void RegisterConfiguredComponents_SingleComponentWithTwoServices()
 {
     var builder = EmbeddedConfiguration.ConfigureContainerWithXml("ComponentRegistrar_SingletonWithTwoServices.xml");
     var container = builder.Build();
     container.AssertRegistered<ITestComponent>("The ITestComponent wasn't registered.");
     container.AssertRegistered<object>("The object wasn't registered.");
     container.AssertNotRegistered<SimpleComponent>("The base SimpleComponent type was incorrectly registered.");
     Assert.Same(container.Resolve<ITestComponent>(), container.Resolve<object>());
 }
Пример #6
0
        public void RegisterConfiguredComponents_PropertyInjectionWithProvidedValues()
        {
            var builder   = EmbeddedConfiguration.ConfigureContainerWithXml("ComponentRegistrar_SingletonWithTwoServices.xml");
            var container = builder.Build();
            var cpt       = (SimpleComponent)container.Resolve <ITestComponent>();

            Assert.Equal("hello", cpt.Message);
            Assert.True(cpt.ABool, "The Boolean property value was not properly parsed/converted.");
        }
        public void ParameterStringListInjectionMultipleConstructors()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_EnumerableParameters.xml").Build();

            var poco = container.Resolve <L>();

            Assert.True(poco.List.Count == 2);
            Assert.Equal(poco.List[0], "Val1");
            Assert.Equal(poco.List[1], "Val2");
        }
        public void ConvertsTypeInList()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_EnumerableParameters.xml").Build();

            var poco = container.Resolve <B>();

            Assert.True(poco.List.Count == 2);
            Assert.Equal(1.234, poco.List[0]);
            Assert.Equal(2.345, poco.List[1]);
        }
        public void ParameterStringListInjectionOptionalParameter()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_EnumerableParameters.xml").Build();

            var poco = container.Resolve <K>();

            Assert.True(poco.List.Count == 2);
            Assert.Equal("Val1", poco.List[0]);
            Assert.Equal("Val2", poco.List[1]);
        }
        public void InjectsConstructorParameter()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_EnumerableParameters.xml").Build();

            var poco = container.Resolve <E>();

            Assert.True(poco.List.Count == 2);
            Assert.Equal(poco.List[0], 1);
            Assert.Equal(poco.List[1], 2);
        }
        public void FillsNonGenericListWithString()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_EnumerableParameters.xml").Build();

            var poco = container.Resolve <C>();

            Assert.True(poco.List.Count == 2);
            Assert.Equal(poco.List[0], "1");
            Assert.Equal(poco.List[1], "2");
        }
        public void InjectsGenericCollection()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_EnumerableParameters.xml").Build();

            var poco = container.Resolve <I>();

            Assert.NotNull(poco.Collection);
            Assert.True(poco.Collection.Count == 2);
            Assert.Equal(poco.Collection.First(), 1);
            Assert.Equal(poco.Collection.Last(), 2);
        }
        public void InjectsConcreteDictionary()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_DictionaryParameters.xml").Build();

            var poco = container.Resolve <D>();

            Assert.True(poco.Dictionary.Count == 2);
            Assert.True(poco.Dictionary.ContainsKey("Key1"));
            Assert.True(poco.Dictionary.ContainsKey("Key2"));
            Assert.Equal("Val1", poco.Dictionary["Key1"]);
            Assert.Equal("Val2", poco.Dictionary["Key2"]);
        }
        public void ConvertsDictionaryValue()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_DictionaryParameters.xml").Build();

            var poco = container.Resolve <F>();

            Assert.True(poco.Dictionary.Count == 2);
            Assert.True(poco.Dictionary.ContainsKey("Key1"));
            Assert.True(poco.Dictionary.ContainsKey("Key2"));
            Assert.Equal(1, poco.Dictionary["Key1"]);
            Assert.Equal(2, poco.Dictionary["Key2"]);
        }
        public void NumericKeysZeroBasedListConvertedToDictionary()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_DictionaryParameters.xml").Build();

            var poco = container.Resolve <E>();

            Assert.True(poco.Dictionary.Count == 2);
            Assert.True(poco.Dictionary.ContainsKey(0));
            Assert.True(poco.Dictionary.ContainsKey(1));
            Assert.Equal("Val1", poco.Dictionary[0]);
            Assert.Equal("Val2", poco.Dictionary[1]);
        }
        public void InjectsGenericIEnumerable()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_EnumerableParameters.xml").Build();

            var poco = container.Resolve <H>();

            Assert.NotNull(poco.Enumerable);
            var enumerable = poco.Enumerable.ToList();

            Assert.True(enumerable.Count == 2);
            Assert.Equal(enumerable[0], 1);
            Assert.Equal(enumerable[1], 2);
        }
        public void InjectsIEnumerable()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_EnumerableParameters.xml").Build();

            var poco = container.Resolve <G>();

            Assert.NotNull(poco.Enumerable);
            var enumerable = poco.Enumerable.Cast <string>().ToList();

            Assert.True(enumerable.Count == 2);
            Assert.Equal("Val1", enumerable[0]);
            Assert.Equal("Val2", enumerable[1]);
        }
        public void NumericKeysZeroBasedNonSequential()
        {
            var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_DictionaryParameters.xml").Build();

            var poco = container.Resolve <G>();

            Assert.True(poco.Dictionary.Count == 3);
            Assert.True(poco.Dictionary.ContainsKey(0));
            Assert.True(poco.Dictionary.ContainsKey(5));
            Assert.True(poco.Dictionary.ContainsKey(10));
            Assert.Equal("Val0", poco.Dictionary[0]);
            Assert.Equal("Val1", poco.Dictionary[5]);
            Assert.Equal("Val2", poco.Dictionary[10]);
        }
        public void TypeConversionsAreCaseInvariant(CultureInfo culture)
        {
            // Issue #26 - parsing needs to be InvariantCulture or config fails
            // when it's moved from machine to machine.
            TestCulture.With(
                culture,
                () =>
            {
                var container = EmbeddedConfiguration.ConfigureContainerWithXml("ConfigurationExtensions_EnumerableParameters.xml").Build();

                var poco = container.Resolve <E>();

                Assert.True(poco.List.Count == 2);
                Assert.Equal(1.234, poco.List[0]);
                Assert.Equal(2.345, poco.List[1]);
            });
        }