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

Budget surplus widget fix #168

Merged
merged 11 commits into from
Jan 7, 2025
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,6 @@ UpgradeLog*.XML
/Rees.TangyFruitMapper/project.lock.json
.idea
*.zip
BudgetAnalyser.Engine.UnitTest/codecoverage
codecoverage
coverage.json
2 changes: 1 addition & 1 deletion BudgetAnalyser.Encryption/BudgetAnalyser.Encryption.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ConfuzzleCore" Version="3.0.1" />
<PackageReference Include="ConfuzzleCore" Version="3.0.2" />
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
<PackageReference Include="Rees.TangyFruitMapper" Version="2.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="Portable.Xaml" Version="0.26.0" />
<PackageReference Include="Rees.UnitTestUtilities" Version="2.0.1" />
<PackageReference Include="Rees.UnitTestUtilities" Version="2.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
99 changes: 53 additions & 46 deletions BudgetAnalyser.Engine.UnitTest/Helper/BudgetModelHelper.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,67 @@
using System;
using System.Diagnostics;
using System.Linq;
using BudgetAnalyser.Engine.Budget;
using BudgetAnalyser.Engine.Budget;

namespace BudgetAnalyser.Engine.UnitTest.Helper
namespace BudgetAnalyser.Engine.UnitTest.Helper;

public static class BudgetModelHelper
{
public static class BudgetModelHelper
public static void Output(this IBudgetCurrencyContext instance, IReesTestOutput? outputWriter = null)
{
public static void Output(this IBudgetCurrencyContext instance)
var writer = NonNullableOutputWriter(outputWriter);
writer.WriteLine(string.Empty);
writer.WriteLine("******************************* BUDGET OUTPUT ********************************");
writer.WriteLine(
$"Budget Currency Context: {instance.FileName} Budget Name: {instance.Model.Name} Effective From: {instance.Model.EffectiveFrom:d} Effective Until: {instance.EffectiveUntil:d}");
if (instance.BudgetActive)
{
Debug.WriteLine(string.Empty);
Debug.WriteLine($"Budget Currency Context: {instance.FileName} Budget Name: {instance.Model.Name} Effective From: {instance.Model.EffectiveFrom:d} Effective Until: {instance.EffectiveUntil:d}");
if (instance.BudgetActive)
{
Debug.WriteLine("Budget is ACTIVE.");
}
else if (instance.BudgetArchived)
{
Debug.WriteLine("Budget is ARCHIVED.");
}
else if (instance.BudgetInFuture)
{
Debug.WriteLine("Budget is FUTURE.");
}
instance.Model.Output(false);
writer.WriteLine("{0} Budget is ACTIVE.", instance.Model.BudgetCycle);
}
else if (instance.BudgetArchived)
{
writer.WriteLine("{0} Budget is ARCHIVED.", instance.Model.BudgetCycle);
}
else if (instance.BudgetInFuture)
{
writer.WriteLine("{0} Budget is FUTURE.", instance.Model.BudgetCycle);
}

public static void Output(this BudgetModel instance, bool includeTitle = true)
instance.Model.Output(false, writer);
}

public static void Output(this BudgetModel instance, bool includeTitle = true, IReesTestOutput? outputWriter = null)
{
var writer = NonNullableOutputWriter(outputWriter);
if (includeTitle)
{
writer.WriteLine(string.Empty);
writer.WriteLine($"Budget Model: '{instance.Name}' EffectiveFrom: {instance.EffectiveFrom}");
}

writer.WriteLine(@" Incomes Expenses");
writer.WriteLine(@" ==================================================================");
var incomeIndex = 0;
var incomeArray = instance.Incomes.ToArray();
foreach (var expense in instance.Expenses)
{
if (includeTitle)
if (incomeIndex <= incomeArray.GetUpperBound(0))
{
Debug.WriteLine(string.Empty);
Debug.WriteLine($"Budget Model: '{instance.Name}' EffectiveFrom: {instance.EffectiveFrom}");
writer.Write($" {incomeArray[incomeIndex].Bucket.Code,-10} {incomeArray[incomeIndex].Amount:F2}");
writer.WriteLine($" {expense.Bucket.Code,-10} {expense.Amount:F2}");
incomeIndex++;
}
Debug.WriteLine(@" Incomes Expenses");
Debug.WriteLine(@" ==================================================================");
var incomeIndex = 0;
var incomeArray = instance.Incomes.ToArray();
foreach (var expense in instance.Expenses)
else
{
if (incomeIndex <= incomeArray.GetUpperBound(0))
{
Debug.Write($" {incomeArray[incomeIndex].Bucket.Code.PadRight(10)} {incomeArray[incomeIndex].Amount:F2}");
Debug.WriteLine($" {expense.Bucket.Code.PadRight(10)} {expense.Amount:F2}");
incomeIndex++;
}
else
{
Debug.WriteLine($" {expense.Bucket.Code.PadRight(10)} {expense.Amount:F2}");
}
writer.WriteLine($" {expense.Bucket.Code,-10} {expense.Amount:F2}");
}

Debug.WriteLine(@" ------------------------------------------------------------------");
Debug.WriteLine($" Total Income: {instance.Incomes.Sum(i => i.Amount):F2} Total Expenses: {instance.Expenses.Sum(e => e.Amount):F2}");
Debug.WriteLine($" Surplus: {instance.Surplus:F2}");
Debug.WriteLine(@"======================================================================");
}

writer.WriteLine(@" ------------------------------------------------------------------");
writer.WriteLine($" Total Income: {instance.Incomes.Sum(i => i.Amount):F2} Total Expenses: {instance.Expenses.Sum(e => e.Amount):F2}");
writer.WriteLine($" Surplus: {instance.Surplus:F2}");
writer.WriteLine(@"======================================================================");
}

private static IReesTestOutput NonNullableOutputWriter(IReesTestOutput? outputWriter)
{
return outputWriter ?? new DebugTestOutput();
}
}
26 changes: 26 additions & 0 deletions BudgetAnalyser.Engine.UnitTest/Helper/DebugTestOutput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Diagnostics;

namespace BudgetAnalyser.Engine.UnitTest.Helper;

public class DebugTestOutput : IReesTestOutput
{
public void Write(string text)
{
Debug.Write(text);
}

public void Write(string template, params object[] args)
{
Debug.Write(string.Format(template, args));
}

public void WriteLine(string line)
{
Debug.WriteLine(line);
}

public void WriteLine(string template, params object[] args)
{
Debug.WriteLine(template, args);
}
}
9 changes: 9 additions & 0 deletions BudgetAnalyser.Engine.UnitTest/Helper/IReesTestOutput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace BudgetAnalyser.Engine.UnitTest.Helper;

public interface IReesTestOutput
{
void Write(string text);
void Write(string template, params object[] args);
void WriteLine(string line);
void WriteLine(string template, params object[] args);
}
Loading
Loading