Skip to content

Commit

Permalink
Add integration tests for Transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
anion0278 committed Jan 28, 2024
1 parent c482f3e commit 6f37af3
Show file tree
Hide file tree
Showing 25 changed files with 27,470 additions and 28 deletions.
4 changes: 3 additions & 1 deletion Mapp.BusinessLogic.Invoices.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
using Moq;
using VerifyXunit;
using Xunit;
using Xunit.Categories;

namespace Mapp.BusinessLogic.Invoices.Tests
{
[UsesVerify]
[IntegrationTest]
public class IntegrationTests: VerifyBase
{
// TODO add multi-file import test
Expand Down Expand Up @@ -82,7 +84,7 @@ private async Task IntegrationTestBase(string testCaseDataDirName, int startingO

ApplicationConstants.Rounding = 2; // TODO solve by intoducing settings context

var jsonManager = new JsonManager();
var jsonManager = new JsonManager(configMock.Object, new FileManager());
var invoiceXmlXmlManager = new InvoicesXmlManager(Mock.Of<IDialogService>(), configMock.Object) ;
var currencyLoader = new CsvLoader(configMock.Object);
var autocompleteDataLoader = new AutocompleteDataLoader(jsonManager, configMock.Object);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -16,6 +16,7 @@
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
<PackageReference Include="Verify.Xunit" Version="16.3.6" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.categories" Version="2.0.8" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
26 changes: 17 additions & 9 deletions Mapp.BusinessLogic.Invoices/Transactions/GpcGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mapp.Common;
using Mapp.DataAccess;

namespace Mapp.BusinessLogic.Transactions
{
Expand All @@ -16,21 +18,27 @@ public class GpcGenerator : IGpcGenerator
"0740000002001353907Czech Goods s.r.o. 01111900000013280900+00000016514842+000000461730770000000494070190011{0}FIO ";

private string _transactionBase = "07500000020013539{0}000000000000000000000000000000000{1}{2}{3}00000000000000000000000000{4}000124{5}";
private readonly IFileManager _fileManager;

public GpcGenerator(IFileManager fileManager)
{
_fileManager = fileManager;
}

public void SaveTransactions(IEnumerable<Transaction> transactions, string fileName)
{
DateTime endOfCurrentMonth = GetEndOfCurrentMonth();

string firstLine = string.Format(_intitialLine, endOfCurrentMonth.ToString("ddMMyy"));

using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName))
var outputText = new StringBuilder();

outputText.AppendLine(firstLine);
foreach (var transaction in transactions.Where(t => !t.Type.Equals(TransactionTypes.ServiceFee)))
{
file.WriteLine(firstLine);
foreach (var transaction in transactions.Where(t => !t.Type.Equals(TransactionTypes.ServiceFee)))
{
file.WriteLine(GetTransactionLine(transaction));
}
outputText.AppendLine(GetTransactionLine(transaction));
}
_fileManager.WriteAllTextToFile(fileName, outputText.ToString());
}

private string GetShortVariableCodeForRefund(string fullVariableCode) // TODO remove repetition
Expand All @@ -50,7 +58,7 @@ private string GetTransactionLine(Transaction transaction)
zerosRemoved = 0;
}

string type = ((int) transaction.Type).ToString();
string type = ((int)transaction.Type).ToString();
// in case that order ID contained zeros at the beginning
type = type.PadRight(type.Length + zerosRemoved, '0');

Expand All @@ -65,7 +73,7 @@ private string GetTransactionLine(Transaction transaction)
string formatted = string.Format(_transactionBase,
marketPlace,
price,
type,
type,
shortVariableCode,
orderId,
date);
Expand All @@ -78,7 +86,7 @@ private string GetTransactionLine(Transaction transaction)

private string FormatPrice(decimal price)
{
string priceFormatted = Math.Abs(price).ToString("N2").RemoveAll(".").RemoveAll(",").PadLeft(8,'0');
string priceFormatted = Math.Abs(price).ToString("N2").RemoveAll(".").RemoveAll(",").PadLeft(8, '0');
return priceFormatted;
}

Expand Down
17 changes: 7 additions & 10 deletions Mapp.BusinessLogic.Invoices/Transactions/TransactionsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ namespace Mapp.BusinessLogic.Transactions
public interface ITransactionsReader
{
IEnumerable<Transaction> ReadTransactionsFromMultipleFiles(IEnumerable<string> fileNames);
DateTime ParseDate(string dateString, MarketPlaceTransactionsConfig settings);
IEnumerable<Transaction> ReadTransactions(string fileName);
TransactionTypes ParseTransactionType(string transactionType, MarketPlaceTransactionsConfig settings);
}

public class TransactionsReader : ITransactionsReader
Expand Down Expand Up @@ -49,9 +46,9 @@ private IEnumerable<MarketPlaceTransactionsConfig> GetAvailableMarketplaceConfig
});
IMapper mapper = mapperConfiguration.CreateMapper();

var configDtos = _jsonManager.LoadTransactionsConfigs();
var configsData = _jsonManager.LoadTransactionsConfigs();

var configs = configDtos.Select<MarketPlaceTransactionsConfigDTO, MarketPlaceTransactionsConfig>(dto =>
var configs = configsData.Select(dto =>
mapper.Map<MarketPlaceTransactionsConfigDTO, MarketPlaceTransactionsConfig>(dto));

var marketPlaceIds = configs.Select(s => s.MarketPlaceId).ToList();
Expand Down Expand Up @@ -84,13 +81,13 @@ private IReadOnlyList<string[]> GetFileLines(string fileName, string encodingCod
return lineItems;
}

public DateTime ParseDate(string dateString, MarketPlaceTransactionsConfig settings)
private DateTime ParseDate(string dateString, MarketPlaceTransactionsConfig config)
{
var match = Regex.Match(dateString, settings.DateSubstring);
return DateTime.Parse(match.Groups[1].Value, settings.DateCultureInfo);
var match = Regex.Match(dateString, config.DateSubstring);
return DateTime.Parse(match.Groups[1].Value, config.DateCultureInfo);
}

public IEnumerable<Transaction> ReadTransactions(string fileName)
private IEnumerable<Transaction> ReadTransactions(string fileName)
{
var lines = GetFileLines(fileName);

Expand Down Expand Up @@ -174,7 +171,7 @@ public IEnumerable<Transaction> ReadTransactions(string fileName)
return transactions;
}

public TransactionTypes ParseTransactionType(string transactionType, MarketPlaceTransactionsConfig settings)
private TransactionTypes ParseTransactionType(string transactionType, MarketPlaceTransactionsConfig settings)
{
// TODO refactoring AWFUL CODE
if (settings.OrderTypeNames.Any(n => n.EqualsIgnoreCase(transactionType)))
Expand Down
Loading

0 comments on commit 6f37af3

Please sign in to comment.