changeset 8:6e84a4c92378

FakeWebClientShim added and refactoring
author stevenh7776 stevenhollidge@hotmail.com
date Tue, 21 Feb 2012 17:05:47 +0700
parents cdc88fd7cb89
children 904a9faadf8b
files .hgignore Stocks/Stocks.Common/EventArgs/PriceChangedEventArgs.cs Stocks/Stocks.Common/Events/PriceChanged.cs Stocks/Stocks.Common/Fakes/FakeWebClientShim.cs Stocks/Stocks.Common/Stocks.Common.csproj Stocks/Stocks.Common/WebClientShim.cs Stocks/Stocks.Service/StocksService.cs
diffstat 7 files changed, 38 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Tue Feb 21 01:19:54 2012 +0700
+++ b/.hgignore	Tue Feb 21 17:05:47 2012 +0700
@@ -4,3 +4,4 @@
 *.suo
 *.csproj.user
 */obj/*
+Stocks/packages/xunit.extensions.1.9.0.1566/xunit.extensions.1.9.0.1566.nupkg
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Stocks/Stocks.Common/EventArgs/PriceChangedEventArgs.cs	Tue Feb 21 17:05:47 2012 +0700
@@ -0,0 +1,9 @@
+using Stocks.Common.Models;
+
+namespace Stocks.Common.Events
+{
+  public class PriceChangedEventArgs
+  {
+    public Price Price { get; set; }
+  }
+}
--- a/Stocks/Stocks.Common/Events/PriceChanged.cs	Tue Feb 21 01:19:54 2012 +0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-using Stocks.Common.Models;
-
-namespace Stocks.Common.Events
-{
-  public class PriceChangedEventArgs
-  {
-    public Price Price { get; set; }
-  }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Stocks/Stocks.Common/Fakes/FakeWebClientShim.cs	Tue Feb 21 17:05:47 2012 +0700
@@ -0,0 +1,23 @@
+
+namespace Stocks.Common.Fakes
+{
+  public class FakeWebClientShim : IWebClientShim
+  {
+    private string _downloadString;
+
+    public FakeWebClientShim(string downloadString = "")
+    {
+      _downloadString = downloadString;
+    }
+
+    public string DownloadString(string address)
+    {
+      return _downloadString;
+    }
+
+    public void Dispose()
+    {
+      // do nothing
+    }
+  }
+}
--- a/Stocks/Stocks.Common/Stocks.Common.csproj	Tue Feb 21 01:19:54 2012 +0700
+++ b/Stocks/Stocks.Common/Stocks.Common.csproj	Tue Feb 21 17:05:47 2012 +0700
@@ -53,8 +53,9 @@
     <Compile Include="ConfigurationService.cs" />
     <Compile Include="Core\ExtensionMethods.cs" />
     <Compile Include="Core\TimedDelegates.cs" />
-    <Compile Include="Events\PriceChanged.cs" />
+    <Compile Include="EventArgs\PriceChangedEventArgs.cs" />
     <Compile Include="Factory.cs" />
+    <Compile Include="Fakes\FakeWebClientShim.cs" />
     <Compile Include="IConfigurationService.cs" />
     <Compile Include="Exceptions\InvalidWebPriceData.cs" />
     <Compile Include="IStocksService.cs" />
--- a/Stocks/Stocks.Common/WebClientShim.cs	Tue Feb 21 01:19:54 2012 +0700
+++ b/Stocks/Stocks.Common/WebClientShim.cs	Tue Feb 21 17:05:47 2012 +0700
@@ -15,8 +15,6 @@
       _webClient = webClient;
     }
 
-    // add event handlers to the shim if you wish 
-    // to hook into DownloadStringCompleted event
     public string DownloadString(string address)
     {
       return _webClient.DownloadString(address).ToString();
--- a/Stocks/Stocks.Service/StocksService.cs	Tue Feb 21 01:19:54 2012 +0700
+++ b/Stocks/Stocks.Service/StocksService.cs	Tue Feb 21 17:05:47 2012 +0700
@@ -46,9 +46,9 @@
       _serviceUrl = _configurationService.GetServiceUrl(symbolsCsv);
     }
 
+    public event PriceChangedEventHandler PriceChanged;
     public delegate void PriceChangedEventHandler(object sender, PriceChangedEventArgs e);
-    public event PriceChangedEventHandler PriceChanged;
-    protected virtual void RaisePriceChanged(Price price)
+    protected virtual void OnPriceChanged(Price price)
     {
       Stats.PriceChangeEvents++;
 
@@ -128,7 +128,7 @@
     {
       localPrice.PreviousPrice = localPrice.CurrentPrice;
       localPrice.CurrentPrice = webPrice.CurrentPrice;
-      RaisePriceChanged(localPrice);
+      OnPriceChanged(localPrice);
     }
 
     private void UpdateStats(Stopwatch timeToDownload, string webResponse)