-
Notifications
You must be signed in to change notification settings - Fork 405
Expand file tree
/
Copy pathRatingEngineRate.cs
More file actions
108 lines (89 loc) · 2.92 KB
/
RatingEngineRate.cs
File metadata and controls
108 lines (89 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using Xunit;
namespace ArdalisRating.Tests
{
// only for testing purpose
public class FakeLogger : ILogger
{
public List<string> LoggedMessages { get; } = new List<string>();
public void Log(string message)
{
LoggedMessages.Add(message);
}
}
// Only for testing purpose
public class FakePolicySource : IPolicySource
{
public string PolicyString { get; set; } = "";
public string GetPolicyFromSource()
{
return PolicyString;
}
}
public class RatingEngineRate
{
private readonly RatingEngine _engine;
private readonly ILogger _logger;
private readonly IPolicySource _policySource;
private IRatingContext Context { get; set; }
public RatingEngineRate()
{
_logger = new FakeLogger();
_policySource = new FakePolicySource();
_engine = new RatingEngine(_logger, _policySource);
this.Context = new DefaultRatingContext(_policySource);
}
[Fact]
public void ReturnsRatingOf10000For200000LandPolicy()
{
var policy = new Policy
{
Type = "Land",
BondAmount = 200000,
Valuation = 200000
};
string json = JsonConvert.SerializeObject(policy);
//File.WriteAllText("policy.json", json);
_policySource.PolicyString = json;
//var engine = new RatingEngine();
_engine.Rate();
var result = _engine.Rating;
Assert.Equal(10000, result);
}
[Fact]
public void ReturnsRatingOf0For200000BondOn260000LandPolicy()
{
var policy = new Policy
{
Type = "Land",
BondAmount = 200000,
Valuation = 260000
};
string json = JsonConvert.SerializeObject(policy);
File.WriteAllText("policy.json", json);
// var _engine = new RatingEngine();
_engine.Rate();
var result = _engine.Rating;
Assert.Equal(0, result);
}
[Fact]
public void LogsStartingLoadingAndCompleting()
{
var policy = new Policy()
{
Type = "Land",
BondAmount = 2000000,
Valuation = 260000
};
string json = JsonConvert.SerializeObject(policy);
File.WriteAllText("policy.json", json);
_engine.Rate();
var result = _engine.Rating;
Assert.Contains(_logger.LoggedMessages, m => m == "Starting rate.");
Assert.Contains(_logger.LoggedMessages, m => m == "Loading policy.");
Assert.Contains(_logger.LoggedMessages, m => m == "Rating completed.");
}
}
}