main
  1using Machine.Specifications;
  2using Rhino.Mocks;
  3using solidware.financials.infrastructure;
  4using solidware.financials.messages;
  5using solidware.financials.windows.ui;
  6using solidware.financials.windows.ui.presenters;
  7
  8namespace specs.unit.ui.presenters
  9{
 10    public class AddNewStockSymbolPresenterSpecs
 11    {
 12        public abstract class concern
 13        {
 14            Establish context = () =>
 15            {
 16                builder = Create.dependency<UICommandBuilder>();
 17                sut = new AddNewStockSymbolPresenter(builder);
 18            };
 19
 20            static protected AddNewStockSymbolPresenter sut;
 21            static protected UICommandBuilder builder;
 22        }
 23
 24        public class when_loading_the_dialog : concern
 25        {
 26            Establish context = () =>
 27            {
 28                add_command = Create.an<ObservableCommand>();
 29                cancel_command = Create.an<ObservableCommand>();
 30                builder.is_told_to(x => x.build<AddNewStockSymbolPresenter.AddCommand, AddNewStockSymbolPresenter.IsValid>(sut)).it_will_return(add_command);
 31                builder.is_told_to(x => x.build<CancelCommand>(sut)).it_will_return(cancel_command);
 32            };
 33
 34            Because of = () =>
 35            {
 36                sut.present();
 37            };
 38
 39            It should_build_the_add_command = () =>
 40            {
 41                sut.Add.should_be_equal_to(add_command);
 42            };
 43
 44            It should_build_the_cancel_command = () =>
 45            {
 46                sut.Cancel.should_be_equal_to(cancel_command);
 47            };
 48
 49            static ObservableCommand add_command;
 50            static ObservableCommand cancel_command;
 51        }
 52
 53        public class when_a_blank_symbol_is_entered : concern
 54        {
 55            Because of = () =>
 56            {
 57                sut.present();
 58                result = sut.Symbol["Value"];
 59            };
 60
 61            It should_display_an_error = () =>
 62            {
 63                result.should_be_equal_to("Please specify a symbol.");
 64            };
 65
 66            static string result;
 67        }
 68
 69        public class AddCommandSpecs
 70        {
 71            public abstract class concern_for_add_command
 72            {
 73                Establish context = () =>
 74                {
 75                    bus = Create.dependency<ServiceBus>();
 76                    sut = new AddNewStockSymbolPresenter.AddCommand(bus);
 77                };
 78
 79                static protected ServiceBus bus;
 80                static protected AddNewStockSymbolPresenter.AddCommand sut;
 81            }
 82
 83            public class when_adding_a_new_symbol_to_watch : concern_for_add_command
 84            {
 85                Establish context = () =>
 86                {
 87                    presenter = Create.an<AddNewStockSymbolPresenter>();
 88                    presenter.is_told_to(x => x.Symbol).it_will_return("TD.TO".ToObservable());
 89                    presenter.Stub(x => x.close).Return(() =>
 90                    {
 91                        closed = true;
 92                    });
 93                };
 94
 95                Because of = () =>
 96                {
 97                    sut.run(presenter);
 98                };
 99
100                It should_publish_a_message_to_save_that_symbol = () =>
101                {
102                    bus.received(x => x.publish(new StartWatchingSymbol {Symbol = "TD.TO"}));
103                };
104
105                It should_close_the_dialog = () =>
106                {
107                    closed.should_be_true();
108                };
109
110                static AddNewStockSymbolPresenter presenter;
111                static bool closed;
112            }
113        }
114
115        public class IsValidSpecs
116        {
117            public class concern
118            {
119                Establish context = () =>
120                {
121                    sut = new AddNewStockSymbolPresenter.IsValid();
122                };
123
124                static protected AddNewStockSymbolPresenter.IsValid sut;
125            }
126
127            public class when_a_valid_symbol_is_entered : concern
128            {
129                Establish context = () =>
130                {
131                    presenter = Create.an<AddNewStockSymbolPresenter>();
132                    presenter.is_told_to(x => x.Symbol).it_will_return("ARX.TO".ToObservable());
133                };
134
135                Because of = () =>
136                {
137                    result = sut.is_satisfied_by(presenter);
138                };
139
140                It should_be_valid = () =>
141                {
142                    result.should_be_true();
143                };
144
145                static bool result;
146                static AddNewStockSymbolPresenter presenter;
147            }
148
149            public class when_a_invalid_symbol_is_entered : concern
150            {
151                Establish context = () =>
152                {
153                    presenter = Create.an<AddNewStockSymbolPresenter>();
154                    presenter.is_told_to(x => x.Symbol).it_will_return("".ToObservable());
155                };
156
157                Because of = () =>
158                {
159                    result = sut.is_satisfied_by(presenter);
160                };
161
162                It should_be_invalid = () =>
163                {
164                    result.should_be_false();
165                };
166
167                static bool result;
168                static AddNewStockSymbolPresenter presenter;
169            }
170        }
171    }
172}