forked from mganss/XmlSchemaClassGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXsdElsterDatenabholung5.cs
93 lines (87 loc) · 3.89 KB
/
XsdElsterDatenabholung5.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Xunit;
using System.Text;
namespace XmlSchemaClassGenerator.Tests
{
[TestCaseOrderer("XmlSchemaClassGenerator.Tests.PriorityOrderer", "XmlSchemaClassGenerator.Tests")]
public class XsdElsterDatenabholung5
{
static XsdElsterDatenabholung5()
{
// Ensure that the output directories are empty.
Directory.Delete(GetOutputPath(string.Empty), true);
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
[Fact, TestPriority(1)]
public void CanGenerateClasses()
{
var outputPath = GetOutputPath("CanGenerateClasses");
var gen = new Generator
{
EnableDataBinding = true,
IntegerDataType = typeof(int),
UseXElementForAny = true,
CollectionType = typeof(IList<>),
CollectionImplementationType = typeof(List<>),
GenerateDesignerCategoryAttribute = false,
GenerateNullables = true,
GenerateSerializableAttribute = false,
OutputFolder = outputPath,
NamingScheme = NamingScheme.Direct,
DataAnnotationMode = DataAnnotationMode.None,
EmitOrder = true,
GenerateDescriptionAttribute = true,
SeparateClasses = true,
NamespaceProvider = new NamespaceProvider
{
GenerateNamespace = key =>
{
return (Path.GetFileName(key.Source.LocalPath)) switch
{
"th000008_extern.xsd" or "ndh000010_extern.xsd" or "headerbasis000002.xsd" => "Elster.Basis",
"datenabholung_5.xsd" or "elster0810_datenabholung_5.xsd" => key.XmlSchemaNamespace switch
{
"http://www.elster.de/2002/XMLSchema" => "Elster.Datenabholung5",
_ => throw new NotSupportedException(string.Format("Namespace {0} for schema {1}", key.XmlSchemaNamespace, key.Source)),
},
_ => throw new NotSupportedException(string.Format("Namespace {0} for schema {1}", key.XmlSchemaNamespace, key.Source)),
};
}
}
};
var xsdFiles = new[]
{
"headerbasis000002.xsd",
"ndh000010_extern.xsd",
"th000008_extern.xsd",
"datenabholung_5.xsd",
"elster0810_datenabholung_5.xsd",
}.Select(x => Path.Combine(InputPath, x)).ToList();
var encodings = System.Text.Encoding.GetEncodings();
System.Text.Encoding.GetEncoding("ISO-8859-15");
gen.Generate(xsdFiles);
}
[Fact, TestPriority(2)]
public void CanCompileClasses()
{
var inputPath = GetOutputPath("CanGenerateClasses");
var fileNames = new DirectoryInfo(inputPath).GetFiles("*.cs", SearchOption.AllDirectories).Select(x => x.FullName).ToArray();
var assembly = Compiler.CompileFiles("Elster.Test", fileNames);
assembly.GetType("Elster.Datenabholung5.Elster", true);
assembly.GetType("Elster.Basis.TransferHeaderCType", true);
}
private static string InputPath
{
get { return Path.Combine(Directory.GetCurrentDirectory(), "xsd", "elster-xml-datenabholung5"); }
}
private static string GetOutputPath(string testCaseId)
{
var result = Path.Combine(Directory.GetCurrentDirectory(), "output", "elster-xml-datenabholung5", testCaseId);
Directory.CreateDirectory(result);
return result;
}
}
}