Skip to content
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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Comment on lines +1 to +6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused usings

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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of all this, can't you just use Assert.DoesNotThrow?

}
}

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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
Loading