File tree Expand file tree Collapse file tree 3 files changed +66
-0
lines changed
Tests/Integration/CryptoStatsSource Expand file tree Collapse file tree 3 files changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Threading . Tasks ;
4
+
5
+ namespace CryptoStatsSource
6
+ {
7
+ public interface ICryptoNameResolver
8
+ {
9
+ public Task < string > Resolve ( string symbol ) ;
10
+
11
+ public Task Refresh ( ) ;
12
+ }
13
+
14
+ public class CryptoNameResolverImpl : ICryptoNameResolver
15
+ {
16
+ private ICryptoStatsSource _cryptoStatsSource ;
17
+ private Dictionary < String , String > _symbolToNameMap ;
18
+
19
+ public CryptoNameResolverImpl ( ICryptoStatsSource cryptoStatsSource )
20
+ {
21
+ _cryptoStatsSource = cryptoStatsSource ;
22
+ }
23
+
24
+ public async Task Refresh ( )
25
+ {
26
+ _symbolToNameMap = new ( ) ;
27
+ ( await _cryptoStatsSource . GetAvailableCryptocurrencies ( ) ) . ForEach ( c =>
28
+ _symbolToNameMap . TryAdd ( c . Symbol , c . Name ) ) ;
29
+ }
30
+
31
+
32
+ public async Task < string > Resolve ( string symbol )
33
+ {
34
+ if ( _symbolToNameMap ? . GetValueOrDefault ( symbol ) == null ) await Refresh ( ) ;
35
+
36
+ return _symbolToNameMap . GetValueOrDefault ( symbol , null ) ;
37
+ }
38
+ }
39
+ }
Original file line number Diff line number Diff line change
1
+ using CryptoStatsSource ;
2
+ using Xunit ;
3
+
4
+ namespace Tests . Integration . CryptoStatsSource
5
+ {
6
+ public class ResolveNameTest
7
+ {
8
+ private readonly CoingeckoSource _source ;
9
+ private readonly CryptoNameResolverImpl _resolver ;
10
+
11
+ public ResolveNameTest ( )
12
+ {
13
+ _source = new ( ) ;
14
+ _resolver = new ( _source ) ;
15
+ }
16
+
17
+ [ Fact ]
18
+ public async void SimpleThreeEntries ( )
19
+ {
20
+ Assert . Equal ( "Bitcoin" , await _resolver . Resolve ( "btc" ) ) ;
21
+ Assert . Equal ( "Cardano" , await _resolver . Resolve ( "ada" ) ) ;
22
+ Assert . Equal ( "Litecoin" , await _resolver . Resolve ( "ltc" ) ) ;
23
+ Assert . Equal ( "Ethereum" , await _resolver . Resolve ( "eth" ) ) ;
24
+ Assert . Null ( await _resolver . Resolve ( "abcefghbzbzrfoo" ) ) ;
25
+ }
26
+ }
27
+ }
File renamed without changes.
You can’t perform that action at this time.
0 commit comments