Esempio n. 1
0
 public static async Task <int> Main()
 {
     _container = CompositionRoot.Setup();
     return(await new CliApplicationBuilder()
            .AddCommandsFromThisAssembly()
            .SetExecutableName(ExecutableName)
            .SetVersion(BuildVersion())
            .UseTypeActivator(type => CliTypeActivator.ResolveType(_container, type))
            .Build()
            .RunAsync());
 }
        public void Resolve_ServiceCommandType_ActiveCommandSet()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <StubCommand>();
            var container = CompositionRoot.Setup(builder);

            var createdType   = CliTypeActivator.ResolveType(container, typeof(StubCommand));
            var activeCommand = container.Resolve <IActiveServiceCommandProvider>().ActiveCommand;

            activeCommand.Should().BeSameAs(createdType);
            activeCommand.Should().BeOfType <StubCommand>();
        }
        public void Resolve_NonServiceCommandType_NoActiveCommandSet()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <NonServiceCommandType>();
            var container = CompositionRoot.Setup(builder);

            var createdType = CliTypeActivator.ResolveType(container, typeof(NonServiceCommandType));

            Action act = () => _ = container.Resolve <IActiveServiceCommandProvider>().ActiveCommand;

            createdType.Should().BeOfType <NonServiceCommandType>();
            act.Should()
            .Throw <InvalidOperationException>()
            .WithMessage("The active command has not yet been determined");
        }