Commit b0d5cf6

mo khan <mo@mokhan.ca>
2009-05-11 21:26:46
started implementing a rebind command to rebind an item when the text in a textbox changes.
1 parent 86d3747
product/Gorilla.Commons.Windows.Forms/Helpers/BindableTextBox.cs
@@ -4,6 +4,7 @@ namespace Gorilla.Commons.Windows.Forms.Helpers
     {
         void bind_to(T item);
         T get_selected_value();
+        string text();
     }
 
     public class BindableTextBox<T> : IBindableTextBox<T>
@@ -24,5 +25,10 @@ namespace Gorilla.Commons.Windows.Forms.Helpers
         {
             return control.get_selected_item();
         }
+
+        public string text()
+        {
+            return control.text();
+        }
     }
 }
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Helpers/BindableTextBoxSpecs.cs
@@ -33,4 +33,14 @@ namespace Gorilla.Commons.Windows.Forms.Helpers
 
         static string result;
     }
+
+    //public class when_the_value_of_a_textbox_changes : concerns_for_text_box
+    //{
+    //    it should_apply_the_new_value_to_the_text_control = () => {
+                         
+    //    };
+
+    //    because b = () => {
+    //    };
+    //}
 }
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Helpers/Events.cs
@@ -21,6 +21,7 @@ namespace Gorilla.Commons.Windows.Forms.Helpers
             void OnMouseWheel(MouseEventArgs args);
             void OnValidated(EventArgs args);
             void OnValidating(CancelEventArgs args);
+            void OnLeave(EventArgs args);
         }
 
         public interface FormEvents : ControlEvents
product/Gorilla.Commons.Windows.Forms/Helpers/ITextBoxCommand.cs
@@ -0,0 +1,8 @@
+using Gorilla.Commons.Utility.Core;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+    public interface ITextBoxCommand<T> : IParameterizedCommand<IBindableTextBox<T>>
+    {
+    }
+}
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Helpers/ITextControl.cs
@@ -4,5 +4,6 @@ namespace Gorilla.Commons.Windows.Forms.Helpers
     {
         void set_selected_item(ItemToStore item);
         ItemToStore get_selected_item();
+        string text();
     }
 }
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Helpers/RebindTextBoxCommand.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Linq.Expressions;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+    public class RebindTextBoxCommand<T> : ITextBoxCommand<T>
+    {
+        readonly Expression<Func<string, T>> binder;
+
+        public RebindTextBoxCommand(Expression<Func<string, T>> binder)
+        {
+            this.binder = binder;
+        }
+
+        public void run(IBindableTextBox<T> item)
+        {
+            item.bind_to(binder.Compile()(item.text()));
+        }
+    }
+}
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Helpers/RebindTextBoxCommandSpecs.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Linq.Expressions;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+
+namespace Gorilla.Commons.Windows.Forms.Helpers
+{
+    public class RebindTextBoxCommandSpecs
+    {
+    }
+
+    [Concern(typeof (RebindTextBoxCommand<>))]
+    public class when_the_text_in_a_textbox_changes :
+        concerns_for<ITextBoxCommand<string>, RebindTextBoxCommand<string>>
+    {
+        context c = () =>
+                        {
+                            textbox = an<IBindableTextBox<string>>();
+                            binder = x => "";
+                        };
+
+        public override ITextBoxCommand<string> create_sut()
+        {
+            return new RebindTextBoxCommand<string>(binder);
+        }
+
+        static protected IBindableTextBox<string> textbox;
+        static protected Expression<Func<string, string>> binder;
+    }
+
+    [Concern(typeof (RebindTextBoxCommand<>))]
+    public class when_rebinding_an_item_to_a_textbox : when_the_text_in_a_textbox_changes
+    {
+        it should_bind_the_text_control_to_the_new_item = () => textbox.was_told_to(x => x.bind_to("kat"));
+
+        context c = () =>
+                        {
+                            binder = x => "kat";
+                            when_the(textbox).is_told_to(x => x.text()).it_will_return("kitty");
+                        };
+
+        because b = () => sut.run(textbox);
+    }
+}
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Helpers/TextControl.cs
@@ -22,5 +22,10 @@ namespace Gorilla.Commons.Windows.Forms.Helpers
         {
             return selected_item;
         }
+
+        public string text()
+        {
+            return textbox.Text;
+        }
     }
 }
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Gorilla.Commons.Windows.Forms.csproj
@@ -96,8 +96,11 @@
     <Compile Include="Helpers\IBindableList.cs" />
     <Compile Include="Helpers\IEventTarget.cs" />
     <Compile Include="Helpers\IListControl.cs" />
+    <Compile Include="Helpers\ITextBoxCommand.cs" />
     <Compile Include="Helpers\ITextControl.cs" />
     <Compile Include="Helpers\ListBoxListControl.cs" />
+    <Compile Include="Helpers\RebindTextBoxCommand.cs" />
+    <Compile Include="Helpers\RebindTextBoxCommandSpecs.cs" />
     <Compile Include="Helpers\SuspendLayout.cs" />
     <Compile Include="Helpers\TextControl.cs" />
     <Compile Include="Helpers\TextControlSpecs.cs" />