Example #1
0
        public void CommandSource_generator_produces_correct_code(bool useVB, string generatedCodeName)
        {
            var source = useVB
                       ? vbClassSource
                       : csharpClassSource;

            generatedCodeName = $"CliRoot{generatedCodeName}";

            var output = Utils.LanguageUtils(useVB).GenerateAndTestSource(generatedCodeName, source, null);

            NamerFactory.AdditionalInformation = $"{Utils.LanguageName(useVB)}-{Utils.ShortenedGeneratedCodeName(generatedCodeName)}";
            Approvals.Verify(output);
        }
        public void Command_with_argument(bool useVB)
        {
            var descriptor = new CliDescriptor
            {
                CommandDescriptor = new CommandDescriptor(null, "MyCommand", new RawInfoForType(null, namespaceName, className))
            };

            descriptor.CommandDescriptor.Arguments.Add(new ArgumentDescriptor(new ArgTypeInfoRoslyn(typeof(string)), descriptor.CommandDescriptor, "Argument1", new RawInfoForProperty(null, namespaceName, className)));
            var dom    = new GenerateCommandSource().CreateCode(descriptor);
            var actual = Utils.Generator(useVB).Generate(dom);

            NamerFactory.AdditionalInformation = Utils.LanguageName(useVB);
            Approvals.Verify(actual);
        }
        public void CliFromMethod_creates_code_that_will_compile_to_run(bool useVB, string generatedCodeName)
        {
            Utils utils       = Utils.LanguageUtils(useVB);
            var   testProject = "FromMethodOutput";
            var   outputPath  = $"{Path.Combine(outputRootPath, testProject)}.{Utils.Extension(useVB)}";
            var   input       = @$ "Program.{Utils.Extension(useVB)}";

            input = Path.Combine(outputPath, input);

            var output = utils.GenerateAndTest(generatedCodeName, input, outputPath, isExe: true);

            output.Length.Should().BeGreaterThan(1000);
            NamerFactory.AdditionalInformation = $"{Utils.LanguageName(useVB)}-{Utils.ShortenedGeneratedCodeName(generatedCodeName)}";
            Approvals.Verify(output);
        }
        public void CliRoot_creates_code_that_will_compile(bool useVB, string generatedCodeName)
        {
            Utils utils       = Utils.LanguageUtils(useVB);
            var   testProject = "Output";
            var   input       = $"CliRoot.{Utils.Extension(useVB)}";
            var   outputPath  = $"{Path.Combine(outputRootPath, testProject)}.{Utils.Extension(useVB)}";

            generatedCodeName = $"CliRoot{generatedCodeName}";

            var output = utils.GenerateAndTest(generatedCodeName, input, outputPath);

            output.Length.Should().BeGreaterThan(1000);
            NamerFactory.AdditionalInformation = $"{Utils.LanguageName(useVB)}-{Utils.ShortenedGeneratedCodeName(generatedCodeName)}";
            Approvals.Verify(output);
        }
        public void Command_with_option(bool useVB)
        {
            var descriptor = new CliDescriptor
            {
                CommandDescriptor = new CommandDescriptor(null, "MyCommand", new RawInfoForType(null, namespaceName, className))
            };

            descriptor.CommandDescriptor.Options.Add(new OptionDescriptor(descriptor.CommandDescriptor, "Option1", new RawInfoForProperty(null, namespaceName, className)));

            var dom    = new GenerateCommandSource().CreateCode(descriptor);
            var actual = Utils.Generator(useVB).Generate(dom);

            NamerFactory.AdditionalInformation = Utils.LanguageName(useVB);
            Approvals.Verify(actual);
        }
        public void Simple_command(bool useVB)
        {
            var descriptor = new CliDescriptor
            {
                CommandDescriptor = new CommandDescriptor(null, "MyCommand", new RawInfoForType(null, namespaceName, className))
            };

            descriptor.CommandDescriptor.CliName = "my-command";

            var dom    = new GenerateCommandSource().CreateCode(descriptor);
            var actual = Utils.Generator(useVB).Generate(dom);

            NamerFactory.AdditionalInformation = Utils.LanguageName(useVB);
            Approvals.Verify(actual);
        }