diff --git a/advanced_template.zip b/advanced_template.zip index d5d85d9..50bd9d9 100644 Binary files a/advanced_template.zip and b/advanced_template.zip differ diff --git a/basic_template.zip b/basic_template.zip deleted file mode 100644 index cf100db..0000000 Binary files a/basic_template.zip and /dev/null differ diff --git a/soap_template.zip b/soap_template.zip deleted file mode 100644 index 98da3f1..0000000 Binary files a/soap_template.zip and /dev/null differ diff --git a/templates/advanced/OutSystems.IbanChecker.UnitTests/IbanCheckerTests.cs b/templates/advanced/OutSystems.IbanChecker.UnitTests/IbanCheckerTests.cs index fb2698a..4041b02 100644 --- a/templates/advanced/OutSystems.IbanChecker.UnitTests/IbanCheckerTests.cs +++ b/templates/advanced/OutSystems.IbanChecker.UnitTests/IbanCheckerTests.cs @@ -1,5 +1,6 @@ using IbanNet; using IbanNet.Registry; +using Microsoft.Extensions.Logging; using NUnit.Framework; using OutSystems.ExternalLibraries.SDK; using Iban = OutSystems.IbanChecker.Structures.Iban; @@ -78,7 +79,8 @@ public void IbanCheckerCorrectlyParsesValidIban() { // valid IBAN string using the IbanParser. var parser = new IbanParser(IbanRegistry.Default); var iban = parser.Parse("NL91 ABNA 0417 1643 00"); - var checker = new IbanChecker(); + var logger = new LoggerFactory().CreateLogger(); + var checker = new IbanChecker(logger); // Act: Parse a sample valid IBAN string using the IbanChecker. var ibanStruct = checker.Parse("NL91 ABNA 0417 1643 00"); @@ -99,7 +101,8 @@ public void IbanCheckerCorrectlyTryParsesValidIban() { // valid IBAN string using the IbanParser. var parser = new IbanParser(IbanRegistry.Default); var iban = parser.Parse("NL91 ABNA 0417 1643 00"); - var checker = new IbanChecker(); + var logger = new LoggerFactory().CreateLogger(); + var checker = new IbanChecker(logger); // Act: Try to parse a sample valid IBAN string using the IbanChecker and // check for success. @@ -122,8 +125,9 @@ public void IbanCheckerCorrectlyTryParsesValidIban() { // [Test] public void IbanCheckerCorrectlyTryParsesInvalidIban() { + var logger = new LoggerFactory().CreateLogger(); // Setup: Instantiate a new IbanChecker. - var checker = new IbanChecker(); + var checker = new IbanChecker(logger); // Act: Try to parse a sample invalid IBAN string using the IbanChecker and // check for failure. @@ -145,8 +149,9 @@ public void IbanCheckerCorrectlyTryParsesInvalidIban() { /// [Test] public void IbanCheckerCorrectlyValidatesIbanFromRejectedCountry() { + var logger = new LoggerFactory().CreateLogger(); // Setup: Instantiate a new IbanChecker. - var checker = new IbanChecker(); + var checker = new IbanChecker(logger); // Act: Validate an IBAN using the IbanChecker, providing a list of // rejected countries. @@ -169,8 +174,9 @@ public void IbanCheckerCorrectlyValidatesIbanFromRejectedCountry() { /// [Test] public void IbanCheckerCorrectlyValidatesIbanFromAcceptedCountry() { + var logger = new LoggerFactory().CreateLogger(); // Setup: Instantiate a new IbanChecker. - var checker = new IbanChecker(); + var checker = new IbanChecker(logger); // Act: Validate an IBAN using the IbanChecker, providing a list of // rejected countries that does not include the IBAN's country code. diff --git a/templates/advanced/OutSystems.IbanChecker/IbanChecker.cs b/templates/advanced/OutSystems.IbanChecker/IbanChecker.cs index c26a861..084581b 100644 --- a/templates/advanced/OutSystems.IbanChecker/IbanChecker.cs +++ b/templates/advanced/OutSystems.IbanChecker/IbanChecker.cs @@ -2,6 +2,7 @@ using System.Linq; using IbanNet; using IbanNet.Registry; +using Microsoft.Extensions.Logging; namespace OutSystems.IbanChecker { /// @@ -23,12 +24,20 @@ public class IbanChecker : IIbanChecker { private IIbanValidator _validator; /// - /// The constructor initializes the IbanChecker class with new instances + /// An instance of ILogger from the Microsoft.Extensions.Logging library, used for + /// logging. + /// + private readonly ILogger _logger; + + /// + /// The constructor initializes the IbanChecker class with the specified logger and creates new instances /// of the IbanParser and IbanValidator classes from the IbanNet library. /// - public IbanChecker() { + /// The logger instance used for logging operations within the IbanChecker. + public IbanChecker(ILogger logger) { _validator = new IbanValidator(); _parser = new IbanParser(_validator); + _logger = logger; } /// @@ -40,6 +49,7 @@ public IbanChecker() { /// An Iban struct representing the parsed IBAN. /// Thrown if the parsing fails. public Structures.Iban Parse(string value) { + _logger.LogInformation("Parsing IBAN: {IbanValue}", value); return new Structures.Iban(_parser.Parse(value)); } @@ -56,8 +66,10 @@ public bool TryParse(string value, out Structures.Iban? iban) { IbanNet.Iban? internalIban; if (_parser.TryParse(value, out internalIban)) { iban = new Structures.Iban(internalIban); + _logger.LogInformation("Successfully parsed IBAN: {IbanValue}", value); return true; } + _logger.LogWarning("Failed to parse IBAN: {IbanValue}", value); return false; } @@ -75,8 +87,10 @@ public Structures.ValidationResult Validate(string iban, IEnumerable? re var validatorWithRejectedCountries = new IbanValidator(new IbanValidatorOptions { Rules = { new CustomRules.RejectCountryRule(rejectedCountries) } }); + _logger.LogInformation("Validating IBAN: {IbanValue} with rejected countries: {RejectedCountries}", iban, rejectedCountries); return new Structures.ValidationResult(validatorWithRejectedCountries.Validate(iban)); } + _logger.LogInformation("Validating IBAN: {IbanValue} with default rules", iban); return new Structures.ValidationResult(_validator.Validate(iban)); } @@ -94,12 +108,16 @@ public string Format(Structures.Iban iban, string? format = null) { var ibanBuilder = new IbanNet.Builders.IbanBuilder(); IbanRegistry.Default.TryGetValue(iban.Country.TwoLetterISORegionName, out IbanCountry? country); if (country == null) { - throw new System.Exception("Invalid country: " + iban.Country.TwoLetterISORegionName); - } + var errorMessage = "Invalid country: " + iban.Country.TwoLetterISORegionName; + _logger.LogError("Failed to format IBAN. {ErrorMessage}.", errorMessage); + throw new System.Exception(errorMessage); + } var ib = _parser.Parse(ibanBuilder .WithCountry(country) .WithBankAccountNumber(iban.Bban) .Build()); + _logger.LogInformation("Formatting IBAN for country: {CountryCode} with format: {Format}.", + iban.Country.TwoLetterISORegionName, format ?? ""); return ib.ToString(format); } } diff --git a/templates/advanced/OutSystems.IbanChecker/OutSystems.IbanChecker.csproj b/templates/advanced/OutSystems.IbanChecker/OutSystems.IbanChecker.csproj index 216f82a..5253e21 100644 --- a/templates/advanced/OutSystems.IbanChecker/OutSystems.IbanChecker.csproj +++ b/templates/advanced/OutSystems.IbanChecker/OutSystems.IbanChecker.csproj @@ -8,6 +8,7 @@ +