internal static UserTweetsDTO MapToUserTweets(User user, List<Tweet> tweets)
        {
            var allUserTweets = tweets.Select(x => new UserTweetDTO(x.Name, x.Message))
                                          .Where(x => user.Followees.Contains(x.Name) ||
                                                      user.Name == x.Name);

            var userTweets = new UserTweetsDTO();
            userTweets.Name = user.Name;
            userTweets.Tweets.AddRange(allUserTweets);
            return userTweets;
        }
        public void MapToUserTweets_WhereParamteersAreValid_ReturnsUserTweetsList()
        {
            var user = new User();
            user.Name = "Tom";
            user.Followees = new List<string>() {"Mary", "Tom", "Sue" };
            var tweets = new List<Tweet>();
            tweets.Add(new Tweet() { Name = "Sue", Message = "I love programming." });
            tweets.Add(new Tweet() { Name = "Tom", Message = "Great weather outside!" });
            tweets.Add(new Tweet() { Name = "Jane", Message = "I love my red socks." });
            tweets.Add(new Tweet() { Name = "Tom", Message = "Nothing travels faster than speed of light" });
            tweets.Add(new Tweet() { Name = "Mary", Message = "Mary has a little lamb" });

            var results = UserTweetMapper.MapToUserTweets(user, tweets);

            Assert.AreEqual(4, results.Tweets.Count);
            Assert.AreEqual("Tom", results.Name);
            Assert.AreEqual("Great weather outside!", results.Tweets[1].Message);
            Assert.AreEqual("Mary has a little lamb", results.Tweets[3].Message);
        }
示例#3
0
        public User Create(string lineFeed)
        {
            try
            {
                var user = new User();

                var userFields = lineFeed.Split(new string[]{"follows"}, StringSplitOptions.RemoveEmptyEntries);
                user.Name = userFields[0].Trim();

                var followers = userFields[1].Split(',');
                foreach(var follow in followers)
                    user.Followees.Add(follow.Trim());

                return user;
            }
            catch(IndexOutOfRangeException ex)
            {
                Error.Log(Constants.InvalidUserRecord, ex);
                throw new DomainException(Constants.InvalidUserRecord, ex);
            }
        }