From 3f17b2cff22b0c666652f20992037b660d1391b0 Mon Sep 17 00:00:00 2001 From: Ben Rees Date: Wed, 1 Jan 2025 16:17:17 +1300 Subject: [PATCH] Upgrade Rees Test Utils. Remove local AssertExtension. --- .../AssertExtension.cs | 20 ------------------- .../BudgetAnalyser.Engine.UnitTest.csproj | 2 +- .../OverallPerformanceBudgetAnalyserTest.cs | 17 ++++++++-------- .../BudgetAnalyser.Wpf.UnitTest.csproj | 2 +- 4 files changed, 11 insertions(+), 30 deletions(-) delete mode 100644 BudgetAnalyser.Engine.UnitTest/AssertExtension.cs diff --git a/BudgetAnalyser.Engine.UnitTest/AssertExtension.cs b/BudgetAnalyser.Engine.UnitTest/AssertExtension.cs deleted file mode 100644 index 93f55d14..00000000 --- a/BudgetAnalyser.Engine.UnitTest/AssertExtension.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace BudgetAnalyser.Engine.UnitTest; - -public static class AssertExtensions -{ - public static void AreEqualWithTolerance(decimal expected, decimal actual, decimal tolerance = 0.01M, string message = "") - { - if (Math.Abs(expected - actual) >= tolerance) - { - throw new AssertFailedException($"Expected: {expected}, Actual: {actual}. {message}"); - } - } - - public static void AreEqualWithTolerance(double expected, double actual, double tolerance = 0.01, string message = "") - { - if (Math.Abs(expected - actual) >= tolerance) - { - throw new AssertFailedException($"Expected: {expected}, Actual: {actual}. {message}"); - } - } -} diff --git a/BudgetAnalyser.Engine.UnitTest/BudgetAnalyser.Engine.UnitTest.csproj b/BudgetAnalyser.Engine.UnitTest/BudgetAnalyser.Engine.UnitTest.csproj index bbcf8373..efedaccf 100644 --- a/BudgetAnalyser.Engine.UnitTest/BudgetAnalyser.Engine.UnitTest.csproj +++ b/BudgetAnalyser.Engine.UnitTest/BudgetAnalyser.Engine.UnitTest.csproj @@ -51,7 +51,7 @@ - + diff --git a/BudgetAnalyser.Engine.UnitTest/Reports/OverallPerformanceBudgetAnalyserTest.cs b/BudgetAnalyser.Engine.UnitTest/Reports/OverallPerformanceBudgetAnalyserTest.cs index c07d87b4..408147f6 100644 --- a/BudgetAnalyser.Engine.UnitTest/Reports/OverallPerformanceBudgetAnalyserTest.cs +++ b/BudgetAnalyser.Engine.UnitTest/Reports/OverallPerformanceBudgetAnalyserTest.cs @@ -4,6 +4,7 @@ using BudgetAnalyser.Engine.UnitTest.Helper; using BudgetAnalyser.Engine.UnitTest.TestData; using BudgetAnalyser.Engine.UnitTest.TestHarness; +using Rees.UnitTestUtilities; namespace BudgetAnalyser.Engine.UnitTest.Reports; @@ -80,7 +81,7 @@ public void Analyse_ShouldReturnCorrectAverageSpend_Fortnight() var result = this.analyser!.Analyse(this.statementTestData, this.budgetsTestData, this.dateCriteria); - AssertExtensions.AreEqualWithTolerance(-461.54M, result.AverageSpend); + Ensure.AreEqualWithTolerance(-461.54M, result.AverageSpend); } [TestMethod] @@ -99,7 +100,7 @@ public void Analyse_ShouldReturnCorrectAverageSurplus_Fortnight() var result = this.analyser!.Analyse(this.statementTestData, this.budgetsTestData, this.dateCriteria); - AssertExtensions.AreEqualWithTolerance(-230.77M, result.AverageSurplus); + Ensure.AreEqualWithTolerance(-230.77M, result.AverageSurplus); } [TestMethod] @@ -137,7 +138,7 @@ public void Analyse_ShouldReturnCorrectOverallPerformanceRating_Fortnight() var result = this.analyser!.Analyse(this.statementTestData, this.budgetsTestData, this.dateCriteria); - AssertExtensions.AreEqualWithTolerance(8020M, result.OverallPerformance); + Ensure.AreEqualWithTolerance(8020M, result.OverallPerformance); } [TestMethod] @@ -157,7 +158,7 @@ public void Analyse_ShouldReturnResultCorrectAvgForCarMtc_Fortnight() var result = this.analyser!.Analyse(this.statementTestData, this.budgetsTestData, this.dateCriteria); var avgCarMtc = result.Analyses.Single(b => b.Bucket.Code == StatementModelTestData.CarMtcBucket.Code).AverageSpend; - AssertExtensions.AreEqualWithTolerance(92.31M, avgCarMtc); + Ensure.AreEqualWithTolerance(92.31M, avgCarMtc); } [TestMethod] @@ -177,7 +178,7 @@ public void Analyse_ShouldReturnResultCorrectAvgForHair_Fortnight() var result = this.analyser!.Analyse(this.statementTestData, this.budgetsTestData, this.dateCriteria); var avgHair = result.Analyses.Single(b => b.Bucket.Code == StatementModelTestData.HairBucket.Code).AverageSpend; - AssertExtensions.AreEqualWithTolerance(138.46M, avgHair); + Ensure.AreEqualWithTolerance(138.46M, avgHair); } [TestMethod] @@ -197,7 +198,7 @@ public void Analyse_ShouldReturnResultCorrectAvgForPhone_Fortnight() var result = this.analyser!.Analyse(this.statementTestData, this.budgetsTestData, this.dateCriteria); var avgPhone = result.Analyses.Single(b => b.Bucket.Code == StatementModelTestData.PhoneBucket.Code).AverageSpend; - AssertExtensions.AreEqualWithTolerance(46.15M, avgPhone); + Ensure.AreEqualWithTolerance(46.15M, avgPhone); } [TestMethod] @@ -217,7 +218,7 @@ public void Analyse_ShouldReturnResultCorrectAvgForPower_Fortnight() var result = this.analyser!.Analyse(this.statementTestData, this.budgetsTestData, this.dateCriteria); var avgPower = result.Analyses.Single(b => b.Bucket.Code == StatementModelTestData.PowerBucket.Code).AverageSpend; - AssertExtensions.AreEqualWithTolerance(184.62M, avgPower); + Ensure.AreEqualWithTolerance(184.62M, avgPower); } [TestMethod] @@ -237,7 +238,7 @@ public void Analyse_ShouldReturnResultCorrectAvgForSurplus_Fortnight() var result = this.analyser!.Analyse(this.statementTestData, this.budgetsTestData, this.dateCriteria); var avgSurplus = result.Analyses.Single(b => b.Bucket.Code == StatementModelTestData.SurplusBucket.Code).AverageSpend; - AssertExtensions.AreEqualWithTolerance(230.77M, avgSurplus); + Ensure.AreEqualWithTolerance(230.77M, avgSurplus); } [TestMethod] diff --git a/BudgetAnalyser.Wpf.UnitTest/BudgetAnalyser.Wpf.UnitTest.csproj b/BudgetAnalyser.Wpf.UnitTest/BudgetAnalyser.Wpf.UnitTest.csproj index 2e7fb680..57039d66 100644 --- a/BudgetAnalyser.Wpf.UnitTest/BudgetAnalyser.Wpf.UnitTest.csproj +++ b/BudgetAnalyser.Wpf.UnitTest/BudgetAnalyser.Wpf.UnitTest.csproj @@ -19,7 +19,7 @@ - +