File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed
DesignPatternsInCSharp/RulesEngine/Discounts Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,23 @@ public void Returns10PctForCustomersWhoAreVeterans(int customerAge)
54
54
result . Should ( ) . Be ( .10m ) ;
55
55
}
56
56
57
+ [ Theory ]
58
+ [ InlineData ( 1 , .05 ) ]
59
+ [ InlineData ( 2 , .08 ) ]
60
+ [ InlineData ( 5 , .10 ) ]
61
+ [ InlineData ( 10 , .12 ) ]
62
+ [ InlineData ( 15 , .15 ) ]
63
+ public void ReturnsCorrectLoyaltyDiscountForLongtimeCustomers ( int yearsAsCustomer , decimal expectedDiscount )
64
+ {
65
+ var customer = CreateCustomer ( DEFAULT_AGE ,
66
+ DateTime . Today . AddYears ( - yearsAsCustomer ) . AddDays ( - 1 ) ) ;
67
+
68
+ var result = _calculator . CalculateDiscountPercentage ( customer ) ;
69
+
70
+ result . Should ( ) . Be ( expectedDiscount ) ;
71
+ }
72
+
73
+
57
74
private Customer CreateCustomer ( int age = DEFAULT_AGE , DateTime ? firstPurchaseDate = null )
58
75
{
59
76
return new Customer
Original file line number Diff line number Diff line change @@ -10,8 +10,31 @@ public decimal CalculateDiscountPercentage(Customer customer)
10
10
{
11
11
return .15m ;
12
12
}
13
-
14
- if ( customer . IsVeteran )
13
+ else
14
+ {
15
+ if ( customer . DateOfFirstPurchase . Value < DateTime . Now . AddYears ( - 15 ) )
16
+ {
17
+ return .15m ;
18
+ }
19
+ if ( customer . DateOfFirstPurchase . Value < DateTime . Now . AddYears ( - 10 ) )
20
+ {
21
+ return .12m ;
22
+ }
23
+ if ( customer . DateOfFirstPurchase . Value < DateTime . Now . AddYears ( - 5 ) )
24
+ {
25
+ return .10m ;
26
+ }
27
+ if ( customer . DateOfFirstPurchase . Value < DateTime . Now . AddYears ( - 2 ) )
28
+ {
29
+ return .08m ;
30
+ }
31
+ if ( customer . DateOfFirstPurchase . Value < DateTime . Now . AddYears ( - 1 ) )
32
+ {
33
+ return .05m ;
34
+ }
35
+ }
36
+
37
+ if ( customer . IsVeteran )
15
38
{
16
39
return .10m ;
17
40
}
You can’t perform that action at this time.
0 commit comments