diff --git a/AutoDI.Fody.Tests/DerivedClassTests.cs b/AutoDI.Fody.Tests/DerivedClassTests.cs new file mode 100644 index 0000000..7e4de19 --- /dev/null +++ b/AutoDI.Fody.Tests/DerivedClassTests.cs @@ -0,0 +1,71 @@ +using System.Reflection; +using System.Threading.Tasks; +using System.Xml.Linq; +using AutoDI.AssemblyGenerator; +using DerivedClassTestsNamespace; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AutoDI.Fody.Tests +{ + [TestClass] + public class DerivedClassTests + { + private static Assembly _testAssembly; + private static IContainer _map; + + [ClassInitialize] + public static async Task Initialize(TestContext context) + { + var gen = new Generator(); + + _testAssembly = (await gen.Execute()).SingleAssembly(); + + DI.Init(_testAssembly, builder => + { + builder.ConfigureContainer(map => + { + _map = map; + }); + }); + } + + [ClassCleanup] + public static void Cleanup() + { + DI.Dispose(_testAssembly); + } + + [TestMethod] + [Description("Issue 121")] + public void CanExcludeDerivedClasses() + { + //TODO: Outstanding question of how to handle this... + var libraryClass = _testAssembly.Resolve(); + Assert.AreEqual(nameof(LibraryClass), libraryClass?.GetType().Name); + var baseClass = _testAssembly.Resolve(); + Assert.AreEqual(nameof(MyBaseClass), baseClass?.GetType().Name); + var myClass = _testAssembly.Resolve(); + Assert.AreEqual(nameof(MyClass), myClass?.GetType().Name); + + var other = _testAssembly.Resolve(); + Assert.AreEqual(nameof(AllYourBase), other?.GetType().Name); + } + } +} + +// +// +// +namespace DerivedClassTestsNamespace +{ + public class LibraryClass { } + + public class MyBaseClass : LibraryClass { } + + public class MyClass : MyBaseClass { } + + public class OtherBase { } + + public class AllYourBase : OtherBase { } +} +// \ No newline at end of file