From 62681c044aa9824fcceef8e698bcae7da1c1b095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Sun, 30 May 2021 23:42:04 +0200 Subject: [PATCH] Add test that covers including command line arguments in the comments --- XmlSchemaClassGenerator.Tests/XmlTests.cs | 63 ++++++++++++++++++- .../CommandLineArgumentsProvider.cs | 2 +- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/XmlSchemaClassGenerator.Tests/XmlTests.cs b/XmlSchemaClassGenerator.Tests/XmlTests.cs index e1a0b59f..1b66de13 100644 --- a/XmlSchemaClassGenerator.Tests/XmlTests.cs +++ b/XmlSchemaClassGenerator.Tests/XmlTests.cs @@ -56,7 +56,9 @@ private static IEnumerable ConvertXml(string name, IEnumerable x CodeTypeReferenceOptions = generatorPrototype.CodeTypeReferenceOptions, DoNotForceIsNullable = generatorPrototype.DoNotForceIsNullable, CreateGeneratedCodeAttributeVersion = generatorPrototype.CreateGeneratedCodeAttributeVersion, - NetCoreSpecificCode = generatorPrototype.NetCoreSpecificCode + NetCoreSpecificCode = generatorPrototype.NetCoreSpecificCode, + GenerateCommandLineArgumentsComment = generatorPrototype.GenerateCommandLineArgumentsComment, + CommandLineArgumentsProvider = generatorPrototype.CommandLineArgumentsProvider, }; gen.CommentLanguages.Clear(); @@ -2388,5 +2390,64 @@ void UnknownAttributeHandler(object sender, XmlAttributeEventArgs e) AssertEx.Equal(deserializedObject, deserializedXml); } } + + [Theory] + [InlineData("fake command line arguments", "fake command line arguments")] + [InlineData(null, "N/A")] + public void IncludeCommandLineArguments(string commandLineArguments, string expectedCommandLineArguments) + { + const string xsd = @" + + + + + +"; + + var generator = new Generator + { + GenerateInterfaces = false, + NamespaceProvider = new NamespaceProvider + { + GenerateNamespace = key => "Test" + }, + GenerateCommandLineArgumentsComment = true, + CommandLineArgumentsProvider = new CommandLineArgumentsProvider(commandLineArguments) + }; + + var contents = ConvertXml(nameof(IncludeCommandLineArguments), xsd, generator); + + var csharp = Assert.Single(contents); + + CompareOutput( + $@"//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +// This code was generated by Tests version 1.0.0.1 using the following command: +// {expectedCommandLineArguments} +namespace Test +{{ + + + [System.CodeDom.Compiler.GeneratedCodeAttribute(""Tests"", ""1.0.0.1"")] + [System.SerializableAttribute()] + [System.Xml.Serialization.XmlTypeAttribute(""elem"", Namespace=""http://local.none"")] + [System.ComponentModel.DesignerCategoryAttribute(""code"")] + [System.Xml.Serialization.XmlRootAttribute(""document"", Namespace=""http://local.none"")] + public partial class Elem + {{ + + [System.Xml.Serialization.XmlAttributeAttribute(""Text"")] + public string Text {{ get; set; }} + }} +}} +", csharp); + } } } diff --git a/XmlSchemaClassGenerator/CommandLineArgumentsProvider.cs b/XmlSchemaClassGenerator/CommandLineArgumentsProvider.cs index 144e14c2..e71d0c4f 100644 --- a/XmlSchemaClassGenerator/CommandLineArgumentsProvider.cs +++ b/XmlSchemaClassGenerator/CommandLineArgumentsProvider.cs @@ -9,7 +9,7 @@ public class CommandLineArgumentsProvider { public CommandLineArgumentsProvider(string commandLineArguments) { - CommandLineArguments = commandLineArguments ?? throw new ArgumentNullException(nameof(commandLineArguments)); + CommandLineArguments = commandLineArguments; } public string CommandLineArguments { get; }