|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | + |
| 7 | +namespace Shared.Tests |
| 8 | +{ |
| 9 | + using System.Diagnostics.PerformanceData; |
| 10 | + using Shouldly; |
| 11 | + using ValueObjects; |
| 12 | + using Xunit; |
| 13 | + |
| 14 | + public class MoneyTests |
| 15 | + { |
| 16 | + [Theory] |
| 17 | + [InlineData(0)] |
| 18 | + [InlineData(1.00)] |
| 19 | + [InlineData(1.59)] |
| 20 | + [InlineData(100.00)] |
| 21 | + [InlineData(-1.59)] |
| 22 | + public void Money_CanBeCreated_IsCreated(Decimal moneyValue) |
| 23 | + { |
| 24 | + Money money = Money.Create(moneyValue); |
| 25 | + |
| 26 | + money.ShouldNotBeNull(); |
| 27 | + money.Value.ShouldBe(moneyValue); |
| 28 | + } |
| 29 | + |
| 30 | + [Theory] |
| 31 | + [InlineData(1,100,101)] |
| 32 | + [InlineData(0, 100, 100)] |
| 33 | + [InlineData(-1, 100, 99)] |
| 34 | + [InlineData(1.01, 100.01, 101.02)] |
| 35 | + [InlineData(0.01, 100.01, 100.02)] |
| 36 | + [InlineData(-1.01, 100.01, 99)] |
| 37 | + public void Money_AddOperator_ValueAdded(Decimal initialValue, Decimal valueToAdd, Decimal expectedResult) |
| 38 | + { |
| 39 | + Money money1 = Money.Create(initialValue); |
| 40 | + Money money2 = Money.Create(valueToAdd); |
| 41 | + |
| 42 | + var result = money1 + money2; |
| 43 | + result.Value.ShouldBe(expectedResult); |
| 44 | + } |
| 45 | + |
| 46 | + [Theory] |
| 47 | + [InlineData(1, 100, -99)] |
| 48 | + [InlineData(0, 100, -100)] |
| 49 | + [InlineData(-1, 100, -101)] |
| 50 | + [InlineData(1.01, 100.01, -99)] |
| 51 | + [InlineData(0.01, 100.01, -100)] |
| 52 | + [InlineData(-1.01, 100.01, -101.02)] |
| 53 | + public void Money_SubtractOperator_ValueAdded(Decimal initialValue, Decimal valueToSubtract, Decimal expectedResult) |
| 54 | + { |
| 55 | + Money money1 = Money.Create(initialValue); |
| 56 | + Money money2 = Money.Create(valueToSubtract); |
| 57 | + |
| 58 | + var result = money1 - money2; |
| 59 | + result.Value.ShouldBe(expectedResult); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + public class PositiveMoneyTests |
| 64 | + { |
| 65 | + [Theory] |
| 66 | + [InlineData(1.00)] |
| 67 | + [InlineData(1.59)] |
| 68 | + [InlineData(100.00)] |
| 69 | + public void PositiveMoney_CanBeCreated_IsCreated(Decimal moneyValue) |
| 70 | + { |
| 71 | + PositiveMoney money = PositiveMoney.Create(Money.Create(moneyValue)); |
| 72 | + |
| 73 | + money.ShouldNotBeNull(); |
| 74 | + money.Value.ShouldBe(moneyValue); |
| 75 | + } |
| 76 | + |
| 77 | + [Theory] |
| 78 | + [InlineData(0)] |
| 79 | + [InlineData(-1)] |
| 80 | + public void PositiveMoney_NonPositiveAmountRejected_ErrorThrown(Decimal moneyValue) |
| 81 | + { |
| 82 | + Should.Throw<ArgumentOutOfRangeException>(() => |
| 83 | + { |
| 84 | + PositiveMoney.Create(Money.Create(moneyValue)); |
| 85 | + }); |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments