Skip to content

Commit

Permalink
Rfx Empiria.Assertion new interface was applied
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcota committed May 29, 2022
1 parent fb19d6c commit f378253
Show file tree
Hide file tree
Showing 156 changed files with 600 additions and 595 deletions.
2 changes: 1 addition & 1 deletion BalanceEngine/BalanceExplorer/Adapters/BalanceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static private FixedList<IBalanceEntryDto> MapToDto(
return new FixedList<IBalanceEntryDto>(mappedItems);

default:
throw Assertion.AssertNoReachThisCode(
throw Assertion.EnsureNoReachThisCode(
$"Unhandled balance type {command.TrialBalanceType}.");
}
}
Expand Down
4 changes: 2 additions & 2 deletions BalanceEngine/BalanceExplorer/Domain/Balance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class Balance {
#region Constructors and parsers

internal Balance(BalanceCommand command, FixedList<BalanceEntry> entries) {
Assertion.AssertObject(command, "command");
Assertion.AssertObject(entries, "entries");
Assertion.Require(command, "command");
Assertion.Require(entries, "entries");

Command = command;
Entries = entries;
Expand Down
4 changes: 2 additions & 2 deletions BalanceEngine/BalanceExplorer/Domain/BalanceConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Empiria.FinancialAccounting.BalanceEngine {
internal class BalanceConstructor {

internal BalanceConstructor(BalanceCommand command){
Assertion.AssertObject(command, "command");
Assertion.Require(command, "command");

Command = command;
}
Expand Down Expand Up @@ -56,7 +56,7 @@ internal Balance GenerateBalance() {
return saldosPorCuenta.Build();

default:
throw Assertion.AssertNoReachThisCode(
throw Assertion.EnsureNoReachThisCode(
$"Unhandled trial balance type {this.Command.TrialBalanceType}.");
}
}
Expand Down
2 changes: 1 addition & 1 deletion BalanceEngine/BalanceExplorer/UseCases/BalanceUseCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static public BalanceUseCases UseCaseInteractor() {
#endregion Constructors and parsers

public BalanceDto BuildBalanceSearch(BalanceCommand command) {
Assertion.AssertObject(command, "command");
Assertion.Require(command, "command");

var balanceConstructor = new BalanceConstructor(command);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ private bool ValidateEntryForSummaryParentAccount(TrialBalanceEntry entry,
return false;

} else {
throw Assertion.AssertNoReachThisCode();
throw Assertion.EnsureNoReachThisCode();
}
return true;
}
Expand Down Expand Up @@ -507,8 +507,9 @@ private void ValuateAccountEntriesToExchangeRate(FixedList<TrialBalanceEntry> en
a => a.FromCurrency.Code == _command.InitialPeriod.ValuateToCurrrencyUID &&
a.ToCurrency.Code == entry.Currency.Code);

Assertion.AssertObject(exchangeRate, $"No se ha registrado el tipo de cambio para la " +
$"moneda {entry.Currency.FullName} con la fecha proporcionada.");
// ToDo: URGENT This require must be checked before any state change
Assertion.Require(exchangeRate, $"No se ha registrado el tipo de cambio para la " +
$"moneda {entry.Currency.FullName} con la fecha proporcionada.");

entry.MultiplyBy(exchangeRate.Value);
}
Expand Down
4 changes: 2 additions & 2 deletions BalanceEngine/Commons/Data/BalancesDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static internal class BalancesDataService {


static internal FixedList<TrialBalanceEntry> GetTrialBalanceEntries(BalanceCommand command) {
Assertion.AssertObject(command, nameof(command));
Assertion.Require(command, nameof(command));

BalancesSqlClauses sqlClauses = BalancesSqlClauses.BuildFrom(command);

Expand All @@ -30,7 +30,7 @@ static internal FixedList<TrialBalanceEntry> GetTrialBalanceEntries(BalanceComma


static internal FixedList<TrialBalanceEntry> GetTrialBalanceEntries(TrialBalanceCommand command) {
Assertion.AssertObject(command, nameof(command));
Assertion.Require(command, nameof(command));

BalancesSqlClauses sqlClauses = BalancesSqlClauses.BuildFrom(command);

Expand Down
4 changes: 2 additions & 2 deletions BalanceEngine/Commons/Data/BalancesSqlClauses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private BalancesSqlClauses() {


static internal BalancesSqlClauses BuildFrom(TrialBalanceCommand command) {
Assertion.AssertObject(command, nameof(command));
Assertion.Require(command, nameof(command));

var builder = new BalancesSqlClausesBuilder(command);

Expand All @@ -34,7 +34,7 @@ static internal BalancesSqlClauses BuildFrom(TrialBalanceCommand command) {


static internal BalancesSqlClauses BuildFrom(BalanceCommand command) {
Assertion.AssertObject(command, nameof(command));
Assertion.Require(command, nameof(command));

TrialBalanceCommand trialBalanceCommand = CopyToTrialBalanceCommand(command);

Expand Down
14 changes: 7 additions & 7 deletions BalanceEngine/Commons/Data/BalancesSqlClausesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sealed private class BalancesSqlClausesBuilder {
private readonly TrialBalanceCommand _command;

internal BalancesSqlClausesBuilder(TrialBalanceCommand command) {
Assertion.AssertObject(command, nameof(command));
Assertion.Require(command, nameof(command));

this._command = PrepareCommand(command);
}
Expand Down Expand Up @@ -147,7 +147,7 @@ private string GetWhereClause() {
return "WHERE DEBE <> 0 OR HABER <> 0";
}

throw Assertion.AssertNoReachThisCode();
throw Assertion.EnsureNoReachThisCode();
}


Expand All @@ -169,7 +169,7 @@ private string GetInitialFields() {
return "ID_MAYOR, ID_MONEDA, ID_CUENTA_ESTANDAR, ID_SECTOR, ID_CUENTA_AUXILIAR, ";
}

throw Assertion.AssertNoReachThisCode();
throw Assertion.EnsureNoReachThisCode();
}


Expand All @@ -192,7 +192,7 @@ private string GetInitialGroupingClause() {
return "GROUP BY ID_MAYOR, ID_MONEDA, ID_CUENTA_ESTANDAR, ID_SECTOR, ID_CUENTA_AUXILIAR";
}

throw Assertion.AssertNoReachThisCode();
throw Assertion.EnsureNoReachThisCode();
}


Expand All @@ -205,7 +205,7 @@ private string GetOrderClause() {
return "ORDER BY ID_MAYOR, ID_MONEDA, NUMERO_CUENTA_ESTANDAR, ID_SECTOR";
}

throw Assertion.AssertNoReachThisCode();
throw Assertion.EnsureNoReachThisCode();
}


Expand Down Expand Up @@ -242,7 +242,7 @@ private string GetOutputFields() {

}

throw Assertion.AssertNoReachThisCode();
throw Assertion.EnsureNoReachThisCode();
}


Expand Down Expand Up @@ -279,7 +279,7 @@ private string GetAccountRangeFilter() {
$"NUMERO_CUENTA_ESTANDAR LIKE '{_command.ToAccount}%')";
}

throw Assertion.AssertNoReachThisCode();
throw Assertion.EnsureNoReachThisCode();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static public TrialBalanceComparatorUseCases UseCaseInteractor() {
#region Use cases

public TrialBalanceDto BuildBalances(TrialBalanceCommand command) {
Assertion.AssertObject(command, "command");
Assertion.Require(command, "command");

var trialBalanceEngine = new TrialBalanceEngine(command);

Expand Down
10 changes: 5 additions & 5 deletions BalanceEngine/Commons/UseCases/TrialBalanceUseCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ static public TrialBalanceUseCases UseCaseInteractor() {
#region Use cases

public async Task<AnaliticoDeCuentasDto> BuildAnaliticoDeCuentas(TrialBalanceCommand command) {
Assertion.AssertObject(command, "command");
Assertion.Require(command, "command");

Assertion.Assert(command.TrialBalanceType == TrialBalanceType.AnaliticoDeCuentas,
Assertion.Require(command.TrialBalanceType == TrialBalanceType.AnaliticoDeCuentas,
"command.TrialBalanceType must be 'AnaliticoDeCuentas'.");

var builder = new AnaliticoDeCuentasBuilder(command);
Expand All @@ -52,9 +52,9 @@ public async Task<AnaliticoDeCuentasDto> BuildAnaliticoDeCuentas(TrialBalanceCom


public async Task<BalanzaTradicionalDto> BuildBalanzaTradicional(TrialBalanceCommand command) {
Assertion.AssertObject(command, "command");
Assertion.Require(command, "command");

Assertion.Assert(command.TrialBalanceType == TrialBalanceType.Balanza,
Assertion.Require(command.TrialBalanceType == TrialBalanceType.Balanza,
"command.TrialBalanceType must be 'Balanza'.");

var builder = new BalanzaTradicionalBuilder(command);
Expand All @@ -65,7 +65,7 @@ public async Task<BalanzaTradicionalDto> BuildBalanzaTradicional(TrialBalanceCom


public TrialBalanceDto BuildTrialBalance(TrialBalanceCommand command) {
Assertion.AssertObject(command, "command");
Assertion.Require(command, "command");

var trialBalanceEngine = new TrialBalanceEngine(command);

Expand Down
2 changes: 1 addition & 1 deletion BalanceEngine/TrialBalances/Adapters/TrialBalanceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static private FixedList<ITrialBalanceEntryDto> Map(TrialBalanceCommand command,
return new FixedList<ITrialBalanceEntryDto>(mappedItemsComparative);

default:
throw Assertion.AssertNoReachThisCode(
throw Assertion.EnsureNoReachThisCode(
$"Unhandled trial balance type {command.TrialBalanceType}.");
}
}
Expand Down
20 changes: 10 additions & 10 deletions BalanceEngine/TrialBalances/Domain/EnsureBalanceValidations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void CheckSummaryEntriesIsEqualToTotalByGroup(FixedList<ITrialBalanceEnt
x.Currency.Code == debtorGroup.Currency.Code)
.Sum(x => x.CurrentBalance);

Assertion.Assert(Math.Abs(debtorGroup.CurrentBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
Assertion.Require(Math.Abs(debtorGroup.CurrentBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
$"La suma del saldo actual de las cuentas no es igual al total por grupo " +
$"en {debtorGroup.GroupName} con naturaleza {debtorGroup.DebtorCreditor}, " +
$"Total de cuentas: {entriesTotal}, Total del grupo: {debtorGroup.CurrentBalance}");
Expand All @@ -91,7 +91,7 @@ private void CheckSummaryEntriesIsEqualToTotalByGroup(FixedList<ITrialBalanceEnt
x.Currency.Code == creditorGroup.Currency.Code)
.Sum(x => x.CurrentBalance);

Assertion.Assert(Math.Abs(creditorGroup.CurrentBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
Assertion.Require(Math.Abs(creditorGroup.CurrentBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
$"La suma del saldo actual de las cuentas no es igual al total por grupo " +
$"en {creditorGroup.GroupName} con naturaleza {creditorGroup.DebtorCreditor}, " +
$"Total de cuentas: {entriesTotal}, Total del grupo: {creditorGroup.CurrentBalance}");
Expand Down Expand Up @@ -130,7 +130,7 @@ private void CheckTotalsByDebtorAndCreditorEntries(FixedList<ITrialBalanceEntry>
decimal totalDebit = totalDebtorDebit + totalCreditorDebit;
decimal totalCredit = totalDebtorCredit + totalCreditorCredit;

Assertion.Assert(Math.Abs(totalDebit - totalCredit) <= MAX_BALANCE_DIFFERENCE,
Assertion.Require(Math.Abs(totalDebit - totalCredit) <= MAX_BALANCE_DIFFERENCE,
$"La suma de cargos totales ({totalDebit}) no es igual a la suma de abonos totales ({totalCredit}) de la balanza, o excede el " +
$"límite máximo de {MAX_BALANCE_DIFFERENCE} pesos de diferencia.");
}
Expand Down Expand Up @@ -166,7 +166,7 @@ private void CheckTotalsByGroupEntriesInBalanza(List<TrialBalanceEntry> entries)
x => x.ItemType == TrialBalanceItemType.BalanceTotalGroupCreditor)
.Sum(x => x.CurrentBalance);

Assertion.Assert(Math.Abs(totalByGroupDebtor - totalByGroupCreditor) <= MAX_BALANCE_DIFFERENCE,
Assertion.Require(Math.Abs(totalByGroupDebtor - totalByGroupCreditor) <= MAX_BALANCE_DIFFERENCE,
"La suma de saldos del total de cuentas deudoras no es igual al de las cuentas acreedoras, " +
$"o excede el límite máximo de {MAX_BALANCE_DIFFERENCE} pesos de diferencia.");
}
Expand All @@ -186,7 +186,7 @@ private void CheckTotalsConsolidated(FixedList<ITrialBalanceEntry> entriesList)
x => x.ItemType == TrialBalanceItemType.BalanceTotalConsolidated)
.Sum(x => x.CurrentBalance);

Assertion.Assert(Math.Abs(totalConsolidated - totalsByCurrency) <= MAX_BALANCE_DIFFERENCE,
Assertion.Require(Math.Abs(totalConsolidated - totalsByCurrency) <= MAX_BALANCE_DIFFERENCE,
"La suma de totales por moneda no es igual al total consolidado, " +
$"o excede el límite máximo de {MAX_BALANCE_DIFFERENCE} pesos de diferencia.");
}
Expand Down Expand Up @@ -224,7 +224,7 @@ private void CheckTotalsInReport(FixedList<ITrialBalanceEntry> entriesList) {
x => x.ItemType == TrialBalanceItemType.BalanceTotalConsolidated)
.Sum(x => x.TotalBalance);

Assertion.Assert(Math.Abs(totalReport - (totalDebtor - totalCreditor)) <= MAX_BALANCE_DIFFERENCE,
Assertion.Require(Math.Abs(totalReport - (totalDebtor - totalCreditor)) <= MAX_BALANCE_DIFFERENCE,
"La suma de total de deudoras menos acreedoras no es igual al total del reporte, " +
$"o excede el límite máximo de {MAX_BALANCE_DIFFERENCE} pesos de diferencia.");
}
Expand All @@ -248,7 +248,7 @@ private void TotalByDebtorOrCreditorAnalitico(FixedList<ITrialBalanceEntry> entr
.Sum(x => x.DomesticBalance);
}

Assertion.Assert(Math.Abs(totalDebtor.DomesticBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
Assertion.Require(Math.Abs(totalDebtor.DomesticBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
$"La suma del saldo actual ({entriesTotal}) de las cuentas deudoras no es " +
$"igual al {totalDebtor.GroupName} ({totalDebtor.DomesticBalance})");
}
Expand All @@ -263,7 +263,7 @@ private void TotalByDebtorOrCreditorAnalitico(FixedList<ITrialBalanceEntry> entr
x.ItemType == TrialBalanceItemType.Entry)
.Sum(x => x.DomesticBalance);
}
Assertion.Assert(Math.Abs(totalCreditor.DomesticBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
Assertion.Require(Math.Abs(totalCreditor.DomesticBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
$"La suma del saldo actual ({entriesTotal}) de las cuentas acreedoras no es " +
$"igual al {totalCreditor.GroupName} ({totalCreditor.DomesticBalance})");
}
Expand All @@ -281,7 +281,7 @@ private void TotalByDebtorOrCreditorBalanza(FixedList<ITrialBalanceEntry> entrie
x.Currency.Code == totalDebtor.Currency.Code)
.Sum(x => x.CurrentBalance);

Assertion.Assert(Math.Abs(totalDebtor.CurrentBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
Assertion.Require(Math.Abs(totalDebtor.CurrentBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
$"La suma del saldo actual ({entriesTotal}) de las cuentas deudoras no es " +
$"igual al {totalDebtor.GroupName} ({totalDebtor.CurrentBalance})");
}
Expand All @@ -291,7 +291,7 @@ private void TotalByDebtorOrCreditorBalanza(FixedList<ITrialBalanceEntry> entrie
x.Currency.Code == totalCreditor.Currency.Code)
.Sum(x => x.CurrentBalance);

Assertion.Assert(Math.Abs(totalCreditor.CurrentBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
Assertion.Require(Math.Abs(totalCreditor.CurrentBalance - entriesTotal) <= MAX_BALANCE_DIFFERENCE,
$"La suma del saldo actual ({entriesTotal}) de las cuentas acreedoras no es " +
$"igual al {totalCreditor.GroupName} ({totalCreditor.CurrentBalance})");
}
Expand Down
16 changes: 11 additions & 5 deletions BalanceEngine/TrialBalances/Domain/Helpers/TrialBalanceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ internal List<TrialBalanceEntry> GetCalculatedParentAccounts(FixedList<TrialBala
} else if (_command.DoNotReturnSubledgerAccounts && entry.Account.NotHasParent) {
continue;
} else {
throw Assertion.AssertNoReachThisCode();
throw Assertion.EnsureNoReachThisCode();
}

if (entry.HasParentPostingEntry) {
Expand Down Expand Up @@ -497,11 +497,16 @@ internal void RestrictLevels(List<TrialBalanceEntry> entries) {
}

if (_command.DoNotReturnSubledgerAccounts) {

entries.RemoveAll(x => x.Level <= _command.Level);

} else if (_command.WithSubledgerAccount) {

entries.RemoveAll(x => x.Level <= _command.Level);

} else {
throw Assertion.AssertNoReachThisCode();

throw Assertion.EnsureNoReachThisCode();
}
}

Expand Down Expand Up @@ -608,8 +613,9 @@ internal FixedList<TrialBalanceEntry> ValuateToExchangeRate(FixedList<TrialBalan
var exchangeRate = exchangeRates.FirstOrDefault(a => a.FromCurrency.Code == commandPeriod.ValuateToCurrrencyUID &&
a.ToCurrency.Code == entry.Currency.Code);

Assertion.AssertObject(exchangeRate, $"No se ha registrado el tipo de cambio para la " +
$"moneda {entry.Currency.FullName} en la fecha proporcionada.");
// ToDo: URGENT This require must be checked before any state
Assertion.Require(exchangeRate, $"No se ha registrado el tipo de cambio para la " +
$"moneda {entry.Currency.FullName} en la fecha proporcionada.");

if (_command.TrialBalanceType == TrialBalanceType.BalanzaValorizadaComparativa) {
if (commandPeriod.IsSecondPeriod) {
Expand Down Expand Up @@ -775,7 +781,7 @@ private void GetSummaryEntriesWithSectorization(
returnedEntries.AddRange(hashEntries.ToFixedList().ToList());
}


private void SetLastChangeDateToParentEntries(TrialBalanceEntry entry,
List<TrialBalanceEntry> summaryEntriesList) {
StandardAccount currentParentAccount = entry.Account.GetParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ internal FixedList<TrialBalanceEntry> ValuateToExchangeRate(
var exchangeRate = exchangeRates.FirstOrDefault(a => a.FromCurrency.Code == commandPeriod.ValuateToCurrrencyUID &&
a.ToCurrency.Code == entry.Currency.Code);

Assertion.AssertObject(exchangeRate, $"No hay tipo de cambio para la moneda {entry.Currency.FullName}.");
// ToDo: URGENT This require must be checked before any state
Assertion.Require(exchangeRate, $"No hay tipo de cambio para la moneda {entry.Currency.FullName}.");

entry.ExchangeRate = exchangeRate.Value;
}
Expand Down
4 changes: 2 additions & 2 deletions BalanceEngine/TrialBalances/Domain/StoredBalanceSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static internal StoredBalanceSet GetBestBalanceSet(AccountsChart accountsChart,

var bestBalanceSet = GetList(accountsChart).FindLast(x => x.BalancesDate < fromDate && x.Calculated);

Assertion.AssertObject(bestBalanceSet,
Assertion.Require(bestBalanceSet,
$"No hay ningún conjunto de saldos definidos para el catálogo {accountsChart.Name} " +
$"para la fecha {fromDate.ToString("dd/MMM/yyyy")}.");

Expand Down Expand Up @@ -161,7 +161,7 @@ public bool Unprotected {
#region Methods

internal void Calculate() {
Assertion.Assert(this.Unprotected,
Assertion.Require(this.Unprotected,
"This balance set is protected. It can not be recalculated.");

this.Calculated = false;
Expand Down
Loading

0 comments on commit f378253

Please sign in to comment.