20
|
1 using System.Net;
|
|
2 using System;
|
|
3
|
|
4 namespace Stocks.Common
|
|
5 {
|
|
6 // Shim to wrap WebClient component to allow the shim to
|
|
7 // be mocked or stubbed for unit tests.
|
|
8 // Favours injection and composition over inheritence
|
|
9 public class WebClientShim : IWebClientShim
|
|
10 {
|
|
11 private WebClient _webClient;
|
|
12
|
|
13 public WebClientShim(WebClient webClient)
|
|
14 {
|
|
15 _webClient = webClient;
|
|
16 }
|
|
17
|
|
18 public string DownloadString(string address)
|
|
19 {
|
|
20 return _webClient.DownloadString(address).ToString();
|
|
21 }
|
|
22
|
|
23 public void Dispose()
|
|
24 {
|
|
25 _webClient.Dispose();
|
|
26 }
|
|
27 }
|
|
28 } |