comparison Stocks/Stocks.Common/WebClientShim.cs @ 6:c812bca7b1ac

"Restore packages on build" enabled by Nuget 1.6 General refactoring based on code analysis
author stevenh7776 stevenhollidge@hotmail.com
date Tue, 21 Feb 2012 01:00:34 +0700
parents 57f20ba55884
children 6e84a4c92378
comparison
equal deleted inserted replaced
5:877d70fb8176 6:c812bca7b1ac
1 using System; 1 using System.Net;
2 using System.Collections.Generic; 2 using System;
3 using System.Linq;
4 using System.Text;
5 using System.Net;
6 3
7 namespace Stocks.Common 4 namespace Stocks.Common
8 { 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 9 public class WebClientShim : IWebClientShim
10 { 10 {
11 private readonly WebClient _webClient; 11 private WebClient _webClient;
12 12
13 public WebClientShim(WebClient webClient) 13 public WebClientShim(WebClient webClient)
14 { 14 {
15 _webClient = webClient; 15 _webClient = webClient;
16 } 16 }
17 17
18 // add event handlers to the shim if you wish
19 // to hook into DownloadStringCompleted event
18 public string DownloadString(string address) 20 public string DownloadString(string address)
19 { 21 {
20 return _webClient.DownloadString(address).ToString(); 22 return _webClient.DownloadString(address).ToString();
21 } 23 }
24
25 public void Dispose()
26 {
27 _webClient.Dispose();
28 }
22 } 29 }
23 } 30 }