Skip to content

Commit

Permalink
Add test that covers including command line arguments in the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed May 30, 2021
1 parent 9857951 commit 62681c0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
63 changes: 62 additions & 1 deletion XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ private static IEnumerable<string> ConvertXml(string name, IEnumerable<string> 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();
Expand Down Expand Up @@ -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 = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<xs:schema elementFormDefault=""qualified"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" targetNamespace=""http://local.none"" xmlns:l=""http://local.none"">
<xs:element name=""document"" type=""l:elem"" />
<xs:complexType name=""elem"">
<xs:attribute name=""Text"" type=""xs:string""/>
</xs:complexType>
</xs:schema>";

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(
$@"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
// 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);
}
}
}
2 changes: 1 addition & 1 deletion XmlSchemaClassGenerator/CommandLineArgumentsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class CommandLineArgumentsProvider
{
public CommandLineArgumentsProvider(string commandLineArguments)
{
CommandLineArguments = commandLineArguments ?? throw new ArgumentNullException(nameof(commandLineArguments));
CommandLineArguments = commandLineArguments;
}

public string CommandLineArguments { get; }
Expand Down

0 comments on commit 62681c0

Please sign in to comment.