Commit ac14219
Changed files (4)
product
desktop.ui
specs
unit
ui
presenters
product/desktop.ui/presenters/SingleStockPresenter.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using gorilla.utility;
+using solidware.financials.infrastructure.eventing;
+using solidware.financials.messages;
+
+namespace solidware.financials.windows.ui.presenters
+{
+ public class SingleStockPresenter : TabPresenter, EventSubscriber<CurrentStockPrice>
+ {
+ string symbol_to_watch;
+
+ public SingleStockPresenter(string symbol_to_watch)
+ {
+ this.symbol_to_watch = symbol_to_watch;
+ Chart = new ObservableCollection<KeyValuePair<DateTime, decimal>>();
+ }
+
+ public ICollection<KeyValuePair<DateTime, decimal>> Chart { get; set; }
+
+ public string Header
+ {
+ get { return symbol_to_watch; }
+ }
+
+ public void present()
+ {
+ }
+
+ public void notify(CurrentStockPrice message)
+ {
+ if (symbol_to_watch.Equals(message.Symbol))
+ Chart.Add(new KeyValuePair<DateTime, decimal>(Clock.now(), message.Price));
+ }
+ }
+}
\ No newline at end of file
product/desktop.ui/solidware.financials.csproj
@@ -114,6 +114,7 @@
<Compile Include="bootstrappers\ComposeShell.cs" />
<Compile Include="bootstrappers\ConfigureMappings.cs" />
<Compile Include="bootstrappers\DefaultMapper.cs" />
+ <Compile Include="presenters\SingleStockPresenter.cs" />
<Compile Include="RunInBackgroundInterceptor.cs" />
<Compile Include="bootstrappers\StopEssentialServices.cs" />
<Compile Include="bootstrappers\WireUpSubscribers.cs" />
product/specs/unit/ui/presenters/SingleStockPresenterSpecs.cs
@@ -0,0 +1,87 @@
+using System;
+using gorilla.utility;
+using Machine.Specifications;
+using solidware.financials.messages;
+using solidware.financials.windows.ui.presenters;
+
+namespace specs.unit.ui.presenters
+{
+ public class SingleStockPresenterSpecs
+ {
+ [Subject(typeof (SingleStockPresenter))]
+ public abstract class concern
+ {
+ Establish context = () =>
+ {
+ Clock.change_time_provider_to(() => now);
+ sut = new SingleStockPresenter("ARX.TO");
+ };
+
+ Cleanup clean = () =>
+ {
+ Clock.reset();
+ };
+
+ static protected SingleStockPresenter sut;
+ static protected DateTime now = new DateTime(2011, 01, 01);
+ }
+
+ public class when_a_new_price_is_received_for_the_stock_this_chart_is_for : concern
+ {
+ Establish context = () =>
+ {
+ current_price = new CurrentStockPrice
+ {
+ Symbol = "ARX.TO",
+ Price = 29.00m
+ };
+ };
+
+ Because of = () =>
+ {
+ sut.present();
+ sut.notify(current_price);
+ };
+
+ It should_update_the_chart_with_the_new_data_point = () =>
+ {
+ sut.Chart.should_contain(x => x.Key.Equals(now) && x.Value.Equals(29.00m));
+ };
+
+ static CurrentStockPrice current_price;
+ }
+
+ public class when_a_new_price_is_received_for_another_stock : concern
+ {
+ Establish context = () =>
+ {
+ current_price = new CurrentStockPrice
+ {
+ Symbol = "TD.TO",
+ Price = 90.00m
+ };
+ };
+
+ Because of = () =>
+ {
+ sut.present();
+ sut.notify(current_price);
+ };
+
+ It should_not_update_the_chart = () =>
+ {
+ sut.Chart.Count.should_be_equal_to(0);
+ };
+
+ static CurrentStockPrice current_price;
+ }
+
+ public class when_displaying_the_header_for_this_tab : concern
+ {
+ It should_describe_the_stock_that_it_is_for = () =>
+ {
+ sut.Header.should_be_equal_to("ARX.TO");
+ };
+ }
+ }
+}
\ No newline at end of file
product/specs/specs.csproj
@@ -111,6 +111,7 @@
<Compile Include="unit\ui\presenters\AddNewStockSymbolPresenterSpecs.cs" />
<Compile Include="IllegalExtensions.cs" />
<Compile Include="unit\ui\presenters\specifications\IfFamilyMemberIsSelectedSpecs.cs" />
+ <Compile Include="unit\ui\presenters\SingleStockPresenterSpecs.cs" />
<Compile Include="unit\ui\presenters\StockWatchPresenterSpecs.cs" />
<Compile Include="unit\ui\RunInBackgroundInterceptorSpecs.cs" />
</ItemGroup>