Esempio n. 1
0
 public PostCommand(User user, ITweetsRepository tweetsRepository, ParsedInput parsedInput, TextWriter textWriter)
 {
     _user = user;
     _tweetsRepository = tweetsRepository;
     _parsedInput = parsedInput;
     _textWriter = textWriter;
 }
Esempio n. 2
0
 public WallCommand(User user, ITweetsRepository tweetsRepository, TextWriter textWriter, ParsedInput parsedInput)
 {
     _user = user;
     _tweetsRepository = tweetsRepository;
     _textWriter = textWriter;
     _parsedInput = parsedInput;
 }
Esempio n. 3
0
        public ICommand Create(User user,
            ParsedInput parsedInput,
            ITweetsRepository tweetsRepository,
            TextWriter textWriter)
        {
            switch (parsedInput.CommandType)
            {
                case CommandType.Read:
                {
                    return new ReadCommand(user, tweetsRepository, textWriter, parsedInput);
                }
                case CommandType.Follow:
                {
                    return new FollowCommand(user, new User(parsedInput.RequiredAction), textWriter);
                }
                case CommandType.Wall:

                {
                    return new WallCommand(user, tweetsRepository, textWriter, parsedInput);
                }
                case CommandType.Post:
                default:
                {
                    return new PostCommand(user, tweetsRepository, parsedInput, textWriter);
                }
            }
        }
Esempio n. 4
0
        public string FormatTweets(User user, bool isWall)
        {
            var formattedOutput = new StringBuilder();
            var aggregatedList = _tweetsRepository.GetTweets(user).ToList();

            if (isWall)
            {
                foreach (var followedUser in user.Following)
                {
                    formattedOutput.AppendLine($"{user.Name} follows {followedUser.Name}");
                    aggregatedList.AddRange(_tweetsRepository.GetTweets(followedUser));
                }
            }

            aggregatedList = aggregatedList.OrderByDescending(tweet => tweet.DatePublished).ToList();
            foreach (var tweet in aggregatedList)
            {
                var dateDiff = (_currentTime - tweet.DatePublished);
                formattedOutput.AppendLine(
                    $"{tweet.User.Name} - {tweet.Message} ({DateTimeHelper.GetFriendlyRelativeTime(dateDiff)})");
            }

            return formattedOutput.ToString();
        }
Esempio n. 5
0
 public FollowCommand(User user, User userToFollow, TextWriter textWriter)
 {
     _user = user;
     _userToFollow = userToFollow;
     _textWriter = textWriter;
 }
 public IEnumerable<Tweet> GetTweets(User user)
 {
     return Tweets.Where(tweet => tweet.User.Name.Equals(user.Name, StringComparison.CurrentCultureIgnoreCase));
 }
 public void WhenTheyFollowUser(string userToFollow)
 {
     famousUser = new User(userToFollow);
     _user.Follow(famousUser);
 }
 public void GivenAUserHasAnAccount(string username)
 {
     _user = new User(username);
     _timeline = new Timeline(_tweetsRepository, _today);
 }
 public void GivenTheUserHasFollowed(string username, string userToFollow)
 {
     User user = _usersRepository.GetUser(username);
     User famousUser = new User(userToFollow);
     user.Following.Add(famousUser);
 }
Esempio n. 10
0
 IEnumerable<Tweet> GetTweets(User user)
 {
     return _tweetsRepository.GetTweets(user);
 }
Esempio n. 11
0
 public void Follow(User follower)
 {
     Following.Add(follower);
 }
Esempio n. 12
0
 public Tweet(User user, string message, DateTime datePublished)
 {
     User = user;
     Message = message;
     DatePublished = datePublished;
 }