|
| 1 | +{* Licensed to the Apache Software Foundation (ASF) under one |
| 2 | + * or more contributor license agreements. See the NOTICE file |
| 3 | + * distributed with this work for additional information |
| 4 | + * regarding copyright ownership. The ASF licenses this file |
| 5 | + * to you under the Apache License, Version 2.0 (the |
| 6 | + * "License"); you may not use this file except in compliance |
| 7 | + * with the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, |
| 12 | + * software distributed under the License is distributed on an |
| 13 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | + * KIND, either express or implied. See the License for the |
| 15 | + * specific language governing permissions and limitations |
| 16 | + * under the License.} |
| 17 | + |
| 18 | +unit intf.XRechnungUBLTests.UnitTests; |
| 19 | + |
| 20 | +interface |
| 21 | + |
| 22 | +uses |
| 23 | + System.SysUtils |
| 24 | + ,DUnitX.TestFramework |
| 25 | + ,intf.ZUGFeRDInvoiceDescriptor |
| 26 | + ,intf.ZUGFeRDProfile,intf.ZUGFeRDInvoiceTypes |
| 27 | + ,intf.ZUGFeRDInvoiceProvider |
| 28 | + ,intf.ZUGFeRDVersion |
| 29 | + ; |
| 30 | + |
| 31 | +type |
| 32 | + [TestFixture] |
| 33 | + TXRechnungUBLTests = class |
| 34 | + public |
| 35 | + [Test] |
| 36 | + procedure TestInvoiceCreation; |
| 37 | + [Test] |
| 38 | + procedure TestTradelineitemProductCharacterstics; |
| 39 | + /// <summary> |
| 40 | + /// https://github.com/stephanstapel/ZUGFeRD-csharp/issues/319 |
| 41 | + /// </summary> |
| 42 | + [Test] |
| 43 | + procedure TestSkippingOfAllowanceChargeBasisAmount; |
| 44 | + end; |
| 45 | + |
| 46 | +implementation |
| 47 | + |
| 48 | +{ TXRechnungUBLTests } |
| 49 | + |
| 50 | +procedure TXRechnungUBLTests.TestInvoiceCreation; |
| 51 | +begin |
| 52 | +// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice(); |
| 53 | +// MemoryStream ms = new MemoryStream(); |
| 54 | +// |
| 55 | +// desc.Save(ms, ZUGFeRDVersion.Version22, Profile.XRechnung, ZUGFeRDFormats.UBL); |
| 56 | +// ms.Seek(0, SeekOrigin.Begin); |
| 57 | +// |
| 58 | +// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms); |
| 59 | +// |
| 60 | +// Assert.AreEqual(loadedInvoice.Invoicee, null); |
| 61 | +// Assert.AreNotEqual(loadedInvoice.Seller, null); |
| 62 | +// Assert.AreEqual(loadedInvoice.Taxes.Count, 2); |
| 63 | +// Assert.AreEqual(loadedInvoice.SellerContact.Name, "Max Mustermann"); |
| 64 | +// Assert.IsNull(loadedInvoice.BuyerContact); |
| 65 | +end; |
| 66 | + |
| 67 | +procedure TXRechnungUBLTests.TestSkippingOfAllowanceChargeBasisAmount; |
| 68 | +begin |
| 69 | +// // actual values do not matter |
| 70 | +// decimal basisAmount = 123.0m; |
| 71 | +// decimal percent = 11.0m; |
| 72 | +// decimal allowanceChargeBasisAmount = 121.0m; |
| 73 | +// |
| 74 | +// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice(); |
| 75 | +// desc.AddApplicableTradeTax(basisAmount, percent, TaxTypes.LOC, TaxCategoryCodes.K, allowanceChargeBasisAmount); |
| 76 | +// MemoryStream ms = new MemoryStream(); |
| 77 | +// |
| 78 | +// desc.Save(ms, ZUGFeRDVersion.Version22, Profile.XRechnung, ZUGFeRDFormats.UBL); |
| 79 | +// ms.Seek(0, SeekOrigin.Begin); |
| 80 | +// |
| 81 | +// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms); |
| 82 | +// |
| 83 | +// Tax tax = loadedInvoice.Taxes.FirstOrDefault(t => t.TypeCode == TaxTypes.LOC); |
| 84 | +// Assert.IsNotNull(tax); |
| 85 | +// Assert.AreEqual(basisAmount, tax.BasisAmount); |
| 86 | +// Assert.AreEqual(percent, tax.Percent); |
| 87 | +// Assert.AreEqual(null, tax.AllowanceChargeBasisAmount); |
| 88 | +end; |
| 89 | + |
| 90 | +procedure TXRechnungUBLTests.TestTradelineitemProductCharacterstics; |
| 91 | +begin |
| 92 | +// InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice(); |
| 93 | +// |
| 94 | +// desc.TradeLineItems[0].ApplicableProductCharacteristics = new ApplicableProductCharacteristic[] |
| 95 | +// { |
| 96 | +// new ApplicableProductCharacteristic() |
| 97 | +// { |
| 98 | +// Description = "Test Description", |
| 99 | +// Value = "1.5 kg" |
| 100 | +// }, |
| 101 | +// new ApplicableProductCharacteristic() |
| 102 | +// { |
| 103 | +// Description = "UBL Characterstics 2", |
| 104 | +// Value = "3 kg" |
| 105 | +// }, |
| 106 | +// }.ToList(); |
| 107 | +// |
| 108 | +// MemoryStream ms = new MemoryStream(); |
| 109 | +// |
| 110 | +// desc.Save(ms, ZUGFeRDVersion.Version22, Profile.XRechnung, ZUGFeRDFormats.UBL); |
| 111 | +// ms.Seek(0, SeekOrigin.Begin); |
| 112 | +// |
| 113 | +// InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms); |
| 114 | +// |
| 115 | +// Assert.IsNotNull(loadedInvoice.TradeLineItems); |
| 116 | +// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics.Count, 2); |
| 117 | +// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics[0].Description, "Test Description"); |
| 118 | +// Assert.AreEqual(loadedInvoice.TradeLineItems[0].ApplicableProductCharacteristics[1].Value, "3 kg"); |
| 119 | +end; |
| 120 | + |
| 121 | +initialization |
| 122 | + |
| 123 | +//I was hoping to use RTTI to discover the TestFixture classes, however unlike .NET |
| 124 | +//if we don't touch the class somehow then the linker will remove |
| 125 | +//the class from the resulting exe. |
| 126 | +//We could just do this: |
| 127 | +//TMyExampleTests.ClassName; |
| 128 | +//TExampleFixture2.ClassName; |
| 129 | +//which is enough to make the compiler link the classes into the exe, but that seems a |
| 130 | +//bit redundent so I guess we'll just use manual registration. If you use the |
| 131 | +//{$STRONGLINKTYPES ON} compiler directive then it will link the TestFixtures in and you |
| 132 | +//can use RTTI. The downside to that is the resulting exe will potentially much larger. |
| 133 | +//Not sure which version {$STRONGLINKTYPES ON} was introduced so we'll allow RTTI and |
| 134 | +//manual registration for now. |
| 135 | + |
| 136 | +end. |
0 commit comments