public void Read_FromStream_ParametersAreParsed()
        {
            // arrange
            var memoryStream = new MemoryStream();

            var streamWriter = new StreamWriter(memoryStream);
            streamWriter.WriteLine("assembly AssemblyOne.dll");
            streamWriter.WriteLine("reference ReferenceOne.dll");
            streamWriter.WriteLine("withDocs true");
            streamWriter.WriteLine("ignoreNamespace please.ignore");
            streamWriter.WriteLine("ignoreNamespace also.ignore");
            streamWriter.WriteLine("ignoreNamespaceRegex ^testing123$");
            streamWriter.WriteLine("headerLine this_is_line_1");
            streamWriter.WriteLine("headerLine this_is_line_2");
            streamWriter.WriteLine("headerFile headerfile.txt");
            streamWriter.WriteLine("outputFilePath output_file_path.txt");
            streamWriter.Flush();

            memoryStream.Position = 0;
            var streamReader = new StreamReader(memoryStream);

            var generatorFileReader = new GeneratorParametersReader(new DummyAssemblyLoader());

            // act
            var result = generatorFileReader.ReadFromStream(streamReader).Single();

            // assert
            result.Assembly.ShouldBeEquivalentTo(typeof(string).Assembly);
            result.References[0].ShouldBeEquivalentTo(typeof(string).Assembly);
            result.WithDocumentation.Should().BeTrue();
            result.IgnoreNamespace[0].Should().Be("please.ignore");
            result.IgnoreNamespace[1].Should().Be("also.ignore");
            result.IgnoreNamespaceRegex[0].IsMatch("testing123").Should().BeTrue();
            result.HeaderLines[0].Should().Be("this_is_line_1");
            result.HeaderLines[1].Should().Be("this_is_line_2");
            result.HeaderLines[2].Should().Be("HEADER FILE LINE 1");
            result.HeaderLines[3].Should().Be("HEADER FILE LINE 2");
            result.OutputFilePath.Should().Be("output_file_path.txt");
        }
Example #2
0
        private static List<GeneratorParameters> ReadParametersFromConfigurationFile(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new GeneratorException($"Could not find file {filename}");
            }

            var assemblyLoader = new AssemblyLoader();
            var generatorFileReader = new GeneratorParametersReader(assemblyLoader);

            List<GeneratorParameters> generatorParameters;
            using (var fileStream = File.OpenText(filename))
            {
                generatorParameters = generatorFileReader.ReadFromStream(fileStream).ToList();
            }
            return generatorParameters;
        }