示例#1
0
        public List <Wallet> GetWalletsByUser(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException();
            }

            List <Wallet> walletList = new List <Wallet>();
            User          loggedUser = _ILoggedUser.GetUser();
            bool          isFriend   = false;

            if (loggedUser != null)
            {
                foreach (User friend in user.Friends)
                {
                    if (friend.Equals(loggedUser))
                    {
                        isFriend = true;
                        break;
                    }
                }

                if (isFriend)
                {
                    walletList = _IWalletDAO.FindWalletsByUser(user);
                }

                return(walletList);
            }
            else
            {
                throw new UserNotLoggedInException();
            }
        }
示例#2
0
        public void TestSuccess()
        {
            User loggedUser = new User();
            User friend     = new User();

            friend.AddFriend(loggedUser);

            List <Wallet> wallets = new List <Wallet>();

            wallets.Add(new Wallet());
            wallets.Add(new Wallet());
            wallets.Add(new Wallet());

            IWalletDAO walletDao = Substitute.For <IWalletDAO>();

            walletDao.FindWalletsByUser(friend).Returns(wallets);

            IUserSession userSession = Substitute.For <IUserSession>();

            userSession.GetLoggedUser().Returns(loggedUser);

            WalletService service = new WalletService(userSession, walletDao);
            List <Wallet> result  = service.GetWalletsByUser(friend);

            Assert.IsNotNull(result);
            Assert.AreEqual(wallets.Count, result.Count);
        }
示例#3
0
        public List <Wallet> GetWalletsByUser(User user)
        {
            User loggedUser = RequireLoggedUser();

            if (!user.IsFriendOf(loggedUser))
            {
                return(new List <Wallet>());
            }

            return(walletDao.FindWalletsByUser(user));
        }
        public List <Wallet> GetWalletsByUser(User user)
        {
            User loggedUser = userSession.GetLoggedUser();

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

            List <Wallet> walletList = new List <Wallet>();

            if (user.IsFriendOf(loggedUser))
            {
                walletList = walletDAO.FindWalletsByUser(user);
            }
            return(walletList);
        }
示例#5
0
        public List <Wallet> GetWalletsByUser(User user)
        {
            List <Wallet> walletList = new List <Wallet>();
            User          loggedUser = _userSession.GetLoggedUser();

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

            if (user.GetFriends().Contains(loggedUser))
            {
                walletList = _walletDAO.FindWalletsByUser(user);
            }

            return(walletList);
        }
示例#6
0
        public List <Wallet> GetWalletsByUser(User user)
        {
            User loggedUser = _userSession.GetLoggedUser();

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

            User friend = user.GetFriends().FirstOrDefault(p => p.Equals(loggedUser));

            if (friend != null)
            {
                return(_walletDao.FindWalletsByUser(user));
            }

            return(new List <Wallet>());
        }
示例#7
0
        public List <Wallet> GetWalletsFromFriend(User user)
        {
            List <Wallet> walletList = new List <Wallet>();
            User          loggedUser = userSession.GetLoggedUser();

            if (loggedUser != null && user != null)
            {
                if (loggedUser.HasFriend(user))
                {
                    walletList = walletDao.FindWalletsByUser(user);
                }

                return(walletList);
            }
            else
            {
                throw new UserNotLoggedInException();
            }
        }
示例#8
0
        /// <summary>
        /// Returns wallets belonging to the given user.
        /// </summary>
        /// <param name="user">The user from which we want the wallets.</param>
        /// <returns>A list of wallets belonging to the given user, or an empty list if given user and current user are not friends.</returns>
        /// <exception cref="ArgumentNullException">User parameter is null.</exception>
        /// <exception cref="UserNotLoggedInException">User calling this method is not logged in.</exception>
        public List <Wallet> GetWalletsByUser(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var loggedUser = _userSession.GetLoggedUser();

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

            if (!user.Friends.Contains(loggedUser))
            {
                return(new List <Wallet>());
            }

            return(_walletDao.FindWalletsByUser(user));
        }
        public List <IWallet> GetWalletsByUser(IUser user)
        {
            var  walletList = new List <IWallet>();
            var  loggedUser = _userSession.GetLoggedUser();
            bool isFriend   = false;

            if (loggedUser != null)
            {
                isFriend = user.GetFriends().Any(u => u.Equals(loggedUser));

                if (isFriend)
                {
                    walletList = _walletDAO.FindWalletsByUser(user);
                }

                return(walletList);
            }
            else
            {
                throw new UserNotLoggedInException();
            }
        }