Skip to content

Commit cbaa66a

Browse files
committed
update cs/ch17-04 README. Clean up code to have zero SonarQube squawks
1 parent 044947a commit cbaa66a

21 files changed

Lines changed: 169 additions & 133 deletions

File tree

cs/ch17-01-tests/Money.Tests/CurrencyPairTest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
13
namespace TheSoftwareGorilla.TDD.Money.Tests;
24

35
#region TO DO's
@@ -12,6 +14,7 @@ public class CurrencyPairTest
1214
[TestCase("ZAR", "USD", TestName = "CurrencyPair ZAR to USD are equal")]
1315
[TestCase("CHF", "USD", false, TestName = "CurrencyPair CHF to USD != USD to CHF")]
1416
[TestCase("ZAR", "USD", false, TestName = "CurrencyPair ZAR to USD != USD to ZAR")]
17+
[SuppressMessage("csharpsquid", "S2234", Justification = "Intentional parameter order inversion for inequality assertions.")]
1518
public void TestCurrencyPairs(string from, string to, bool isEqual = true)
1619
{
1720
var pair = new CurrencyPair(from, to);
@@ -34,8 +37,8 @@ public void TestCurrencyPairs(string from, string to, bool isEqual = true)
3437
public void TestEdgeCases(string from, string to)
3538
{
3639
var pair = new CurrencyPair(from, to);
37-
Assert.That(pair, Is.Not.EqualTo(null));
40+
Assert.That(pair, Is.Not.Null);
3841
Assert.That(pair, Is.Not.EqualTo(new object()));
39-
Assert.That(pair, Is.EqualTo(pair));
42+
Assert.That(pair, Is.EqualTo(new CurrencyPair(from, to)));
4043
}
4144
}

cs/ch17-01-tests/Money.Tests/MoneyTest.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,10 @@ public static Func<int, Money> GetCurrencyFactory(string currency)
5353
return _currencyFactories[currency];
5454
}
5555

56-
private Money? _fiveDollar;
57-
5856
[SetUp]
5957
public void Setup()
6058
{
61-
_fiveDollar = Money.Dollar(5);
62-
}
63-
64-
[TearDown]
65-
public void TearDown()
66-
{
67-
_fiveDollar = null;
59+
// No setup needed.
6860
}
6961

7062
[TestCase("USD", 5, 5, TestName = "construct USD 5")]

cs/ch17-01-tests/Money/Bank.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace TheSoftwareGorilla.TDD.Money;
22

33
public class Bank
44
{
5-
private Dictionary<CurrencyPair, int> _rates = new Dictionary<CurrencyPair, int>();
5+
private readonly Dictionary<CurrencyPair, int> _rates = new Dictionary<CurrencyPair, int>();
66
public Money Reduce(Expression source, string to)
77
{
88
return source.Reduce(this, to);

cs/ch17-01-tests/Money/Expression.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
13
namespace TheSoftwareGorilla.TDD.Money;
24

5+
[SuppressMessage("csharpsquid","S101", Justification = "Interface name exists for parity with book examples.")]
36
public interface Expression
47
{
58
Money Reduce(Bank bank, string to);

cs/ch17-02-plus/Money.Tests/CurrencyPairTest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
13
namespace TheSoftwareGorilla.TDD.Money.Tests;
24

35
#region TO DO's
@@ -12,6 +14,7 @@ public class CurrencyPairTest
1214
[TestCase("ZAR", "USD", TestName = "CurrencyPair ZAR to USD are equal")]
1315
[TestCase("CHF", "USD", false, TestName = "CurrencyPair CHF to USD != USD to CHF")]
1416
[TestCase("ZAR", "USD", false, TestName = "CurrencyPair ZAR to USD != USD to ZAR")]
17+
[SuppressMessage("csharpsquid", "S2234", Justification = "Intentional parameter order inversion for inequality assertions.")]
1518
public void TestCurrencyPairs(string from, string to, bool isEqual = true)
1619
{
1720
var pair = new CurrencyPair(from, to);
@@ -34,8 +37,8 @@ public void TestCurrencyPairs(string from, string to, bool isEqual = true)
3437
public void TestEdgeCases(string from, string to)
3538
{
3639
var pair = new CurrencyPair(from, to);
37-
Assert.That(pair, Is.Not.EqualTo(null));
40+
Assert.That(pair, Is.Not.Null);
3841
Assert.That(pair, Is.Not.EqualTo(new object()));
39-
Assert.That(pair, Is.EqualTo(pair));
42+
Assert.That(pair, Is.EqualTo(new CurrencyPair(from, to)));
4043
}
4144
}

cs/ch17-02-plus/Money/Bank.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace TheSoftwareGorilla.TDD.Money;
22

33
public class Bank
44
{
5-
private Dictionary<CurrencyPair, int> _rates = new Dictionary<CurrencyPair, int>();
5+
private readonly Dictionary<CurrencyPair, int> _rates = new Dictionary<CurrencyPair, int>();
66
public Money Reduce(Expression source, string to)
77
{
88
return source.Reduce(this, to);

cs/ch17-02-plus/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ things:
77
- Fix the "Return `Money` from \$5 + \$5" TODO item
88
- Review the design decisions made
99

10-
This is solution is the second part of a four-part series that addresses these tasks. This part focuses on fixing Sum.
10+
This solution is the second part of a four-part series that addresses these tasks. This part focuses on fixing Sum.
1111

1212
For information on how to set up the repository, please see the [README in the ch00](../ch00/README.md) folder.
1313

cs/ch17-03-decimal/Money.Tests/CurrencyPairTest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
13
namespace TheSoftwareGorilla.TDD.Money.Tests;
24

35
#region TO DO's
@@ -12,6 +14,7 @@ public class CurrencyPairTest
1214
[TestCase("ZAR", "USD", TestName = "CurrencyPair ZAR to USD are equal")]
1315
[TestCase("CHF", "USD", false, TestName = "CurrencyPair CHF to USD != USD to CHF")]
1416
[TestCase("ZAR", "USD", false, TestName = "CurrencyPair ZAR to USD != USD to ZAR")]
17+
[SuppressMessage("csharpsquid", "S2234", Justification = "Intentional parameter order inversion for inequality assertions.")]
1518
public void TestCurrencyPairs(string from, string to, bool isEqual = true)
1619
{
1720
var pair = new CurrencyPair(from, to);
@@ -34,8 +37,8 @@ public void TestCurrencyPairs(string from, string to, bool isEqual = true)
3437
public void TestEdgeCases(string from, string to)
3538
{
3639
var pair = new CurrencyPair(from, to);
37-
Assert.That(pair, Is.Not.EqualTo(null));
40+
Assert.That(pair, Is.Not.Null);
3841
Assert.That(pair, Is.Not.EqualTo(new object()));
39-
Assert.That(pair, Is.EqualTo(pair));
42+
Assert.That(pair, Is.EqualTo(new CurrencyPair(from, to)));
4043
}
4144
}

cs/ch17-03-decimal/Money.Tests/CurrencyTransactionTest.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11

22
namespace TheSoftwareGorilla.TDD.Money.Tests;
33

4-
#region TO DO's
5-
//TODO: Add support for subtracting two Money objects
6-
//TODO: Clean up the settle() method in CurrencyTransaction
7-
//TODO: Change the tests to do more assert expected value calculations
8-
//TODO: Add 5 test cases
9-
//TODO: Refactor the tests for separating the asserts
10-
#endregion
114
[TestFixture]
125
[Description("CurrencyTransactionTest class")]
136
public class CurrencyTransactionTest

cs/ch17-03-decimal/Money/CurrencyTransaction.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Net;
2-
31
namespace TheSoftwareGorilla.TDD.Money;
42

53
public class CurrencyTransaction

0 commit comments

Comments
 (0)