Example #1
0
        public void CanLoadIndividualBehavior()
        {
            var xml = XElement.Parse($@"<AutoDI behavior=""{Behaviors.SingleInterfaceImplementation}""/>");

            var settings = Settings.Parse(new Settings(), xml);

            Assert.AreEqual((int)Behaviors.SingleInterfaceImplementation, (int)settings.Behavior);
        }
Example #2
0
        public void CanLoadCompositeBehavior()
        {
            var xml = XElement.Parse($@"<AutoDI behavior=""{Behaviors.SingleInterfaceImplementation},{Behaviors.IncludeClasses}""/>");

            var settings = Settings.Parse(new Settings(), xml);

            Assert.AreEqual((int)(Behaviors.SingleInterfaceImplementation | Behaviors.IncludeClasses), (int)settings.Behavior);
        }
Example #3
0
        public void CanEnableCSharpCodeGeneration()
        {
            var xml = XElement.Parse($@"<AutoDI {nameof(Settings.DebugCodeGeneration)}=""{CodeLanguage.CSharp}"" />");

            var settings = Settings.Parse(new Settings(), xml);

            Assert.AreEqual((int)CodeLanguage.CSharp, (int)settings.DebugCodeGeneration);
        }
Example #4
0
        public void CanLoadBasicSettings()
        {
            var xml = XElement.Parse(@"<AutoDI />");

            var settings = Settings.Parse(new Settings(), xml);

            Assert.AreEqual((int)Behaviors.Default, (int)settings.Behavior);
        }
Example #5
0
        public void CanSkipContainerGeneration()
        {
            var xml = XElement.Parse(@"<AutoDI GenerateRegistrations=""False"" />");

            var settings = Settings.Parse(new Settings(), xml);

            Assert.IsFalse(settings.GenerateRegistrations);
        }
Example #6
0
 private static void TextExpectedParseException(XElement xml, string expectedMessage)
 {
     try
     {
         Settings.Parse(new Settings(), xml);
     }
     catch (SettingsParseException e) when(e.Message == expectedMessage)
     {
         return;
     }
     Assert.Fail("Failed to get expected exception");
 }
Example #7
0
        public void CanLoadSettingsWithDeclaredType()
        {
            var xml = XElement.Parse(@"
                    <AutoDI>
                        <type name=""NS.MyType*"" lifetime=""Transient"" />
                    </AutoDI>");

            var settings = Settings.Parse(new Settings(), xml);

            Assert.AreEqual(1, settings.Types.Count);
            Assert.IsTrue(settings.Types[0].Matches("NS.MyType2"));
            Assert.AreEqual((int)Lifetime.Transient, (int)settings.Types[0].Lifetime);
        }
Example #8
0
        public void CanLoadSettingsWithIncludedAssembly()
        {
            var xml = XElement.Parse(@"
                    <AutoDI>
                        <assembly name=""MyAssembly.*"" />
                    </AutoDI>");

            var settings = Settings.Parse(new Settings(), xml);

            Assert.AreEqual(1, settings.Assemblies.Count);
            var assembly = AssemblyDefinition.CreateAssembly(new AssemblyNameDefinition("MyAssembly.Test", new Version(1, 0, 0)), "<Module>", ModuleKind.Dll);

            Assert.IsTrue(settings.Assemblies[0].Matches(assembly));
        }
Example #9
0
        public void CanLoadSettingsWithRegexMap()
        {
            var xml = XElement.Parse(@"
                    <AutoDI>
                        <map from=""regex:ViewModels.(.*)"" to=""Views.$1"" />
                    </AutoDI>");

            var settings = Settings.Parse(new Settings(), xml);

            Assert.AreEqual(1, settings.Maps.Count);
            var type = new TypeDefinition("ViewModels", "Test", TypeAttributes.Class);

            Assert.IsTrue(settings.Maps[0].TryGetMap(type, out var mappedType));
            Assert.AreEqual("Views.Test", mappedType);
        }
Example #10
0
        public void CanLoadSettingsWithSimpleMap()
        {
            var xml = XElement.Parse(@"
                    <AutoDI>
                        <map from=""IService"" to=""Service"" />
                    </AutoDI>");

            var settings = Settings.Parse(new Settings(), xml);

            Assert.AreEqual(1, settings.Maps.Count);
            var type = new TypeDefinition("", "IService", TypeAttributes.Interface);

            Assert.IsTrue(settings.Maps[0].TryGetMap(type, out string mappedType));
            Assert.AreEqual("Service", mappedType);
        }
Example #11
0
        public void DebugCodeGenerationDefaultsOff()
        {
            var settings = new Settings();

            Assert.AreEqual((int)CodeLanguage.None, (int)settings.DebugCodeGeneration);
        }