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); }
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); }
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); }
public void CanLoadBasicSettings() { var xml = XElement.Parse(@"<AutoDI />"); var settings = Settings.Parse(new Settings(), xml); Assert.AreEqual((int)Behaviors.Default, (int)settings.Behavior); }
public void CanSkipContainerGeneration() { var xml = XElement.Parse(@"<AutoDI GenerateRegistrations=""False"" />"); var settings = Settings.Parse(new Settings(), xml); Assert.IsFalse(settings.GenerateRegistrations); }
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"); }
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); }
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)); }
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); }
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); }