示例#1
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);
        }
示例#2
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);
        }
示例#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);
        }
示例#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);
        }
示例#5
0
        public void CanSkipContainerGeneration()
        {
            var xml = XElement.Parse(@"<AutoDI GenerateRegistrations=""False"" />");

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

            Assert.IsFalse(settings.GenerateRegistrations);
        }
示例#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");
 }
示例#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);
        }
示例#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));
        }
示例#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);
        }
示例#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);
        }