Skip to content

Commit a99a6e0

Browse files
committed
Exception with UBL and unsupported version and profile
An exception will be thrown when writing to UBL with unsupported version and profile other than XRechnung. closes #492
1 parent fa17b64 commit a99a6e0

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

ZUGFeRD.Test/GlobalTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System;
2222
using System.Collections.Generic;
2323
using System.Text;
24+
using static System.Runtime.InteropServices.JavaScript.JSType;
2425

2526
namespace s2industries.ZUGFeRD.Test
2627
{
@@ -107,6 +108,31 @@ public void TestGetVersion()
107108
} // !TestGetVersion()
108109

109110

111+
[TestMethod]
112+
[DataRow(ZUGFeRDVersion.Version1, Profile.Extended)]
113+
[DataRow(ZUGFeRDVersion.Version1, Profile.XRechnung)]
114+
[DataRow(ZUGFeRDVersion.Version20, Profile.Extended)]
115+
[DataRow(ZUGFeRDVersion.Version20, Profile.XRechnung)]
116+
[DataRow(ZUGFeRDVersion.Version20, Profile.XRechnung1)]
117+
[DataRow(ZUGFeRDVersion.Version23, Profile.Extended)]
118+
[DataRow(ZUGFeRDVersion.Version23, Profile.XRechnung1)]
119+
public void UBLNonAvailability(ZUGFeRDVersion version, Profile profile)
120+
{
121+
InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
122+
MemoryStream ms = new MemoryStream();
123+
Assert.ThrowsException<UnsupportedException>(() => desc.Save(ms, version, profile, ZUGFeRDFormats.UBL));
124+
} // !UBLNonAvailability()
125+
126+
127+
[TestMethod]
128+
public void UBLAvailability()
129+
{
130+
InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice();
131+
MemoryStream ms = new MemoryStream();
132+
desc.Save(ms, ZUGFeRDVersion.Version23, Profile.XRechnung, ZUGFeRDFormats.UBL);
133+
} // !UBLAvailability()
134+
135+
110136
[TestMethod]
111137
[DataRow(ZUGFeRDVersion.Version1, Profile.Extended)]
112138
[DataRow(ZUGFeRDVersion.Version20, Profile.Extended)]

ZUGFeRD/InvoiceDescriptor23Writer.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,20 @@ internal class InvoiceDescriptor23Writer : IInvoiceDescriptorWriter
4141
/// <param name="format">Format of the target file</param>
4242
public override void Save(InvoiceDescriptor descriptor, Stream stream, ZUGFeRDFormats format = ZUGFeRDFormats.CII)
4343
{
44-
IInvoiceDescriptorWriter _writer;
45-
switch (format)
44+
IInvoiceDescriptorWriter _writer = null;
45+
46+
if (format == ZUGFeRDFormats.CII)
47+
{
48+
_writer = new InvoiceDescriptor23CIIWriter();
49+
}
50+
else if ((format == ZUGFeRDFormats.UBL) && (descriptor.Profile == Profile.XRechnung))
51+
{
52+
_writer = new InvoiceDescriptor22UBLWriter();
53+
}
54+
55+
if (_writer == null)
4656
{
47-
case ZUGFeRDFormats.UBL: _writer = new InvoiceDescriptor22UBLWriter(); break;
48-
default: _writer = new InvoiceDescriptor23CIIWriter(); break;
57+
throw new UnsupportedException($"Profile {descriptor.Profile.EnumToString()} and format {format.EnumToString()} is not supported.");
4958
}
5059

5160
_writer.Save(descriptor, stream, format);

0 commit comments

Comments
 (0)