Commit fe053c6
Changed files (7)
product
desktop.ui
bootstrappers
presenters
messages
specs
product/desktop.ui/bootstrappers/Bootstrapper.cs
@@ -115,6 +115,7 @@ namespace solidware.financials.windows.ui.bootstrappers
builder.RegisterType<PublishEventHandler<AddedNewFamilyMember>>().As<Handles<AddedNewFamilyMember>>();
builder.RegisterType<PublishEventHandler<IncomeMessage>>().As<Handles<IncomeMessage>>();
builder.RegisterType<PublishEventHandler<CurrentStockPrice>>().As<Handles<CurrentStockPrice>>();
+ builder.RegisterType<PublishEventHandler<StartWatchingSymbol>>().As<Handles<StartWatchingSymbol>>();
}
static void server_registration(ContainerBuilder builder)
product/desktop.ui/presenters/StockViewModel.cs
@@ -4,6 +4,12 @@ namespace solidware.financials.windows.ui.presenters
{
public class StockViewModel
{
+ public StockViewModel(string symbol)
+ {
+ Symbol = symbol;
+ Price = 0m.ToObservable();
+ }
+
public string Symbol { get; set; }
public Observable<decimal> Price { get; set; }
product/desktop.ui/presenters/StockWatchPresenter.cs
@@ -11,7 +11,7 @@ using solidware.financials.windows.ui.views.dialogs;
namespace solidware.financials.windows.ui.presenters
{
- public class StockWatchPresenter : Presenter, TimerClient, EventSubscriber<CurrentStockPrice>
+ public class StockWatchPresenter : Presenter, TimerClient, EventSubscriber<CurrentStockPrice>, EventSubscriber<StartWatchingSymbol>
{
UICommandBuilder builder;
Timer timer;
@@ -24,7 +24,7 @@ namespace solidware.financials.windows.ui.presenters
this.timer = timer;
}
- public virtual IEnumerable<StockViewModel> Stocks { get; set; }
+ public virtual ICollection<StockViewModel> Stocks { get; set; }
public ObservableCommand AddSymbol { get; set; }
public void present()
@@ -44,6 +44,11 @@ namespace solidware.financials.windows.ui.presenters
Stocks.Single(x => x.IsFor(message.Symbol)).ChangePriceTo(message.Price);
}
+ public void notify(StartWatchingSymbol message)
+ {
+ Stocks.Add(new StockViewModel(symbol: message.Symbol));
+ }
+
public class AddSymbolCommand : UICommand<StockWatchPresenter>
{
DialogLauncher launcher;
product/messages/StartWatchingSymbol.cs
@@ -1,8 +1,9 @@
using gorilla.utility;
+using solidware.financials.infrastructure.eventing;
namespace solidware.financials.messages
{
- public class StartWatchingSymbol : ValueType<StartWatchingSymbol>
+ public class StartWatchingSymbol : ValueType<StartWatchingSymbol>, Event
{
public string Symbol { get; set; }
}
product/specs/unit/ui/presenters/StockWatchPresenterSpecs.cs
@@ -80,9 +80,8 @@ namespace specs.unit.ui.presenters
{
Establish context = () =>
{
- sut.Stocks.Add(new StockViewModel
+ sut.Stocks.Add(new StockViewModel(symbol:"ARX.TO")
{
- Symbol = "ARX.TO",
Price = 20.00m.ToObservable()
});
};
@@ -98,6 +97,19 @@ namespace specs.unit.ui.presenters
};
}
+ public class when_starting_to_watch_a_new_symbol : concern
+ {
+ Because of = () =>
+ {
+ sut.notify(new StartWatchingSymbol {Symbol = "TD.TO",});
+ };
+
+ It should_add_the_new_symbol_to_the_list_of_stocks_to_watch = () =>
+ {
+ sut.Stocks.should_contain(x => x.Symbol.Equals("TD.TO"));
+ };
+ }
+
public class AddSymbolCommandSpecs
{
public class when_a_user_wants_to_watch_a_new_symbol
@@ -145,7 +157,7 @@ namespace specs.unit.ui.presenters
Establish context = () =>
{
presenter = Create.an<StockWatchPresenter>();
- presenter.is_told_to(x => x.Stocks).it_will_return(new StockViewModel {Symbol = "ARX.TO"});
+ presenter.is_told_to(x => x.Stocks).it_will_return(new StockViewModel (symbol : "ARX.TO"));
};
Because of = () =>
product/specs/Assertions.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Linq.Expressions;
+using gorilla.utility;
using Machine.Specifications;
namespace specs
@@ -42,6 +44,20 @@ namespace specs
items_to_peek_in_to.Contains(items_to_look_for).should_be_true();
}
+ static public void should_contain<T>(this IEnumerable<T> items, params T[] items_to_find)
+ {
+ foreach (var item_to_find in items_to_find)
+ {
+ items.should_contain(item_to_find);
+ }
+ }
+
+ static public void should_contain<T>(this IEnumerable<T> items, Expression<Func<T, bool>> criteria)
+ {
+ if (items.Any(criteria.Compile())) return;
+ throw new ArgumentException("Could not find {0}".format(criteria));
+ }
+
static public void should_not_contain<T>(this IEnumerable<T> items_to_peek_into, T item_to_look_for)
{
items_to_peek_into.Contains(item_to_look_for).should_be_false();
@@ -72,13 +88,6 @@ namespace specs
item.ShouldBeFalse();
}
- static public void should_contain<T>(this IEnumerable<T> items, params T[] items_to_find)
- {
- foreach (var item_to_find in items_to_find)
- {
- items.should_contain(item_to_find);
- }
- }
static public void should_only_contain<T>(this IEnumerable<T> items, params T[] itemsToFind)
{
product/specs/Mocking.cs
@@ -43,12 +43,17 @@ namespace specs
return options.Return(item);
}
+ static public IMethodOptions<ICollection<R>> it_will_return<R>(this IMethodOptions<ICollection<R>> options, params R[] items)
+ {
+ return options.Return(items.ToList());
+ }
+
static public IMethodOptions<IEnumerable<R>> it_will_return<R>(this IMethodOptions<IEnumerable<R>> options, params R[] items)
{
return options.Return(items.AsEnumerable());
}
- static public IMethodOptions<IEnumerable<R>> it_will_return_nothing<R>( this IMethodOptions<IEnumerable<R>> options)
+ static public IMethodOptions<IEnumerable<R>> it_will_return_nothing<R>(this IMethodOptions<IEnumerable<R>> options)
{
return options.it_will_return();
}