Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated

  • Loading branch information...
commit 55a13b0de7bdec4675a3a0a871d8b57ff05098f6 1 parent 29af7a2
Jean-Paul S. Boodhoo authored September 19, 2011
11  source/nothinbutdotnetprep.specs/MovieLibrarySpecs.cs
@@ -229,13 +229,22 @@ public class when_searching_for_movies : concern_for_searching_and_sorting
229 229
 
230 230
             It should_be_able_to_find_all_movies_published_after_a_certain_year = () =>
231 231
             {
232  
-                var results = sut.all_movies_published_after(2004);
  232
+                var criteria = Where<Movie>
  233
+                                    .has_an(x => x.date_published.Year)
  234
+                                    .greater_than(2004);
  235
+
  236
+                var results = sut.all_movies().all_items_matching(criteria);
  237
+
233 238
 
234 239
                 results.ShouldContainOnly(the_ring, shrek, theres_something_about_mary);
235 240
             };
236 241
 
237 242
             It should_be_able_to_find_all_movies_published_between_a_certain_range_of_years = () =>
238 243
             {
  244
+                var criteria = Where<Movie>
  245
+                                    .has_an(x => x.date_published.Year)
  246
+                                    .between(1982,2003);
  247
+
239 248
                 var results = sut.all_movies_published_between_years(1982, 2003);
240 249
 
241 250
                 results.ShouldContainOnly(indiana_jones_and_the_temple_of_doom, a_bugs_life, pirates_of_the_carribean);
2  source/nothinbutdotnetprep/nothinbutdotnetprep.csproj
@@ -66,6 +66,8 @@
66 66
     <Compile Include="collections\ProductionStudio.cs" />
67 67
     <Compile Include="collections\ReadOnlySetOf.cs" />
68 68
     <Compile Include="utility\filtering\AnonymousMatch.cs" />
  69
+    <Compile Include="utility\filtering\ComparableMatchFactory.cs" />
  70
+    <Compile Include="utility\filtering\NegatingMatch.cs" />
69 71
     <Compile Include="utility\filtering\NeverMatch.cs" />
70 72
     <Compile Include="utility\filtering\MatchFactory.cs" />
71 73
     <Compile Include="utility\filtering\Condition.cs" />
24  source/nothinbutdotnetprep/utility/filtering/ComparableMatchFactory.cs
... ...
@@ -0,0 +1,24 @@
  1
+using System;
  2
+
  3
+namespace nothinbutdotnetprep.utility.filtering
  4
+{
  5
+    public class ComparableMatchFactory<ItemToFilter, PropertyType> where PropertyType : IComparable<PropertyType>
  6
+    {
  7
+        Func<ItemToFilter, PropertyType> accessor;
  8
+
  9
+        public ComparableMatchFactory(Func<ItemToFilter, PropertyType> accessor)
  10
+        {
  11
+            this.accessor = accessor;
  12
+        }
  13
+
  14
+        public IMatchA<ItemToFilter> greater_than(PropertyType value)
  15
+        {
  16
+            return new AnonymousMatch<ItemToFilter>(x => accessor(x).CompareTo(value) > 0);
  17
+        }
  18
+
  19
+        public IMatchA<ItemToFilter> between(PropertyType start,PropertyType end)
  20
+        {
  21
+            throw new NotImplementedException();
  22
+        }
  23
+    }
  24
+}
5  source/nothinbutdotnetprep/utility/filtering/CriteriaExtensions.cs
@@ -2,6 +2,11 @@
2 2
 {
3 3
     public static class CriteriaExtensions
4 4
     {
  5
+        public static IMatchA<Item> not<Item>(this IMatchA<Item> to_negate)
  6
+        {
  7
+            return new NegatingMatch<Item>(to_negate);
  8
+        }
  9
+
5 10
         public static IMatchA<Item> or<Item>(this IMatchA<Item> left, IMatchA<Item> right)
6 11
         {
7 12
             return new OrMatch<Item>(left, right);
4  source/nothinbutdotnetprep/utility/filtering/MatchFactory.cs
@@ -3,7 +3,7 @@
3 3
 
4 4
 namespace nothinbutdotnetprep.utility.filtering
5 5
 {
6  
-    public class MatchFactory<ItemToFilter, PropertyType>
  6
+    public class MatchFactory<ItemToFilter, PropertyType> 
7 7
     {
8 8
         Func<ItemToFilter, PropertyType> accessor;
9 9
 
@@ -24,7 +24,7 @@ public IMatchA<ItemToFilter> equal_to_any(params PropertyType[] values)
24 24
 
25 25
         public IMatchA<ItemToFilter> not_equal_to(PropertyType value)
26 26
         {
27  
-            return new AnonymousMatch<ItemToFilter>(x => !x.Equals(value));
  27
+            return equal_to_any(value).not();
28 28
         }
29 29
     }
30 30
 }
17  source/nothinbutdotnetprep/utility/filtering/NegatingMatch.cs
... ...
@@ -0,0 +1,17 @@
  1
+namespace nothinbutdotnetprep.utility.filtering
  2
+{
  3
+    public class NegatingMatch<Item> : IMatchA<Item>
  4
+    {
  5
+        IMatchA<Item> original;
  6
+
  7
+        public NegatingMatch(IMatchA<Item> original)
  8
+        {
  9
+            this.original = original;
  10
+        }
  11
+
  12
+        public bool matches(Item item)
  13
+        {
  14
+            return !original.matches(item);
  15
+        }
  16
+    }
  17
+}
7  source/nothinbutdotnetprep/utility/filtering/Where.cs
@@ -4,6 +4,13 @@ namespace nothinbutdotnetprep.utility.filtering
4 4
 {
5 5
     public static class Where<ItemToFilter>
6 6
     {
  7
+        public static ComparableMatchFactory<ItemToFilter, PropertyType> has_an<PropertyType>(
  8
+            Func<ItemToFilter, PropertyType> accessor)
  9
+            where PropertyType : IComparable<PropertyType>
  10
+        {
  11
+            return new ComparableMatchFactory<ItemToFilter, PropertyType>(accessor);
  12
+        }
  13
+
7 14
         public static MatchFactory<ItemToFilter, PropertyType> has_a<PropertyType>(Func<ItemToFilter, PropertyType> accessor)
8 15
         {
9 16
             return new MatchFactory<ItemToFilter, PropertyType>(accessor);

0 notes on commit 55a13b0

Please sign in to comment.
Something went wrong with that request. Please try again.