Skip to content

Commit

Permalink
[cleanup] removing dependency on console project from tests by moving…
Browse files Browse the repository at this point in the history
… ParseNamespace method to CodeUtilities class
  • Loading branch information
ivan committed Oct 2, 2019
1 parent 48a8473 commit 1645b4f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
19 changes: 1 addition & 18 deletions XmlSchemaClassGenerator.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l
uris.AddRange(expandedGlob);
}

var namespaceMap = namespaces.Select(n => Utility.ParseNamespace(n, namespacePrefix)).ToNamespaceProvider(key =>
var namespaceMap = namespaces.Select(n => CodeUtilities.ParseNamespace(n, namespacePrefix)).ToNamespaceProvider(key =>
{
var xn = key.XmlSchemaNamespace;
var name = string.Join(".", xn.Split('/').Where(p => p != "schema" && GeneratorConfiguration.IdentifierRegex.IsMatch(p))
Expand Down Expand Up @@ -182,21 +182,4 @@ static void ShowHelp(OptionSet p)
p.WriteOptionDescriptions(System.Console.Out);
}
}
public static class Utility
{
public static KeyValuePair<NamespaceKey, string> ParseNamespace(string nsArg, string namespacePrefix)
{
var parts = nsArg.Split(new[] { '=' }, 2);
var xmlNs = parts[0];
var netNs = parts[1];
var parts2 = xmlNs.Split(new[] { '|' }, 2);
var source = parts2.Length == 2 ? new Uri(parts2[1], UriKind.RelativeOrAbsolute) : null;
xmlNs = parts2[0];
if (!string.IsNullOrEmpty(namespacePrefix))
{
netNs = namespacePrefix + "." + netNs;
}
return new KeyValuePair<NamespaceKey, string>(new NamespaceKey(source, xmlNs), netNs);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XmlSampleGenerator\XmlSampleGenerator.csproj" />
<ProjectReference Include="..\XmlSchemaClassGenerator.Console\XmlSchemaClassGenerator.Console.csproj" />
<ProjectReference Include="..\XmlSchemaClassGenerator\XmlSchemaClassGenerator.csproj" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using Ganss.IO;
using Microsoft.CodeAnalysis;
using Microsoft.Xml.XMLGen;
using XmlSchemaClassGenerator.Console;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -408,7 +407,7 @@ public void TestCustomNamespaces()
DataAnnotationMode = DataAnnotationMode.All,
GenerateNullables = true,
MemberVisitor = (member, model) => { },
NamespaceProvider = customNamespaceConfig.Select(n => Utility.ParseNamespace(n, null)).ToNamespaceProvider()
NamespaceProvider = customNamespaceConfig.Select(n => CodeUtilities.ParseNamespace(n, null)).ToNamespaceProvider()
});
Assert.NotNull(assembly);

Expand Down
15 changes: 15 additions & 0 deletions XmlSchemaClassGenerator/CodeUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,5 +297,20 @@ internal static string NormalizeNewlines(string text)
};

internal static Uri CreateUri(string uri) => string.IsNullOrEmpty(uri) ? null : new Uri(uri);

public static KeyValuePair<NamespaceKey, string> ParseNamespace(string nsArg, string namespacePrefix)
{
var parts = nsArg.Split(new[] { '=' }, 2);
var xmlNs = parts[0];
var netNs = parts[1];
var parts2 = xmlNs.Split(new[] { '|' }, 2);
var source = parts2.Length == 2 ? new Uri(parts2[1], UriKind.RelativeOrAbsolute) : null;
xmlNs = parts2[0];
if (!string.IsNullOrEmpty(namespacePrefix))
{
netNs = namespacePrefix + "." + netNs;
}
return new KeyValuePair<NamespaceKey, string>(new NamespaceKey(source, xmlNs), netNs);
}
}
}

0 comments on commit 1645b4f

Please sign in to comment.