Commits

Anonymous committed 57918af

small cleanup

  • Participants
  • Parent commits 7e3fcae

Comments (0)

Files changed (6)

File Dynamic/CSharpDynamic/DynamicFeaturesSamples.Tests/Dynamic_customer_tests.cs

 
         Customer GetCustomer()
         {
-            //return new Customer(_additionalData);
+            return new Customer(_additionalBehavior, _additionalData)
+                       {
+                           FirstName = "Jon",
+                           LastName = "Jones"
+                       };
 
             ////alternatively...
             //return new Customer(new Dictionary<string, object>
             //                            { "Comments", "Some comments..." }, 
             //                            { "NumberOfDependents", 3 }
             //                        });
-
-            // adding behavior...
-            var customer = new Customer(_additionalBehavior)
-                               {
-                                   FirstName = "Jon", LastName = "Jones"
-                               };
-            return customer;
         }
 
         void properties_are_exposed()
             (_customer as DynamicEntity).RespondTo("Comments").ShouldBeTrue();
             (_customer as DynamicEntity).RespondTo("NumberOfDependents").ShouldBeTrue();
         }
-        
+
         void getters_are_exposed()
         {
             ((string) _customer.Comments).ShouldEqual("Some comments...");
 
         void behaviors_are_accessible()
         {
-            ((string)_customer.FullName).ShouldEqual("Jon Jones");
+            ((string) _customer.FullName).ShouldEqual("Jon Jones");
         }
     }
 }

File Dynamic/CSharpDynamic/DynamicFeaturesSamples/Customer.cs

 {
     public class Customer : DynamicEntity
     {
-        public Customer(IEnumerable<KeyValuePair<string, object>> additionalData) : base(additionalData)
+        public Customer(Dictionary<string, Func<dynamic, dynamic>> additionalBehavior,
+                        Dictionary<string, object> additionalData) : base(additionalBehavior, additionalData)
         {
         }
 
-        public Customer(Dictionary<string, Func<dynamic, dynamic>> additionalBehavior) : base(additionalBehavior)
-        {
-            
-        }
-
         public string FirstName { get; set; }
         public string LastName { get; set; }
     }

File Dynamic/CSharpDynamic/DynamicFeaturesSamples/DynamicEntity.cs

         readonly Dictionary<string, Func<dynamic, dynamic>> _additionalBehavior;
         Dictionary<string, object> _additionalData = new Dictionary<string, object>();
 
-        public DynamicEntity(IEnumerable<KeyValuePair<string, object>> additionalData)
+        public DynamicEntity(Dictionary<string, Func<dynamic, dynamic>> additionalBehavior, Dictionary<string, object> additionalData)
         {
+            _additionalBehavior = additionalBehavior;
+
             foreach (var keyValuePair in additionalData)
             {
                 _additionalData.Add(keyValuePair.Key, keyValuePair.Value);
             }
         }
 
-        public DynamicEntity(Dictionary<string, Func<dynamic, dynamic>> additionalBehavior)
-        {
-            _additionalBehavior = additionalBehavior;
-        }
-
         public override bool TryGetMember(GetMemberBinder binder, out object result)
         {
             if (_additionalData.ContainsKey(binder.Name))

File Dynamic/ruby_dynamic/customer.rb

-class DynamicEntity
-
-  attr_reader :additional_behavior
-
-  def initialize(additional_behavior)
-      @additional_behavior = additional_behavior
-  end
-  
-  def respond_to?(name)
-    self.additional_behavior.include?(name)
-  end
-  
-  def method_missing(meth, *args, &block)
-    if self.additional_behavior.include?(meth)
-      self.additional_behavior[meth].call(self)
-    else
-      super
-    end
-   end
-end
+require 'dynamic_entity'
 
 class Customer < DynamicEntity
     attr_accessor :first_name, :last_name
-
 end

File Dynamic/ruby_dynamic/dynamic_entity.rb

+class DynamicEntity
+
+  attr_reader :additional_behavior
+
+  def initialize(additional_behavior)
+      @additional_behavior = additional_behavior
+  end
+  
+  def respond_to?(message)
+    self.additional_behavior.include?(message)
+  end
+  
+  def method_missing(message, *args, &block)
+    if self.additional_behavior.include?(message)
+      self.additional_behavior[message].call(self)
+    else
+      super
+    end
+   end
+end

File Dynamic/ruby_dynamic/spec/customer_spec.rb

 
 describe Customer do
 
-    describe "Dynamic Properties" do
+    describe "Dynamic Behaviors" do
     
-      context "Given additional dynamic heavior for a customer" do
+      context "Given additional dynamic beheavior for a customer" do
       
         before(:each) do
-            @additional_behavior = { :full_name => lambda { |c| "#{c.first_name} #{c.last_name}" } }
+            @additional_behavior = { :full_name => 
+                                      lambda { |c| "#{c.first_name} #{c.last_name}" } }
         end
       
         describe "When object is constructed" do