public void UseStartupSetsFeatureStartupType()
        {
            var registration = new FeatureRegistration <FeatureRegistrationFullNodeFeature>();

            Assert.Null(registration.FeatureStartupType);

            registration.UseStartup <ServiceCollection>();

            Assert.Equal(typeof(ServiceCollection), registration.FeatureStartupType);
        }
        public void BuildFeatureWithFeatureStartupNotHavingStaticConfigureServicesMethodDoesNotCrash()
        {
            var collection   = new ServiceCollection();
            var registration = new FeatureRegistration <FeatureRegistrationFullNodeFeature>();

            registration.FeatureServices(d => { d.AddSingleton <FeatureCollection>(); });
            registration.UseStartup <FeatureNonStaticStartup>();

            registration.BuildFeature(collection);
        }
        public void BuildFeatureWithFeatureStartupTypeBootstrapsStartupAndInvokesStartupWithCollection()
        {
            var collection   = new ServiceCollection();
            var registration = new FeatureRegistration <FeatureRegistrationFullNodeFeature>();

            registration.FeatureServices(d => { d.AddSingleton <FeatureCollection>(); });
            registration.UseStartup <FeatureStartup>();

            registration.BuildFeature(collection);
        }
        public void FeatureServicesAddServiceCollectionToDelegates()
        {
            var collection   = new ServiceCollection();
            var registration = new FeatureRegistration <FeatureRegistrationFullNodeFeature>();

            registration.FeatureServices(d => { d.AddSingleton <FeatureCollection>(); });

            Assert.Equal(typeof(FeatureRegistrationFullNodeFeature), registration.FeatureType);
            Assert.Single(registration.ConfigureServicesDelegates);
            registration.ConfigureServicesDelegates[0].Invoke(collection);
            var descriptors = collection as IList <ServiceDescriptor>;

            Assert.Equal(1, descriptors.Count);
            Assert.Equal(typeof(FeatureCollection), descriptors[0].ImplementationType);
            Assert.Equal(ServiceLifetime.Singleton, descriptors[0].Lifetime);
        }
        public void BuildFeatureWithoutFeatureStartupTypeBootstrapsStartup()
        {
            var collection   = new ServiceCollection();
            var registration = new FeatureRegistration <FeatureRegistrationFullNodeFeature>();

            registration.FeatureServices(d => { d.AddSingleton <FeatureCollection>(); });

            registration.BuildFeature(collection);

            var descriptors = collection as IList <ServiceDescriptor>;

            Assert.Equal(3, descriptors.Count);
            Assert.Equal(typeof(FeatureRegistrationFullNodeFeature), descriptors[0].ImplementationType);
            Assert.Equal(ServiceLifetime.Singleton, descriptors[0].Lifetime);
            Assert.Equal(typeof(IFullNodeFeature), descriptors[1].ServiceType);
            Assert.NotNull(descriptors[1].ImplementationFactory);
            Assert.Equal(ServiceLifetime.Singleton, descriptors[1].Lifetime);
            Assert.Equal(typeof(FeatureCollection), descriptors[2].ImplementationType);
            Assert.Equal(ServiceLifetime.Singleton, descriptors[2].Lifetime);
        }
        public static CommandLineBuilder RegisterWithDotnetSuggest(
            this CommandLineBuilder builder)
        {
            builder.AddMiddleware(async(context, next) =>
            {
                var feature = new FeatureRegistration("dotnet-suggest-registration");

                await feature.EnsureRegistered(async() =>
                {
                    try
                    {
                        var currentProcessFullPath = Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                        var currentProcessFileNameWithoutExtension = Path.GetFileNameWithoutExtension(currentProcessFullPath);

                        var stdOut = new StringBuilder();
                        var stdErr = new StringBuilder();

                        var dotnetSuggestProcess = Process.StartProcess(
                            command: "dotnet-suggest",
                            args: $"register --command-path \"{currentProcessFullPath}\" --suggestion-command \"{currentProcessFileNameWithoutExtension}\"",
                            stdOut: value => stdOut.Append(value),
                            stdErr: value => stdOut.Append(value));

                        await dotnetSuggestProcess.CompleteAsync();

                        return($"{dotnetSuggestProcess.StartInfo.FileName} exited with code {dotnetSuggestProcess.ExitCode}{NewLine}OUT:{NewLine}{stdOut}{NewLine}ERR:{NewLine}{stdErr}");
                    }
                    catch (Exception exception)
                    {
                        return($"Exception during registration:{NewLine}{exception}");
                    }
                });

                await next(context);
            }, MiddlewareOrderInternal.RegisterWithDotnetSuggest);

            return(builder);
        }