Commit 86d3747
Changed files (5)
product
Gorilla.Commons.Windows.Forms
product/Gorilla.Commons.Windows.Forms/Helpers/BindableTextBox.cs
@@ -0,0 +1,28 @@
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public interface IBindableTextBox<T>
+ {
+ void bind_to(T item);
+ T get_selected_value();
+ }
+
+ public class BindableTextBox<T> : IBindableTextBox<T>
+ {
+ readonly ITextControl<T> control;
+
+ public BindableTextBox(ITextControl<T> control)
+ {
+ this.control = control;
+ }
+
+ public void bind_to(T item)
+ {
+ control.set_selected_item(item);
+ }
+
+ public T get_selected_value()
+ {
+ return control.get_selected_item();
+ }
+ }
+}
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Helpers/BindableTextBoxSpecs.cs
@@ -0,0 +1,36 @@
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class BindableTextBoxSpecs
+ {
+ }
+
+ [Concern(typeof (BindableTextBox<>))]
+ public class concerns_for_text_box : concerns_for<IBindableTextBox<string>, BindableTextBox<string>>
+ {
+ context c = () => { control = the_dependency<ITextControl<string>>(); };
+
+ static protected ITextControl<string> control;
+ }
+
+ [Concern(typeof (BindableTextBox<>))]
+ public class when_binding_an_item_to_a_textbox : concerns_for_text_box
+ {
+ it should_change_the_text_of_the_text_control = () => control.was_told_to(x => x.set_selected_item("shrek"));
+
+ because b = () => sut.bind_to("shrek");
+ }
+
+ [Concern(typeof (BindableTextBox<>))]
+ public class when_getting_the_current_value_of_a_text_box : concerns_for_text_box
+ {
+ it should_return_the_current_value_of_the_text_box = () => result.should_be_equal_to("popeye");
+
+ context c = () => when_the(control).is_told_to(x => x.get_selected_item()).it_will_return("popeye");
+ because b = () => { result = sut.get_selected_value(); };
+
+ static string result;
+ }
+}
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Helpers/ITextControl.cs
@@ -0,0 +1,8 @@
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public interface ITextControl<ItemToStore>
+ {
+ void set_selected_item(ItemToStore item);
+ ItemToStore get_selected_item();
+ }
+}
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Helpers/TextControl.cs
@@ -0,0 +1,26 @@
+using System.Windows.Forms;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class TextControl<ItemToStore> : ITextControl<ItemToStore>
+ {
+ readonly TextBox textbox;
+ ItemToStore selected_item;
+
+ public TextControl(TextBox textbox)
+ {
+ this.textbox = textbox;
+ }
+
+ public void set_selected_item(ItemToStore item)
+ {
+ textbox.Text = item.ToString();
+ selected_item = item;
+ }
+
+ public ItemToStore get_selected_item()
+ {
+ return selected_item;
+ }
+ }
+}
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Helpers/TextControlSpecs.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Windows.Forms;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+ public class TextControlSpecs
+ {
+ }
+
+ [Concern(typeof (TextControl<>))]
+ public abstract class behaves_like_text_control : concerns_for<ITextControl<DateTime>, TextControl<DateTime>>
+ {
+ context c = () => { textbox = new TextBox(); };
+
+ public override ITextControl<DateTime> create_sut()
+ {
+ return new TextControl<DateTime>(textbox);
+ }
+
+ static protected TextBox textbox;
+ }
+
+ [Concern(typeof (TextControl<>))]
+ public class when_a_text_control_is_bound_to_an_item : behaves_like_text_control
+ {
+ it should_display_the_textual_version_of_the_item = () => textbox.Text.should_be_equal_to(date.ToString());
+
+ it should_bind_to_that_item = () => sut.get_selected_item().should_be_equal_to(date);
+
+ context c = () => { date = new DateTime(1984, 04, 28); };
+
+ because b = () => sut.set_selected_item(date);
+
+ static DateTime date;
+ }
+}
\ No newline at end of file