Esempio n. 1
0
        public async Task use_lambda_description()
        {
            var builder = Host.CreateDefaultBuilder()
                          .ConfigureServices(services =>
            {
                services.AddSingleton(new FakeService {
                    Name = "Hugo"
                });
                services.Describe <FakeService>("Fake Service #1", (s, w) => w.WriteLine("Fake Service Name: " + s.Name));
                services.Describe <FakeService>("Fake Service #2", (s, w) => w.WriteLineAsync("Fake Service Name Async: " + s.Name));
            });

            var input = new DescribeInput
            {
                HostBuilder = builder
            };

            var original = Console.Out;
            var output   = new StringWriter();

            Console.SetOut(output);

            try
            {
                await new DescribeCommand().Execute(input);

                var text = output.ToString().ReadLines();

                //text.ShouldContain("Fake Service #1");
                text.ShouldContain("Fake Service Name: Hugo");

                //text.ShouldContain("Fake Service #2");
                text.ShouldContain("Fake Service Name Async: Hugo");
            }
            finally
            {
                Console.SetOut(original);
            }
        }
Esempio n. 2
0
        public async Task using_custom_part_factory()
        {
            var builder = Host.CreateDefaultBuilder()
                          .ConfigureServices(services =>
            {
                services.AddSingleton(new FakeService {
                    Name = "Hugo"
                });
                services.AddDescriptionFactory <CustomDiscovery>();
            });

            var input = new DescribeInput
            {
                HostBuilder = builder
            };

            var original = Console.Out;
            var output   = new StringWriter();

            Console.SetOut(output);

            try
            {
                await new DescribeCommand().Execute(input);

                var text = output.ToString().ReadLines();

                text.ShouldContain("Description of the first part");
                text.ShouldContain("Second part writing in blue");
                text.ShouldContain("Description of the third part");
            }
            finally
            {
                Console.SetOut(original);
            }
        }