Commit d182815
Changed files (6)
product
desktop.ui
bootstrappers
presenters
specs
product/desktop.ui/bootstrappers/Bootstrapper.cs
@@ -3,7 +3,6 @@ using System.Threading;
using System.Windows;
using System.Windows.Threading;
using Autofac;
-using Castle.DynamicProxy;
using gorilla.infrastructure.container;
using gorilla.infrastructure.threading;
using gorilla.utility;
product/desktop.ui/presenters/StockViewModel.cs
@@ -6,5 +6,15 @@ namespace solidware.financials.windows.ui.presenters
{
public string Symbol { get; set; }
public Observable<decimal> Price { get; set; }
+
+ public bool IsFor(string symbol)
+ {
+ return Symbol.Equals(symbol);
+ }
+
+ public void ChangePriceTo(decimal price)
+ {
+ Price.Value = price;
+ }
}
}
\ No newline at end of file
product/desktop.ui/presenters/StockWatchPresenter.cs
@@ -1,15 +1,17 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
using gorilla.infrastructure.threading;
using gorilla.utility;
using solidware.financials.infrastructure;
+using solidware.financials.infrastructure.eventing;
using solidware.financials.messages;
using solidware.financials.windows.ui.views.dialogs;
namespace solidware.financials.windows.ui.presenters
{
- public class StockWatchPresenter : Presenter, TimerClient
+ public class StockWatchPresenter : Presenter, TimerClient, EventSubscriber<CurrentStockPrice>
{
UICommandBuilder builder;
Timer timer;
@@ -17,11 +19,7 @@ namespace solidware.financials.windows.ui.presenters
public StockWatchPresenter(UICommandBuilder builder, Timer timer)
{
- Stocks = new ObservableCollection<StockViewModel>
- {
- new StockViewModel {Symbol = "ARX.TO", Price = 25.00m.ToObservable()},
- new StockViewModel {Symbol = "TD.TO", Price = 85.00m.ToObservable()},
- };
+ Stocks = new ObservableCollection<StockViewModel>();
this.builder = builder;
this.timer = timer;
}
@@ -41,6 +39,11 @@ namespace solidware.financials.windows.ui.presenters
refresh_command.Execute(this);
}
+ public void notify(CurrentStockPrice message)
+ {
+ Stocks.Single(x => x.IsFor(message.Symbol)).ChangePriceTo(message.Price);
+ }
+
public class AddSymbolCommand : UICommand<StockWatchPresenter>
{
DialogLauncher launcher;
product/specs/unit/ui/presenters/StockWatchPresenterSpecs.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using gorilla.infrastructure.threading;
using Machine.Specifications;
using Rhino.Mocks;
@@ -75,6 +76,28 @@ namespace specs.unit.ui.presenters
static ObservableCommand refresh_command;
}
+ public class when_a_stock_price_changes : concern
+ {
+ Establish context = () =>
+ {
+ sut.Stocks.Add(new StockViewModel
+ {
+ Symbol = "ARX.TO",
+ Price = 20.00m.ToObservable()
+ });
+ };
+
+ Because of = () =>
+ {
+ sut.notify(new CurrentStockPrice {Symbol = "ARX.TO", Price = 25.50m});
+ };
+
+ It should_display_the_new_price = () =>
+ {
+ sut.Stocks.Last().Price.Value.should_be_equal_to(25.50m);
+ };
+ }
+
public class AddSymbolCommandSpecs
{
public class when_a_user_wants_to_watch_a_new_symbol
product/specs/IllegalExtensions.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+
+namespace specs
+{
+ static public class IllegalExtensions
+ {
+ static public void Add<T>(this IEnumerable<T> items, T item)
+ {
+ var collection = items as ICollection<T>;
+ if (null == collection) throw new ArgumentException("this aint a collection, buddy!");
+ collection.Add(item);
+ }
+ }
+}
\ No newline at end of file
product/specs/specs.csproj
@@ -108,6 +108,7 @@
<Compile Include="unit\ui\presenters\AddFamilyMemberPresenterSpecs.cs" />
<Compile Include="unit\ui\presenters\AddNewIncomeViewModelSpecs.cs" />
<Compile Include="unit\ui\presenters\AddNewStockSymbolPresenterSpecs.cs" />
+ <Compile Include="IllegalExtensions.cs" />
<Compile Include="unit\ui\presenters\specifications\IfFamilyMemberIsSelectedSpecs.cs" />
<Compile Include="unit\ui\presenters\StockWatchPresenterSpecs.cs" />
<Compile Include="unit\ui\RunInBackgroundInterceptorSpecs.cs" />