Commit db77867
Changed files (5)
product
desktop.ui
presenters
messages
specs
unit
ui
presenters
product/desktop.ui/presenters/AddNewStockSymbolPresenter.cs
@@ -1,18 +1,42 @@
using System;
+using solidware.financials.infrastructure;
+using solidware.financials.messages;
namespace solidware.financials.windows.ui.presenters
{
public class AddNewStockSymbolPresenter : DialogPresenter
{
+ readonly UICommandBuilder builder;
+
+ public AddNewStockSymbolPresenter(UICommandBuilder builder)
+ {
+ this.builder = builder;
+ }
+
+ public ObservableCommand Add { get; set; }
+ public ObservableCommand Cancel { get; set; }
+ public virtual string Symbol { get; set; }
+ public Action close { get; set; }
+
public void present()
{
- throw new NotImplementedException();
+ Add = builder.build<AddCommand>(this);
+ Cancel = builder.build<CancelCommand>(this);
}
- public Action close
+ public class AddCommand : UICommand<AddNewStockSymbolPresenter>
{
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
+ ServiceBus bus;
+
+ public AddCommand(ServiceBus bus)
+ {
+ this.bus = bus;
+ }
+
+ public override void run(AddNewStockSymbolPresenter presenter)
+ {
+ bus.publish(new StartWatchingSymbol {Symbol = presenter.Symbol});
+ }
}
}
}
\ No newline at end of file
product/messages/messages.csproj
@@ -49,6 +49,7 @@
<Compile Include="FamilyMemberToAdd.cs" />
<Compile Include="FindAllFamily.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="StartWatchingSymbol.cs" />
<Compile Include="StockPriceRequestQuery.cs" />
</ItemGroup>
<ItemGroup>
product/messages/StartWatchingSymbol.cs
@@ -0,0 +1,9 @@
+using gorilla.utility;
+
+namespace solidware.financials.messages
+{
+ public class StartWatchingSymbol : ValueType<StartWatchingSymbol>
+ {
+ public string Symbol { get; set; }
+ }
+}
\ No newline at end of file
product/specs/unit/ui/presenters/AddNewStockSymbolPresenterSpecs.cs
@@ -0,0 +1,88 @@
+using Machine.Specifications;
+using solidware.financials.infrastructure;
+using solidware.financials.messages;
+using solidware.financials.windows.ui;
+using solidware.financials.windows.ui.presenters;
+
+namespace specs.unit.ui.presenters
+{
+ public class AddNewStockSymbolPresenterSpecs
+ {
+ public abstract class concern
+ {
+ Establish context = () =>
+ {
+ builder = Create.dependency<UICommandBuilder>();
+ sut = new AddNewStockSymbolPresenter(builder);
+ };
+
+ static protected AddNewStockSymbolPresenter sut;
+ static protected UICommandBuilder builder;
+ }
+
+ public class when_loading_the_dialog : concern
+ {
+ Establish context = () =>
+ {
+ add_command = Create.an<ObservableCommand>();
+ cancel_command = Create.an<ObservableCommand>();
+ builder.is_told_to(x => x.build<AddNewStockSymbolPresenter.AddCommand>(sut)).it_will_return(add_command);
+ builder.is_told_to(x => x.build<CancelCommand>(sut)).it_will_return(cancel_command);
+ };
+
+ Because of = () =>
+ {
+ sut.present();
+ };
+
+ It should_build_the_add_command = () =>
+ {
+ sut.Add.should_be_equal_to(add_command);
+ };
+
+ It should_build_the_cancel_command = () =>
+ {
+ sut.Cancel.should_be_equal_to(cancel_command);
+ };
+
+ static ObservableCommand add_command;
+ static ObservableCommand cancel_command;
+ }
+
+ public class AddCommandSpecs
+ {
+ public abstract class concern_for_add_command
+ {
+ Establish context = () =>
+ {
+ bus = Create.dependency<ServiceBus>();
+ sut = new AddNewStockSymbolPresenter.AddCommand(bus);
+ };
+
+ static protected ServiceBus bus;
+ static protected AddNewStockSymbolPresenter.AddCommand sut;
+ }
+
+ public class when_adding_a_new_symbol_to_watch : concern_for_add_command
+ {
+ Establish context = () =>
+ {
+ presenter = Create.an<AddNewStockSymbolPresenter>();
+ presenter.is_told_to(x => x.Symbol).it_will_return("TD.TO");
+ };
+
+ Because of = () =>
+ {
+ sut.run(presenter);
+ };
+
+ It should_publish_a_message_to_save_that_symbol = () =>
+ {
+ bus.received(x => x.publish(new StartWatchingSymbol {Symbol = "TD.TO"}));
+ };
+
+ static AddNewStockSymbolPresenter presenter;
+ }
+ }
+ }
+}
\ No newline at end of file
product/specs/specs.csproj
@@ -106,6 +106,7 @@
<Compile Include="unit\ui\InMemoryApplicationStateSpecs.cs" />
<Compile Include="unit\ui\presenters\AddFamilyMemberPresenterSpecs.cs" />
<Compile Include="unit\ui\presenters\AddNewIncomeViewModelSpecs.cs" />
+ <Compile Include="unit\ui\presenters\AddNewStockSymbolPresenterSpecs.cs" />
<Compile Include="unit\ui\presenters\specifications\IfFamilyMemberIsSelectedSpecs.cs" />
<Compile Include="unit\ui\presenters\StockWatchPresenterSpecs.cs" />
</ItemGroup>