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

Add batuz dtos #218

wants to merge 22 commits into from

Conversation

inakiesteve
Copy link
Contributor

Description

Implemented DTOS for the Batuz integration. Includes a preliminary version of the Models which will be improved in the future. Basic unit tests have been included to test: Dto serialization and deserialization (when applicable) and XSD validation.

Fixes https://mews.atlassian.net/browse/OPS-1744

Type of change

  • Bug fix.
  • [ x ] Feature.
  • Consolidation.

Checklist

  • Is breaking change.
  • Documentation updated.
  • [ x ] Tests included (please specify cases).
    Test cases: DTO serialization and deserialization, XSD validation after serializing.

Copy link
Contributor

@abdallahbeshi abdallahbeshi left a comment

Choose a reason for hiding this comment

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

Isn't there a way to split this PR into multiple smaller PRs?

reviewing 14k lines of code at once is not a good idea.

Comment on lines +1 to +6
using FuncSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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

Comment on lines +14 to +17
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";
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

Comment on lines +20 to +55
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
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);

}
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)

Comment on lines +1 to +6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
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

Comment on lines +1 to +4
using System;
using System.Collections.Generic;
using System.Security;
using System.Xml.Serialization;
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

Comment on lines +12 to +15
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";
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

Comment on lines +57 to +69
private bool XmlSerializationSucceeds(LROEPJ240FacturasEmitidasConSGAltaPeticion batuzInvoiceRequest, out XmlElement? xmlElement)
{
try
{
xmlElement = XmlSerializationHelper<LROEPJ240FacturasEmitidasConSGAltaPeticion>.Serialize(batuzInvoiceRequest, Array.Empty<string>());
return true;
}
catch
{
xmlElement = null;
return false;
}
}
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?


namespace Mews.Fiscalizations.Bizkaia.Tests
{
public static class XmlSerializationHelper<T> where T: class
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use the Xml helpers in the Core library?

[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

@inakiesteve inakiesteve closed this Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants