diff --git a/CHANGELOG.md b/CHANGELOG.md index 1824f7e0..d37dae1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix exception that occurred when running the create-config subcommand. + ## [1.3.1] - 2021-05-05 ### Changed diff --git a/src/Trash.Tests/CompositionRootTest.cs b/src/Trash.Tests/CompositionRootTest.cs new file mode 100644 index 00000000..24a99756 --- /dev/null +++ b/src/Trash.Tests/CompositionRootTest.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections; +using System.Linq; +using System.Reflection; +using Autofac; +using CliFx; +using NUnit.Framework; + +namespace Trash.Tests +{ + [TestFixture] + [Parallelizable(ParallelScope.All)] + public class CompositionRootTest + { + private class ConcreteTypeEnumerator : IEnumerable + { + private readonly Assembly _asm; + + public ConcreteTypeEnumerator() + { + _asm = Assembly.GetAssembly(typeof(CompositionRoot)) ?? throw new NullReferenceException(); + } + + public IEnumerator GetEnumerator() + { + return _asm.DefinedTypes + .Where(t => t.GetInterfaces().Contains(typeof(ICommand)) && !t.IsAbstract) + .GetEnumerator(); + } + } + + [TestCaseSource(typeof(ConcreteTypeEnumerator))] + public void Resolve_ICommandConcreteClasses(Type concreteCmd) + { + var builder = new ContainerBuilder(); + var container = CompositionRoot.Setup(builder); + container.Resolve(concreteCmd); + } + } +} diff --git a/src/Trash/CompositionRoot.cs b/src/Trash/CompositionRoot.cs index a8bde525..db45406f 100644 --- a/src/Trash/CompositionRoot.cs +++ b/src/Trash/CompositionRoot.cs @@ -67,9 +67,7 @@ namespace Trash { // Register all types deriving from CliFx's ICommand. These are all of our supported subcommands. builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) - .Where(t => t.IsAssignableTo(typeof(ICommand))) - .As() - .AsSelf(); + .Where(t => t.IsAssignableTo(typeof(ICommand))); // Used to access the chosen command class. This is assigned from CliTypeActivator builder.RegisterType()