public List<Trip> GetTripsByUser(User.User user)
 {
     List<Trip> tripList = new List<Trip>();
     User.User loggedUser = UserSession.GetInstance().GetLoggedUser();
     bool isFriend = false;
     if (loggedUser != null)
     {
         foreach(User.User friend in user.GetFriends())
         {
             if (friend.Equals(loggedUser))
             {
                 isFriend = true;
                 break;
             }
         }
         if (isFriend)
         {
             tripList = TripDAO.FindTripsByUser(user);
         }
         return tripList;
     }
     else
     {
         throw new UserNotLoggedInException();
     }
 }
        public List<Trip> GetTripsByUser(User.User user)
        {
            var userSearchResult = sessionService.GetLoggedUser();
            if (userSearchResult.HasNotUser()) throw new UserNotLoggedInException();

            return user.IsFriendOf(userSearchResult.User()) ?
                tripRepository.FindTripsByUser(user) : new List<Trip>();
        }
Beispiel #3
0
 public List<Trip.Trip> GetFriendsTrips(User user, ITripDao tripDao)
 {
     var tripList = new List<Trip.Trip>();
     if (IsFriendOf(user))
     {
         tripList = tripDao.FindTripsByUser(this);
     }
     return tripList;
 }
Beispiel #4
0
 private List<Trip> FindtripsByFriendsOf(User.User user, User.User loggedUser)
 {
     foreach(User.User friend in user.GetFriends())
     {
         if (friend.Equals(loggedUser))
         {
             return tripDao.FindTripsByUser(user);
         }
     }
     return NoTrips ();
 }
        public List<Trip> GetTripsByUser(User.User user)
        {
            var loggedUser = _userSession.GetLoggedUser();

            if (loggedUser == null)
                throw new UserNotLoggedInException();

            if (!user.IsFriendsWith(loggedUser))
                return new List<Trip>();

            return _userTripFinder.FindTripsByUser(user);
        }
        public List<Trip> GetTripsByUser(User.User user)
        {
            User.User loggedUser = _userSessionWrapper.GetLoggedInUser();

            if (loggedUser == null)
                throw new UserNotLoggedInException();

            if (user.IsFriendWith(loggedUser))
                return _tripDaoWrapper.FindTripsByUser(user);

            return new List<Trip>();
        }
        public void ShouldReturnTripsByLoggedUser()
        {
            var friend = new User ();
            var trip = new Trip ();
            userSession.Setup (x => x.GetLoggedUser()).Returns(friend);
            var user = new Mock<User>();
            user.Setup (x => x.GetFriends()).Returns (new List<User> {friend, friend});
            tripDao.Setup (x => x.FindTripsByUser (It.IsAny<User> ())).Returns (new List<Trip> { trip });

            var tripsOfFiends = tripService.GetTripsByUser (user.Object);

            Assert.AreEqual(1, tripsOfFiends.Count);
        }
 public User GetLoggedUser(User user)
 {
     throw new DependendClassCallDuringUnitTestException(
         "UserSession.GetLoggedUser() should not be called in an unit test");
 }
Beispiel #9
0
 public bool IsFriendsWith(User loggedUser)
 {
     return _friends.Any(friend => friend == loggedUser);
 }
Beispiel #10
0
 public void AddFriend(User user)
 {
     _friends.Add(user);
 }
Beispiel #11
0
 public bool IsFriendWith(User user)
 {
     return friends.Contains(user);
 }
Beispiel #12
0
 public List<Trip> GetTripsByUser(User.User user)
 {
     var loggedUser = GetLoggedUser();
     return FindtripsByFriendsOf (user, loggedUser);
 }
 public MockUserSession(User.User loggedUser)
 {
     _loggedUser = loggedUser;
 }
 public List<Trip> FindTripsByUser(User.User user)
 {
     return TripDAO.FindTripsByUser(user);
 }
Beispiel #15
0
 public bool IsFriendOf(User loggedUser)
 {
     return Enumerable.Contains(GetFriends(), loggedUser);
 }
Beispiel #16
0
 public bool IsUserLoggedIn(User user)
 {
     throw new DependendClassCallDuringUnitTestException(
         "UserSession.IsUserLoggedIn() should not be called in an unit test");
 }
 public bool IsUserLoggedIn(User.User user)
 {
     throw new System.NotImplementedException();
 }
 //protected override List<Trip.Trip> GetTripListByUser(User.User user)
 //{
 //    return _tripList;
 //}
 internal void SetLoggerUser(User.User user)
 {
     _loggerUser = user;
 }