From a1005c448af4dff1c3ca7115e8b681156bb51cd3 Mon Sep 17 00:00:00 2001 From: mo Date: Mon, 4 Apr 2011 20:09:04 -0600 Subject: hook up tooltip error when no symbol is specified when adding a new stock symbol to watch. --- .../presenters/AddNewStockSymbolPresenter.cs | 28 ++++++++- .../presenters/validation/AnonymousRule.cs | 31 ++++++++++ product/desktop.ui/presenters/validation/Error.cs | 10 +++ .../presenters/validation/INotification.cs | 11 ++++ .../presenters/validation/Notification.cs | 71 ++++------------------ product/desktop.ui/presenters/validation/Rule.cs | 9 +++ .../desktop.ui/presenters/validation/Severity.cs | 7 +++ .../desktop.ui/presenters/validation/Warning.cs | 10 +++ product/desktop.ui/solidware.financials.csproj | 6 ++ .../views/dialogs/AddNewStockSymbolDialog.xaml | 31 +++++++--- .../presenters/AddNewStockSymbolPresenterSpecs.cs | 21 ++++++- 11 files changed, 162 insertions(+), 73 deletions(-) create mode 100644 product/desktop.ui/presenters/validation/AnonymousRule.cs create mode 100644 product/desktop.ui/presenters/validation/Error.cs create mode 100644 product/desktop.ui/presenters/validation/INotification.cs create mode 100644 product/desktop.ui/presenters/validation/Rule.cs create mode 100644 product/desktop.ui/presenters/validation/Severity.cs create mode 100644 product/desktop.ui/presenters/validation/Warning.cs diff --git a/product/desktop.ui/presenters/AddNewStockSymbolPresenter.cs b/product/desktop.ui/presenters/AddNewStockSymbolPresenter.cs index 07706ca..5e66358 100644 --- a/product/desktop.ui/presenters/AddNewStockSymbolPresenter.cs +++ b/product/desktop.ui/presenters/AddNewStockSymbolPresenter.cs @@ -1,29 +1,51 @@ using System; +using System.Linq.Expressions; +using gorilla.utility; using solidware.financials.infrastructure; using solidware.financials.messages; +using solidware.financials.windows.ui.presenters.validation; namespace solidware.financials.windows.ui.presenters { - public class AddNewStockSymbolPresenter : DialogPresenter + public class AddNewStockSymbolPresenter : DialogPresenter, INotification { - UICommandBuilder builder; - public AddNewStockSymbolPresenter(UICommandBuilder builder) { this.builder = builder; + Notification = new Notification(); } public ObservableCommand Add { get; set; } public ObservableCommand Cancel { get; set; } public virtual string Symbol { get; set; } public virtual Action close { get; set; } + public Notification Notification { get; set; } public void present() { Add = builder.build(this); Cancel = builder.build(this); + + Notification.Register(x => x.Symbol, () => Symbol.is_blank(), () => "Please specify a symbol."); + } + + public string this[string property] + { + get { return Notification[property]; } + } + + public string this[Expression> property] + { + get { return Notification[property]; } } + public string Error + { + get { return Notification.Error; } + } + + UICommandBuilder builder; + public class AddCommand : UICommand { ServiceBus bus; diff --git a/product/desktop.ui/presenters/validation/AnonymousRule.cs b/product/desktop.ui/presenters/validation/AnonymousRule.cs new file mode 100644 index 0000000..9804d2e --- /dev/null +++ b/product/desktop.ui/presenters/validation/AnonymousRule.cs @@ -0,0 +1,31 @@ +using System; + +namespace solidware.financials.windows.ui.presenters.validation +{ + public class AnonymousRule : Rule where Severity : validation.Severity, new() + { + readonly Func failCondition; + readonly Func errorMessage; + + public AnonymousRule(Func failCondition, Func errorMessage) + { + this.failCondition = failCondition; + this.errorMessage = errorMessage; + } + + public string ErrorMessage + { + get { return errorMessage(); } + } + + public bool IsViolatedAndMoreSevereThan() where OtherSeverity : validation.Severity, new() + { + return IsViolated() && new Severity().IsMoreSevereThan(new OtherSeverity()); + } + + public bool IsViolated() + { + return failCondition(); + } + } +} \ No newline at end of file diff --git a/product/desktop.ui/presenters/validation/Error.cs b/product/desktop.ui/presenters/validation/Error.cs new file mode 100644 index 0000000..5169f37 --- /dev/null +++ b/product/desktop.ui/presenters/validation/Error.cs @@ -0,0 +1,10 @@ +namespace solidware.financials.windows.ui.presenters.validation +{ + public class Error : Severity + { + public bool IsMoreSevereThan(OtherSeverity otherSeverity) where OtherSeverity : Severity + { + return true; + } + } +} \ No newline at end of file diff --git a/product/desktop.ui/presenters/validation/INotification.cs b/product/desktop.ui/presenters/validation/INotification.cs new file mode 100644 index 0000000..2429576 --- /dev/null +++ b/product/desktop.ui/presenters/validation/INotification.cs @@ -0,0 +1,11 @@ +using System; +using System.ComponentModel; +using System.Linq.Expressions; + +namespace solidware.financials.windows.ui.presenters.validation +{ + public interface INotification : IDataErrorInfo + { + string this[Expression> property] { get; } + } +} \ No newline at end of file diff --git a/product/desktop.ui/presenters/validation/Notification.cs b/product/desktop.ui/presenters/validation/Notification.cs index 00ea4d0..9b71b0c 100755 --- a/product/desktop.ui/presenters/validation/Notification.cs +++ b/product/desktop.ui/presenters/validation/Notification.cs @@ -1,28 +1,29 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Linq.Expressions; using gorilla.utility; namespace solidware.financials.windows.ui.presenters.validation { - public class Notification : IDataErrorInfo + public class Notification : INotification { - IDictionary> validationRules = new Dictionary>(); - - public void Register(Expression> property, Func failCondition, Func errorMessage) where Severity : ISeverity, new() + public void Register(Expression> property, Func failCondition, Func errorMessage) where Severity : validation.Severity, new() { Register(property, new AnonymousRule(failCondition, errorMessage)); } - public void Register(Expression> property, IRule rule) + public void Register(Expression> property, Rule rule) { EnsureRulesAreInitializeFor(property); validationRules[property.pick_property().Name].Add(rule); } - public string this[Expression> property] { get { return this[property.pick_property().Name]; } } + public string this[Expression> property] + { + get { return this[property.pick_property().Name]; } + } + public string this[string propertyName] { get @@ -40,7 +41,7 @@ namespace solidware.financials.windows.ui.presenters.validation get { throw new NotImplementedException(); } } - public bool AreAnyRulesViolatedAndMoreSevereThan() where Severity : ISeverity, new() + public bool AreAnyRulesViolatedAndMoreSevereThan() where Severity : validation.Severity, new() { return validationRules.Any(validationRule => validationRule.Value.Any(x => x.IsViolatedAndMoreSevereThan())); } @@ -48,10 +49,10 @@ namespace solidware.financials.windows.ui.presenters.validation void EnsureRulesAreInitializeFor(Expression> property) { if (!validationRules.ContainsKey(property.pick_property().Name)) - validationRules[property.pick_property().Name] = new List(); + validationRules[property.pick_property().Name] = new List(); } - string BuildErrorsFor(IEnumerable validationRulesForProperty) + string BuildErrorsFor(IEnumerable validationRulesForProperty) { var errors = new List(); validationRulesForProperty.each(x => @@ -60,55 +61,7 @@ namespace solidware.financials.windows.ui.presenters.validation }); return string.Join(Environment.NewLine, errors.ToArray()); } - } - public interface IRule - { - bool IsViolated(); - string ErrorMessage { get; } - bool IsViolatedAndMoreSevereThan() where Severity : ISeverity, new(); - } - public interface ISeverity - { - bool IsMoreSevereThan(OtherSeverity otherSeverity) where OtherSeverity : ISeverity; - } - public class Warning : ISeverity - { - public bool IsMoreSevereThan(OtherSeverity otherSeverity) where OtherSeverity : ISeverity - { - return !(otherSeverity is Error); - } - } - public class Error : ISeverity - { - public bool IsMoreSevereThan(OtherSeverity otherSeverity) where OtherSeverity : ISeverity - { - return true; - } - } - public class AnonymousRule : IRule where Severity : ISeverity, new() - { - readonly Func failCondition; - readonly Func errorMessage; - - public AnonymousRule(Func failCondition, Func errorMessage) - { - this.failCondition = failCondition; - this.errorMessage = errorMessage; - } - - public string ErrorMessage - { - get { return errorMessage(); } - } - public bool IsViolatedAndMoreSevereThan() where OtherSeverity : ISeverity, new() - { - return IsViolated() && new Severity().IsMoreSevereThan(new OtherSeverity()); - } - - public bool IsViolated() - { - return failCondition(); - } + IDictionary> validationRules = new Dictionary>(); } } \ No newline at end of file diff --git a/product/desktop.ui/presenters/validation/Rule.cs b/product/desktop.ui/presenters/validation/Rule.cs new file mode 100644 index 0000000..fe007a5 --- /dev/null +++ b/product/desktop.ui/presenters/validation/Rule.cs @@ -0,0 +1,9 @@ +namespace solidware.financials.windows.ui.presenters.validation +{ + public interface Rule + { + bool IsViolated(); + string ErrorMessage { get; } + bool IsViolatedAndMoreSevereThan() where Severity : validation.Severity, new(); + } +} \ No newline at end of file diff --git a/product/desktop.ui/presenters/validation/Severity.cs b/product/desktop.ui/presenters/validation/Severity.cs new file mode 100644 index 0000000..058353e --- /dev/null +++ b/product/desktop.ui/presenters/validation/Severity.cs @@ -0,0 +1,7 @@ +namespace solidware.financials.windows.ui.presenters.validation +{ + public interface Severity + { + bool IsMoreSevereThan(OtherSeverity otherSeverity) where OtherSeverity : Severity; + } +} \ No newline at end of file diff --git a/product/desktop.ui/presenters/validation/Warning.cs b/product/desktop.ui/presenters/validation/Warning.cs new file mode 100644 index 0000000..3801ef3 --- /dev/null +++ b/product/desktop.ui/presenters/validation/Warning.cs @@ -0,0 +1,10 @@ +namespace solidware.financials.windows.ui.presenters.validation +{ + public class Warning : Severity + { + public bool IsMoreSevereThan(OtherSeverity otherSeverity) where OtherSeverity : Severity + { + return !(otherSeverity is Error); + } + } +} \ No newline at end of file diff --git a/product/desktop.ui/solidware.financials.csproj b/product/desktop.ui/solidware.financials.csproj index dedc36b..23936cb 100644 --- a/product/desktop.ui/solidware.financials.csproj +++ b/product/desktop.ui/solidware.financials.csproj @@ -114,8 +114,14 @@ + + + + + + diff --git a/product/desktop.ui/views/dialogs/AddNewStockSymbolDialog.xaml b/product/desktop.ui/views/dialogs/AddNewStockSymbolDialog.xaml index 400674a..e92662e 100644 --- a/product/desktop.ui/views/dialogs/AddNewStockSymbolDialog.xaml +++ b/product/desktop.ui/views/dialogs/AddNewStockSymbolDialog.xaml @@ -1,12 +1,23 @@  - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/product/specs/unit/ui/presenters/AddNewStockSymbolPresenterSpecs.cs b/product/specs/unit/ui/presenters/AddNewStockSymbolPresenterSpecs.cs index 8fdbd42..da96e04 100644 --- a/product/specs/unit/ui/presenters/AddNewStockSymbolPresenterSpecs.cs +++ b/product/specs/unit/ui/presenters/AddNewStockSymbolPresenterSpecs.cs @@ -50,6 +50,22 @@ namespace specs.unit.ui.presenters static ObservableCommand cancel_command; } + public class when_a_blank_symbol_is_entered : concern + { + Because of = () => + { + sut.present(); + result = sut[x => x.Symbol]; + }; + + It should_display_an_error = () => + { + result.should_be_equal_to("Please specify a symbol."); + }; + + static string result; + } + public class AddCommandSpecs { public abstract class concern_for_add_command @@ -70,7 +86,10 @@ namespace specs.unit.ui.presenters { presenter = Create.an(); presenter.is_told_to(x => x.Symbol).it_will_return("TD.TO"); - presenter.Stub(x => x.close).Return(() => { closed = true; }); + presenter.Stub(x => x.close).Return(() => + { + closed = true; + }); }; Because of = () => -- cgit v1.2.3