-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add batuz dtos #218
Add batuz dtos #218
Changes from all commits
80ca39b
2e0d9fa
015b996
b027920
f8b71c4
96c638b
a52aa5c
bed34d5
bdb031d
84cf268
b4eb0f6
f4cc65e
fe39250
4ed6a6a
2694cc9
b23b992
400264f
e7cbc3f
c99e85e
775f027
2f9688d
874293f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using FuncSharp; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml; | ||
|
||
namespace Mews.Fiscalizations.Bizkaia.Tests | ||
{ | ||
[TestFixture] | ||
public class BatuzInvoiceRequestDtoValidationTests | ||
{ | ||
private const string BatuzXsdFilename = @"./Xsd/LROE_PJ_240_1_1_FacturasEmitidas_ConSG_AltaPeticion_V1_0_2.xsd"; | ||
private const string BatuzTiposComplejosFilename = @"./Xsd/batuz_TiposComplejos.xsd"; | ||
private const string BatuzEnumeradosFilename = @"./Xsd/batuz_Enumerados.xsd"; | ||
private const string BatuzTiposBasicosFilename = @"./Xsd/batuz_TiposBasicos.xsd"; | ||
Comment on lines
+14
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant verbatim string prefix |
||
|
||
[Test] | ||
public void CreateTBatuzInvoiceDto_XmlSerialization_Succeeds() | ||
{ | ||
//Arrange create a dto that matches the samples provided by the Bizkaia authorities | ||
var batuzInvoiceRequest = BatuzInvoiceRequestHelper.CreateSampleBatuzRequest(); | ||
|
||
//act check that xml serialization of the ticketBai succeeds without errors | ||
bool serializationSucceeds = XmlSerializationSucceeds(batuzInvoiceRequest, out XmlElement xmlElement); | ||
|
||
//assert that xml serialization was possible | ||
Assert.True(serializationSucceeds); | ||
Assert.NotNull(xmlElement); | ||
} | ||
|
||
[Test] | ||
public void CreateTicketBaiInvoice_XsdValidation_Succeeds() | ||
{ | ||
//Arrange create a dto that matches the samples provided by the Bizkaia authorities | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't really add the AAA comments for every single test |
||
var batuzInvoiceRequest = BatuzInvoiceRequestHelper.CreateSampleBatuzRequest(); | ||
var schemas = new Dictionary<string, string> | ||
{ | ||
{"https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/LROE_PJ_240_1_1_FacturasEmitidas_ConSG_AltaPeticion_V1_0_2.xsd", BatuzXsdFilename }, | ||
{"https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/batuz_TiposComplejos.xsd", BatuzTiposComplejosFilename }, | ||
{"https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/batuz_Enumerados.xsd", BatuzEnumeradosFilename }, | ||
{"https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/batuz_TiposBasicos.xsd", BatuzTiposBasicosFilename } | ||
}; | ||
|
||
//act check that xml serialization of the ticketBai succeeds without errors | ||
bool serializationSucceeds = XmlSerializationSucceeds(batuzInvoiceRequest, out XmlElement xmlElement); | ||
//assert that xml serialization was possible | ||
Assert.True(serializationSucceeds); | ||
|
||
bool xsdValidationSucceeds = XmlSchemaHelper.XmlSchemaValidationSucceeds(element: xmlElement, | ||
validatingXsdFilename: BatuzXsdFilename, schemas); | ||
Assert.True(xsdValidationSucceeds); | ||
|
||
} | ||
Comment on lines
+20
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the purpose of these tests? wouldn't these test cases get covered later on when you create tests for sending an invoice? (like the other fiscalizations)? and how frequently does these XSDs change? its just once when you import them, and if there will be an update one day, you will just import the new one and verify that your solution works using the other tests (like send_invoice_succeeds..etc) |
||
|
||
private bool XmlSerializationSucceeds(LROEPJ240FacturasEmitidasConSGAltaPeticion batuzInvoiceRequest, out XmlElement? xmlElement) | ||
{ | ||
try | ||
{ | ||
xmlElement = XmlSerializationHelper<LROEPJ240FacturasEmitidasConSGAltaPeticion>.Serialize(batuzInvoiceRequest, Array.Empty<string>()); | ||
return true; | ||
} | ||
catch | ||
{ | ||
xmlElement = null; | ||
return false; | ||
} | ||
} | ||
Comment on lines
+57
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of all this, can't you just use |
||
} | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Security; | ||
using System.Xml.Serialization; | ||
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused usings |
||
|
||
namespace Mews.Fiscalizations.Bizkaia.Tests; | ||
|
||
|
||
[TestFixture] | ||
public class BatuzInvoiceResponseDeserializationTests | ||
{ | ||
private const string CorrectResponseFilename = @"./Documents/LROE_240_FacturasEmitidasConSG_Correcta.xml"; | ||
private const string PartiallyCorrectResponseFilename = @"./Documents/LROE_240_FacturasEmitidasConSG_Parc_Correcta.xml"; | ||
private const string IncorrectResponseFilename = @"./Documents/LROE_240_FacturasEmitidasConSG_Incorrecta.xml"; | ||
private const string TicketBaiFilename = @"./Documents/ticketBai.xml"; | ||
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant verbatim string prefix |
||
private const string OkStatus = "Correcto"; | ||
private const string FailedStatus = "Incorrecto"; | ||
private const int NumberOfRecords = 2; | ||
|
||
[Test] | ||
public void CorrectResponse_Deserialization_Succeeds() | ||
{ | ||
LROEPJ240FacturasEmitidasConSGAltaRespuesta response = XmlSerializationHelper<LROEPJ240FacturasEmitidasConSGAltaRespuesta>. | ||
Deserialize(CorrectResponseFilename); | ||
|
||
Assert.IsNotNull(response); | ||
Assert.True(response.Registros.Length == NumberOfRecords); | ||
|
||
Assert.True(response.Registros.All(registro => registro.SituacionRegistro.EstadoRegistro.Equals(OkStatus))); | ||
} | ||
|
||
[Test] | ||
public void PartiallyCorrectResponse_Deserialization_Succeeds() | ||
{ | ||
LROEPJ240FacturasEmitidasConSGAltaRespuesta response = XmlSerializationHelper<LROEPJ240FacturasEmitidasConSGAltaRespuesta>. | ||
Deserialize(PartiallyCorrectResponseFilename); | ||
|
||
Assert.IsNotNull(response); | ||
Assert.True(response.Registros.Length == NumberOfRecords); | ||
|
||
//first registro is correct | ||
var firstRecord = response.Registros.First(); | ||
Assert.True(firstRecord.SituacionRegistro.EstadoRegistro.Equals(OkStatus)); | ||
|
||
//second registro is incorrect | ||
var secondRecord = response.Registros.Last(); | ||
Assert.True(secondRecord.SituacionRegistro.EstadoRegistro.Equals(FailedStatus)); | ||
} | ||
|
||
[Test] | ||
public void IncorrectResponse_Deserialization_Succeeds() | ||
{ | ||
LROEPJ240FacturasEmitidasConSGAltaRespuesta response = XmlSerializationHelper<LROEPJ240FacturasEmitidasConSGAltaRespuesta>. | ||
Deserialize(IncorrectResponseFilename); | ||
|
||
Assert.IsNotNull(response); | ||
Assert.True(response.Registros.Length == NumberOfRecords); | ||
Assert.True(response.Registros.All(registro => registro.SituacionRegistro.EstadoRegistro.Equals(FailedStatus))); | ||
} | ||
|
||
[Test] | ||
public void WrongFileFormat_Deserialization_Fails() | ||
{ | ||
Assert.Throws<InvalidOperationException>(() => | ||
{ | ||
XmlSerializationHelper<LROEPJ240FacturasEmitidasConSGAltaRespuesta>. | ||
Deserialize(TicketBaiFilename); | ||
}); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<ns2:LROEPJ240FacturasEmitidasConSGAltaRespuesta xmlns:ns2="https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/LROE_PJ_240_1_1_FacturasEmitidas_ConSG_AltaRespuesta_V1_0_1.xsd"> | ||
<Cabecera> | ||
<Modelo>240</Modelo> | ||
<Capitulo>1</Capitulo> | ||
<Subcapitulo>1.1</Subcapitulo> | ||
<Operacion>A00</Operacion> | ||
<Version>1.0</Version> | ||
<Ejercicio>2022</Ejercicio> | ||
<ObligadoTributario> | ||
<NIF>B00000034</NIF> | ||
<ApellidosNombreRazonSocial>HOTEL ADIBIDEZ</ApellidosNombreRazonSocial> | ||
</ObligadoTributario> | ||
</Cabecera> | ||
<DatosPresentacion> | ||
<FechaPresentacion>28-04-2020 16:56:36</FechaPresentacion> | ||
<NIFPresentador>B00000034</NIFPresentador> | ||
</DatosPresentacion> | ||
<Registros> | ||
<Registro> | ||
<Identificador> | ||
<IDFactura> | ||
<SerieFactura>B2022</SerieFactura> | ||
<NumFactura>0100</NumFactura> | ||
<FechaExpedicionFactura>30-01-2022</FechaExpedicionFactura> | ||
</IDFactura> | ||
</Identificador> | ||
<SituacionRegistro> | ||
<EstadoRegistro>Correcto</EstadoRegistro> | ||
</SituacionRegistro> | ||
</Registro> | ||
<Registro> | ||
<Identificador> | ||
<IDFactura> | ||
<SerieFactura>B2022</SerieFactura> | ||
<NumFactura>0101</NumFactura> | ||
<FechaExpedicionFactura>05-02-2022</FechaExpedicionFactura> | ||
</IDFactura> | ||
</Identificador> | ||
<SituacionRegistro> | ||
<EstadoRegistro>Correcto</EstadoRegistro> | ||
</SituacionRegistro> | ||
</Registro> | ||
</Registros> | ||
</ns2:LROEPJ240FacturasEmitidasConSGAltaRespuesta> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<ns2:LROEPJ240FacturasEmitidasConSGAltaRespuesta | ||
xmlns:ns2="https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/LROE_PJ_240_1_1_FacturasEmitidas_ConSG_AltaRespuesta_V1_0_1.xsd"> | ||
<Cabecera> | ||
<Modelo>240</Modelo> | ||
<Capitulo>1</Capitulo> | ||
<Subcapitulo>1.1</Subcapitulo> | ||
<Operacion>A00</Operacion> | ||
<Version>1.0</Version> | ||
<Ejercicio>2022</Ejercicio> | ||
<ObligadoTributario> | ||
<NIF>B00000034</NIF> | ||
<ApellidosNombreRazonSocial>HOTEL ADIBIDEZ</ApellidosNombreRazonSocial> | ||
</ObligadoTributario> | ||
</Cabecera> | ||
<Registros> | ||
<Registro> | ||
<Identificador> | ||
<IDFactura> | ||
<SerieFactura>B2022</SerieFactura> | ||
<NumFactura>0100</NumFactura> | ||
<FechaExpedicionFactura>30-01-2022</FechaExpedicionFactura> | ||
</IDFactura> | ||
</Identificador> | ||
<SituacionRegistro> | ||
<EstadoRegistro>Incorrecto</EstadoRegistro> | ||
<CodigoErrorRegistro>B4_2000003</CodigoErrorRegistro> | ||
<DescripcionErrorRegistroES>Registro duplicado.</DescripcionErrorRegistroES> | ||
<DescripcionErrorRegistroEU>Erregistro bikoiztua.</DescripcionErrorRegistroEU> | ||
</SituacionRegistro> | ||
</Registro> | ||
<Registro> | ||
<Identificador> | ||
<IDFactura> | ||
<SerieFactura>B2022</SerieFactura> | ||
<NumFactura>0101</NumFactura> | ||
<FechaExpedicionFactura>05-02-2022</FechaExpedicionFactura> | ||
</IDFactura> | ||
</Identificador> | ||
<SituacionRegistro> | ||
<EstadoRegistro>Incorrecto</EstadoRegistro> | ||
<CodigoErrorRegistro>B4_2000003</CodigoErrorRegistro> | ||
<DescripcionErrorRegistroES>Registro duplicado.</DescripcionErrorRegistroES> | ||
<DescripcionErrorRegistroEU>Erregistro bikoiztua.</DescripcionErrorRegistroEU> | ||
</SituacionRegistro> | ||
</Registro> | ||
</Registros> | ||
</ns2:LROEPJ240FacturasEmitidasConSGAltaRespuesta> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<ns2:LROEPJ240FacturasEmitidasConSGAltaRespuesta | ||
xmlns:ns2="https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/LROE_PJ_240_1_1_FacturasEmitidas_ConSG_AltaRespuesta_V1_0_1.xsd"> | ||
<Cabecera> | ||
<Modelo>240</Modelo> | ||
<Capitulo>1</Capitulo> | ||
<Subcapitulo>1.1</Subcapitulo> | ||
<Operacion>A00</Operacion> | ||
<Version>1.0</Version> | ||
<Ejercicio>2022</Ejercicio> | ||
<ObligadoTributario> | ||
<NIF>B00000034</NIF> | ||
<ApellidosNombreRazonSocial>HOTEL ADIBIDEZ</ApellidosNombreRazonSocial> | ||
</ObligadoTributario> | ||
</Cabecera> | ||
<DatosPresentacion> | ||
<FechaPresentacion>28-04-2020 16:56:36</FechaPresentacion> | ||
<NIFPresentador>B00000034</NIFPresentador> | ||
</DatosPresentacion> | ||
<Registros> | ||
<Registro> | ||
<Identificador> | ||
<IDFactura> | ||
<SerieFactura>B2022</SerieFactura> | ||
<NumFactura>0100</NumFactura> | ||
<FechaExpedicionFactura>30-01-2022</FechaExpedicionFactura> | ||
</IDFactura> | ||
</Identificador> | ||
<SituacionRegistro> | ||
<EstadoRegistro>Correcto</EstadoRegistro> | ||
</SituacionRegistro> | ||
</Registro> | ||
<Registro> | ||
<Identificador> | ||
<IDFactura> | ||
<SerieFactura>B2022</SerieFactura> | ||
<NumFactura>0101</NumFactura> | ||
<FechaExpedicionFactura>05-02-2022</FechaExpedicionFactura> | ||
</IDFactura> | ||
</Identificador> | ||
<SituacionRegistro> | ||
<EstadoRegistro>Incorrecto</EstadoRegistro> | ||
<CodigoErrorRegistro>B4_2000003</CodigoErrorRegistro> | ||
<DescripcionErrorRegistroES>Registro duplicado.</DescripcionErrorRegistroES> | ||
<DescripcionErrorRegistroEU>Erregistro bikoiztua.</DescripcionErrorRegistroEU> | ||
</SituacionRegistro> | ||
</Registro> | ||
</Registros> | ||
</ns2:LROEPJ240FacturasEmitidasConSGAltaRespuesta> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused usings