Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome, Safari or Firefox browser.

Stack Trace Preview [use arrow keys to navigate]
about: Awesome sample to show others - Fork me on GitHub - An integral part of Oak


toc
Sample\BorrowedGames\Models\User.cs - 152
        
142  }
143
144  public void MarkGameNotInterested(dynamic gameId)
145  {
146      notInterestedGames.Insert(_.NotInterestedGames().New(new { gameId }));
147  }
148
149  public bool GameIsWanted(dynamic game)
150  {
151      return _.Wantss().Any(new { GameId = game.Id, FromUserId = game.User.Id });
152  }
153
154  public bool HasNotBeenRequested(dynamic game)
155  {
156      return !GameIsWanted(game);
157  }
158
159  public bool OwnsGame(dynamic gameId)
160  {
161      return _.Games().Any(new { Id = gameId });
162  }

        
toc
Sample\BorrowedGames\Models\User.cs - 157
        
147  }
148
149  public bool GameIsWanted(dynamic game)
150  {
151      return _.Wantss().Any(new { GameId = game.Id, FromUserId = game.User.Id });
152  }
153
154  public bool HasNotBeenRequested(dynamic game)
155  {
156      return !GameIsWanted(game);
157  }
158
159  public bool OwnsGame(dynamic gameId)
160  {
161      return _.Games().Any(new { Id = gameId });
162  }
163
164  bool DoesNotOwnGame(dynamic gameId)
165  {
166      return !OwnsGame(gameId);
167  }

        
toc
Sample\BorrowedGames\Models\User.cs - 211
        
201  {
202      return _.Friends().Games();
203  }
204
205  public IEnumerable<dynamic> PreferredGames()
206  {
207      var preferredGames =
208          GamesFriendsHave()
209              .Where(s =>
210                  DoesNotOwnGame(s.Id) &&
211                  PrefersGame(s.Id) &&
212                  SharesConsole(s.Console) &&
213                  HasNotBeenRequested(s))
214              .Select(PreferredGame)
215              .OrderByDescending(s => s.IsFavorited)
216              .ThenBy(s => s.Name)
217              .ToModels();
218
219      return preferredGames;
220  }
221

        
toc
Sample\BorrowedGames\Models\User.cs - 208
        
198  }
199
200  public IEnumerable<dynamic> GamesFriendsHave()
201  {
202      return _.Friends().Games();
203  }
204
205  public IEnumerable<dynamic> PreferredGames()
206  {
207      var preferredGames =
208          GamesFriendsHave()
209              .Where(s =>
210                  DoesNotOwnGame(s.Id) &&
211                  PrefersGame(s.Id) &&
212                  SharesConsole(s.Console) &&
213                  HasNotBeenRequested(s))
214              .Select(PreferredGame)
215              .OrderByDescending(s => s.IsFavorited)
216              .ThenBy(s => s.Name)
217              .ToModels();
218

        
toc
Sample\BorrowedGames\Controllers\GamesController.cs - 18
        
8
9  namespace BorrowedGames.Controllers
10  {
11      public class GamesController : BaseController
12      {
13          Games games = new Games();
14
15          public dynamic Preferred()
16          {
17              return Json(LinksForPreferredGames(User().PreferredGames()));
18          }
19
20          public dynamic Wanted()
21          {
22              return Json(LinksForWantedGames(User().WantedGames()));
23          }
24        
25          public dynamic Requested()
26          {   
27              return Json(LinksForRequestedGames(User().RequestedGames()));
28          }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\_games_controller.cs - 68
        
58  }
59
60  public IEnumerable<dynamic> RequestedGames()
61  {
62      return controller.Requested().Data;
63  }
64
65  public IEnumerable<dynamic> PreferredGames()
66  {
67      return controller.Preferred().Data;
68  }
69
70  public dynamic FirstWantedGame(int userId)
71  {
72      return WantedGames(userId).First();
73  }
74
75  public IEnumerable<dynamic> WantedGames(int userId)
76  {
77      return User(userId).WantedGames();
78  }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\_games_controller.cs - 36
        
26      SetCurrentUser(controller, currentUserId);
27
28      mirrorsEdgeId = GivenGame("Mirror's Edge");
29
30      gearsOfWarId = GivenGame("Gears of War");
31  }
32
33  public dynamic PreferredGame(int gameId, int userId)
34  {
35      return PreferredGames().FirstOrDefault(s => s.Id == gameId && s.Owner.Id == userId);
36  }
37
38  public dynamic FirstPreferredGame()
39  {
40      return PreferredGames().First();
41  }
42
43  public dynamic FirstRequestedGame(int gameId, int requestedById)
44  {
45      return FirstRequestedGame(s => s.Id == gameId && s.RequestedBy.Id == requestedById);
46  }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\_games_controller.cs - 88
        
78          }
79
80          public IEnumerable<dynamic> NotInterestedGames()
81          {
82              return controller.NotInterested().Data;
83          }
84
85          public bool IsWanted(int gameId, int userId)
86          {
87              if (PreferredGame(gameId, userId) == null) return true;
88
89              else return false;
90          }
91      }
92  }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\wanted_games.cs - 21
        
11  [Tag("describe_User,describe_GamesController")]
12  class wanted_games : _games_controller
13  {
14      void wanting_game()
15      {
16          it["marks the game as requested"] = () =>
17          {
18              GivenUserHasFriendWithGame(currentUserId, isFollowing: friendId, whoHasGame: mirrorsEdgeId);
19
20              IsWanted(mirrorsEdgeId, currentUserId).should_be_true();
21
22              controller.WantGame(mirrorsEdgeId, friendId);
23
24              IsWanted(mirrorsEdgeId, friendId).should_be_true();
25          };
26      }
27
28      void deleting_wanted_game()
29      {
30          before = () =>
31          {

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\giving_game.cs - 32
        
22
23  context["the requested game has been given"] = () =>
24  {
25      act = () => controller.GiveGame(gearsOfWarId, friendId);
26
27      it["the games return date is set to one month from today"] = () =>
28      {
29          ((DateTime?)FirstRequestedGame(gearsOfWarId, friendId).ReturnDate).should_be(OneMonthFromToday());
30          ((int)FirstRequestedGame(gearsOfWarId, friendId).DaysOut).should_be(0);
31          ((DateTime?)FirstWantedGame(friendId).ReturnDate).should_be(OneMonthFromToday());
32          ((int)FirstWantedGame(friendId).DaysLeft).should_be_greater_than(27);
33      };
34
35      it["the game is considered borrowed"] = () =>
36          ((int)FirstBorrowedGame(friendId).Id).should_be(gearsOfWarId);
37                
38      it["requested game cannot be given again (hypermedia link is removed)"] = () =>
39          ((bool)FirstRequestedGame(gearsOfWarId, friendId).RespondsTo("GiveGame")).should_be_false();
40
41      it["the requested game can be marked as returned by the lender"] = () =>
42          ((string)FirstRequestedGame(gearsOfWarId, friendId).GameReturned).should_be("/Games/GameReturned?gameId=" + gearsOfWarId + "&byUserId=" + friendId);

        
toc
Sample\BorrowedGames\Models\User.cs - 152
        
142  }
143
144  public void MarkGameNotInterested(dynamic gameId)
145  {
146      notInterestedGames.Insert(_.NotInterestedGames().New(new { gameId }));
147  }
148
149  public bool GameIsWanted(dynamic game)
150  {
151      return _.Wantss().Any(new { GameId = game.Id, FromUserId = game.User.Id });
152  }
153
154  public bool HasNotBeenRequested(dynamic game)
155  {
156      return !GameIsWanted(game);
157  }
158
159  public bool OwnsGame(dynamic gameId)
160  {
161      return _.Games().Any(new { Id = gameId });
162  }

        
toc
Sample\BorrowedGames\Models\User.cs - 157
        
147  }
148
149  public bool GameIsWanted(dynamic game)
150  {
151      return _.Wantss().Any(new { GameId = game.Id, FromUserId = game.User.Id });
152  }
153
154  public bool HasNotBeenRequested(dynamic game)
155  {
156      return !GameIsWanted(game);
157  }
158
159  public bool OwnsGame(dynamic gameId)
160  {
161      return _.Games().Any(new { Id = gameId });
162  }
163
164  bool DoesNotOwnGame(dynamic gameId)
165  {
166      return !OwnsGame(gameId);
167  }

        
toc
Sample\BorrowedGames\Models\User.cs - 211
        
201  {
202      return _.Friends().Games();
203  }
204
205  public IEnumerable<dynamic> PreferredGames()
206  {
207      var preferredGames =
208          GamesFriendsHave()
209              .Where(s =>
210                  DoesNotOwnGame(s.Id) &&
211                  PrefersGame(s.Id) &&
212                  SharesConsole(s.Console) &&
213                  HasNotBeenRequested(s))
214              .Select(PreferredGame)
215              .OrderByDescending(s => s.IsFavorited)
216              .ThenBy(s => s.Name)
217              .ToModels();
218
219      return preferredGames;
220  }
221

        
toc
Sample\BorrowedGames\Models\User.cs - 208
        
198  }
199
200  public IEnumerable<dynamic> GamesFriendsHave()
201  {
202      return _.Friends().Games();
203  }
204
205  public IEnumerable<dynamic> PreferredGames()
206  {
207      var preferredGames =
208          GamesFriendsHave()
209              .Where(s =>
210                  DoesNotOwnGame(s.Id) &&
211                  PrefersGame(s.Id) &&
212                  SharesConsole(s.Console) &&
213                  HasNotBeenRequested(s))
214              .Select(PreferredGame)
215              .OrderByDescending(s => s.IsFavorited)
216              .ThenBy(s => s.Name)
217              .ToModels();
218

        
toc
Sample\BorrowedGames\Controllers\GamesController.cs - 18
        
8
9  namespace BorrowedGames.Controllers
10  {
11      public class GamesController : BaseController
12      {
13          Games games = new Games();
14
15          public dynamic Preferred()
16          {
17              return Json(LinksForPreferredGames(User().PreferredGames()));
18          }
19
20          public dynamic Wanted()
21          {
22              return Json(LinksForWantedGames(User().WantedGames()));
23          }
24        
25          public dynamic Requested()
26          {   
27              return Json(LinksForRequestedGames(User().RequestedGames()));
28          }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\_games_controller.cs - 68
        
58  }
59
60  public IEnumerable<dynamic> RequestedGames()
61  {
62      return controller.Requested().Data;
63  }
64
65  public IEnumerable<dynamic> PreferredGames()
66  {
67      return controller.Preferred().Data;
68  }
69
70  public dynamic FirstWantedGame(int userId)
71  {
72      return WantedGames(userId).First();
73  }
74
75  public IEnumerable<dynamic> WantedGames(int userId)
76  {
77      return User(userId).WantedGames();
78  }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\_games_controller.cs - 36
        
26      SetCurrentUser(controller, currentUserId);
27
28      mirrorsEdgeId = GivenGame("Mirror's Edge");
29
30      gearsOfWarId = GivenGame("Gears of War");
31  }
32
33  public dynamic PreferredGame(int gameId, int userId)
34  {
35      return PreferredGames().FirstOrDefault(s => s.Id == gameId && s.Owner.Id == userId);
36  }
37
38  public dynamic FirstPreferredGame()
39  {
40      return PreferredGames().First();
41  }
42
43  public dynamic FirstRequestedGame(int gameId, int requestedById)
44  {
45      return FirstRequestedGame(s => s.Id == gameId && s.RequestedBy.Id == requestedById);
46  }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\_games_controller.cs - 88
        
78          }
79
80          public IEnumerable<dynamic> NotInterestedGames()
81          {
82              return controller.NotInterested().Data;
83          }
84
85          public bool IsWanted(int gameId, int userId)
86          {
87              if (PreferredGame(gameId, userId) == null) return true;
88
89              else return false;
90          }
91      }
92  }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\wanted_games.cs - 42
        
32          GivenUserWantsGame(currentUserId, fromUser: friendId, game: gearsOfWarId);
33
34          GivenUserWantsGame(currentUserId, fromUser: anotherFriendId, game: mirrorsEdgeId);
35
36          GivenUserWantsGame(currentUserId, fromUser: friendId, game: mirrorsEdgeId);
37      };
38
39      act = () => controller.DeleteWant(mirrorsEdgeId, friendId);
40
41      it["is no longer requested"] = () => IsWanted(mirrorsEdgeId, friendId).should_be_false();
42
43      it["other requests are unchanged"] = () =>
44      {
45          IsWanted(mirrorsEdgeId, anotherFriendId).should_be_true();
46
47          IsWanted(gearsOfWarId, friendId).should_be_true();
48      };
49  }
50
51  void retrieving_wanted_games()
52  {

        
toc
Sample\BorrowedGames\Models\User.cs - 152
        
142  }
143
144  public void MarkGameNotInterested(dynamic gameId)
145  {
146      notInterestedGames.Insert(_.NotInterestedGames().New(new { gameId }));
147  }
148
149  public bool GameIsWanted(dynamic game)
150  {
151      return _.Wantss().Any(new { GameId = game.Id, FromUserId = game.User.Id });
152  }
153
154  public bool HasNotBeenRequested(dynamic game)
155  {
156      return !GameIsWanted(game);
157  }
158
159  public bool OwnsGame(dynamic gameId)
160  {
161      return _.Games().Any(new { Id = gameId });
162  }

        
toc
Sample\BorrowedGames\Models\User.cs - 157
        
147  }
148
149  public bool GameIsWanted(dynamic game)
150  {
151      return _.Wantss().Any(new { GameId = game.Id, FromUserId = game.User.Id });
152  }
153
154  public bool HasNotBeenRequested(dynamic game)
155  {
156      return !GameIsWanted(game);
157  }
158
159  public bool OwnsGame(dynamic gameId)
160  {
161      return _.Games().Any(new { Id = gameId });
162  }
163
164  bool DoesNotOwnGame(dynamic gameId)
165  {
166      return !OwnsGame(gameId);
167  }

        
toc
Sample\BorrowedGames\Models\User.cs - 211
        
201  {
202      return _.Friends().Games();
203  }
204
205  public IEnumerable<dynamic> PreferredGames()
206  {
207      var preferredGames =
208          GamesFriendsHave()
209              .Where(s =>
210                  DoesNotOwnGame(s.Id) &&
211                  PrefersGame(s.Id) &&
212                  SharesConsole(s.Console) &&
213                  HasNotBeenRequested(s))
214              .Select(PreferredGame)
215              .OrderByDescending(s => s.IsFavorited)
216              .ThenBy(s => s.Name)
217              .ToModels();
218
219      return preferredGames;
220  }
221

        
toc
Sample\BorrowedGames\Models\User.cs - 208
        
198  }
199
200  public IEnumerable<dynamic> GamesFriendsHave()
201  {
202      return _.Friends().Games();
203  }
204
205  public IEnumerable<dynamic> PreferredGames()
206  {
207      var preferredGames =
208          GamesFriendsHave()
209              .Where(s =>
210                  DoesNotOwnGame(s.Id) &&
211                  PrefersGame(s.Id) &&
212                  SharesConsole(s.Console) &&
213                  HasNotBeenRequested(s))
214              .Select(PreferredGame)
215              .OrderByDescending(s => s.IsFavorited)
216              .ThenBy(s => s.Name)
217              .ToModels();
218

        
toc
Sample\BorrowedGames\Controllers\GamesController.cs - 18
        
8
9  namespace BorrowedGames.Controllers
10  {
11      public class GamesController : BaseController
12      {
13          Games games = new Games();
14
15          public dynamic Preferred()
16          {
17              return Json(LinksForPreferredGames(User().PreferredGames()));
18          }
19
20          public dynamic Wanted()
21          {
22              return Json(LinksForWantedGames(User().WantedGames()));
23          }
24        
25          public dynamic Requested()
26          {   
27              return Json(LinksForRequestedGames(User().RequestedGames()));
28          }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\_games_controller.cs - 68
        
58  }
59
60  public IEnumerable<dynamic> RequestedGames()
61  {
62      return controller.Requested().Data;
63  }
64
65  public IEnumerable<dynamic> PreferredGames()
66  {
67      return controller.Preferred().Data;
68  }
69
70  public dynamic FirstWantedGame(int userId)
71  {
72      return WantedGames(userId).First();
73  }
74
75  public IEnumerable<dynamic> WantedGames(int userId)
76  {
77      return User(userId).WantedGames();
78  }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\_games_controller.cs - 36
        
26      SetCurrentUser(controller, currentUserId);
27
28      mirrorsEdgeId = GivenGame("Mirror's Edge");
29
30      gearsOfWarId = GivenGame("Gears of War");
31  }
32
33  public dynamic PreferredGame(int gameId, int userId)
34  {
35      return PreferredGames().FirstOrDefault(s => s.Id == gameId && s.Owner.Id == userId);
36  }
37
38  public dynamic FirstPreferredGame()
39  {
40      return PreferredGames().First();
41  }
42
43  public dynamic FirstRequestedGame(int gameId, int requestedById)
44  {
45      return FirstRequestedGame(s => s.Id == gameId && s.RequestedBy.Id == requestedById);
46  }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\_games_controller.cs - 88
        
78          }
79
80          public IEnumerable<dynamic> NotInterestedGames()
81          {
82              return controller.NotInterested().Data;
83          }
84
85          public bool IsWanted(int gameId, int userId)
86          {
87              if (PreferredGame(gameId, userId) == null) return true;
88
89              else return false;
90          }
91      }
92  }

        
toc
Sample\BorrowedGames.Tests\Controllers\describe_GamesController\wanted_games.cs - 46
        
36          GivenUserWantsGame(currentUserId, fromUser: friendId, game: mirrorsEdgeId);
37      };
38
39      act = () => controller.DeleteWant(mirrorsEdgeId, friendId);
40
41      it["is no longer requested"] = () => IsWanted(mirrorsEdgeId, friendId).should_be_false();
42
43      it["other requests are unchanged"] = () =>
44      {
45          IsWanted(mirrorsEdgeId, anotherFriendId).should_be_true();
46
47          IsWanted(gearsOfWarId, friendId).should_be_true();
48      };
49  }
50
51  void retrieving_wanted_games()
52  {
53      before = () => GivenUserWantsGame(currentUserId, fromUser: friendId, game: mirrorsEdgeId);
54
55      it["lists requested games"] = () =>
56          WantedGames().should_contain(s => s.Name == "Mirror's Edge");

        

Use a spacebar or arrow keys to navigate