You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if cache.ContainsKey(key)then Some(cache.[key])else None
19
+
member_.Set(key,value)= cache.[key]<- value
20
+
member_.Remove(key)= cache.Remove(key)|> ignore
21
+
22
+
// Mock JSON responses that mimic WorldBank API responses
23
+
letmockIndicatorResponse="""
24
+
[
25
+
{
26
+
"page": 1,
27
+
"pages": 1,
28
+
"per_page": 1000,
29
+
"total": 2
30
+
},
31
+
[
32
+
{
33
+
"id": "AG.AGR.TRAC.NO",
34
+
"name": "Agricultural machinery, tractors",
35
+
"source": {
36
+
"id": "2",
37
+
"value": "World Development Indicators"
38
+
},
39
+
"sourceNote": "Agricultural machinery refers to the number of wheel and crawler tractors.",
40
+
"topics": [
41
+
{
42
+
"id": "9",
43
+
"value": "Infrastructure"
44
+
}
45
+
]
46
+
},
47
+
{
48
+
"id": "AG.CON.FERT.ZS",
49
+
"name": "Fertilizer consumption (kilograms per hectare of arable land)",
50
+
"source": {
51
+
"id": "2",
52
+
"value": "World Development Indicators"
53
+
},
54
+
"sourceNote": "Fertilizer consumption measures the quantity of plant nutrients used per unit of arable land.",
55
+
"topics": [
56
+
{
57
+
"id": "6",
58
+
"value": "Environment"
59
+
}
60
+
]
61
+
}
62
+
]
63
+
]
64
+
"""
65
+
66
+
letmockCountryResponse="""
67
+
[
68
+
{
69
+
"page": 1,
70
+
"pages": 1,
71
+
"per_page": 1000,
72
+
"total": 3
73
+
},
74
+
[
75
+
{
76
+
"id": "ABW",
77
+
"name": "Aruba",
78
+
"capitalCity": "Oranjestad",
79
+
"region": {
80
+
"id": "LCN",
81
+
"value": "Latin America & Caribbean"
82
+
}
83
+
},
84
+
{
85
+
"id": "AFG",
86
+
"name": "Afghanistan",
87
+
"capitalCity": "Kabul",
88
+
"region": {
89
+
"id": "SAS",
90
+
"value": "South Asia"
91
+
}
92
+
},
93
+
{
94
+
"id": "WLD",
95
+
"name": "World",
96
+
"capitalCity": "",
97
+
"region": {
98
+
"id": "NA",
99
+
"value": "Aggregates"
100
+
}
101
+
}
102
+
]
103
+
]
104
+
"""
105
+
106
+
letmockTopicResponse="""
107
+
[
108
+
{
109
+
"page": 1,
110
+
"pages": 1,
111
+
"per_page": 1000,
112
+
"total": 2
113
+
},
114
+
[
115
+
{
116
+
"id": "1",
117
+
"value": "Agriculture & Rural Development",
118
+
"sourceNote": "For the 70 percent of the world's poor who live in rural areas, agriculture is the main source of income and employment."
119
+
},
120
+
{
121
+
"id": "2",
122
+
"value": "Aid Effectiveness",
123
+
"sourceNote": "Aid effectiveness is the impact that aid has in reducing poverty and inequality."
124
+
}
125
+
]
126
+
]
127
+
"""
128
+
129
+
letmockRegionResponse="""
130
+
[
131
+
{
132
+
"page": 1,
133
+
"pages": 1,
134
+
"per_page": 1000,
135
+
"total": 2
136
+
},
137
+
[
138
+
{
139
+
"code": "EAS",
140
+
"name": "East Asia & Pacific"
141
+
},
142
+
{
143
+
"code": "ECS",
144
+
"name": "Europe & Central Asia"
145
+
}
146
+
]
147
+
]
148
+
"""
149
+
150
+
letmockDataResponse="""
151
+
[
152
+
{
153
+
"page": 1,
154
+
"pages": 1,
155
+
"per_page": 1000,
156
+
"total": 3
157
+
},
158
+
[
159
+
{
160
+
"date": "2020",
161
+
"value": "65894.86"
162
+
},
163
+
{
164
+
"date": "2019",
165
+
"value": "62888.17"
166
+
},
167
+
{
168
+
"date": "2018",
169
+
"value": null
170
+
}
171
+
]
172
+
]
173
+
"""
174
+
175
+
[<Test>]
176
+
let``IndicatorRecord should have correct IsRegion property for regular country`` ()=
177
+
letcountry={ Id ="USA"; Name ="United States"; CapitalCity ="Washington"; Region ="North America"}
178
+
country.IsRegion |> should be False
179
+
180
+
[<Test>]
181
+
let``IndicatorRecord should have correct IsRegion property for aggregate region`` ()=
182
+
letregion={ Id ="WLD"; Name ="World"; CapitalCity =""; Region ="Aggregates"}
183
+
region.IsRegion |> should be True
184
+
185
+
[<Test>]
186
+
let``IndicatorRecord should be constructed with all required fields`` ()=
187
+
letindicator={
188
+
Id ="AG.AGR.TRAC.NO"
189
+
Name ="Agricultural machinery, tractors"
190
+
TopicIds =["9"]
191
+
Source ="World Development Indicators"
192
+
Description ="Agricultural machinery refers to the number of wheel and crawler tractors."
193
+
}
194
+
195
+
indicator.Id |> should equal "AG.AGR.TRAC.NO"
196
+
indicator.Name |> should equal "Agricultural machinery, tractors"
197
+
indicator.TopicIds |> should equal ["9"]
198
+
indicator.Source |> should equal "World Development Indicators"
199
+
indicator.Description |> should equal "Agricultural machinery refers to the number of wheel and crawler tractors."
200
+
201
+
[<Test>]
202
+
let``CountryRecord should be constructed with all required fields`` ()=
203
+
letcountry={
204
+
Id ="USA"
205
+
Name ="United States"
206
+
CapitalCity ="Washington"
207
+
Region ="North America"
208
+
}
209
+
210
+
country.Id |> should equal "USA"
211
+
country.Name |> should equal "United States"
212
+
country.CapitalCity |> should equal "Washington"
213
+
country.Region |> should equal "North America"
214
+
country.IsRegion |> should be False
215
+
216
+
[<Test>]
217
+
let``TopicRecord should be constructed with all required fields`` ()=
218
+
lettopic={
219
+
Id ="1"
220
+
Name ="Agriculture & Rural Development"
221
+
Description ="For the 70 percent of the world's poor who live in rural areas, agriculture is the main source of income and employment."
222
+
}
223
+
224
+
topic.Id |> should equal "1"
225
+
topic.Name |> should equal "Agriculture & Rural Development"
226
+
topic.Description |> should equal "For the 70 percent of the world's poor who live in rural areas, agriculture is the main source of income and employment."
227
+
228
+
[<Test>]
229
+
let``WorldBankData should construct with sources`` ()=
230
+
letdata= WorldBankData("http://api.worldbank.org","World Development Indicators")
231
+
data |> should not' (be Null)
232
+
233
+
[<Test>]
234
+
let``WorldBankData should construct with multiple sources`` ()=
235
+
letdata= WorldBankData("http://api.worldbank.org","World Development Indicators;Global Financial Development")
236
+
data |> should not' (be Null)
237
+
238
+
[<Test>]
239
+
let``WorldBankData should handle empty sources`` ()=
0 commit comments