示例#1
0
 private void AssertUser(User a, User b)
 {
     Assert.IsTrue(a.Volatility==b.Volatility);
     Assert.IsTrue(a.MostRecentEvent==b.MostRecentEvent);
     Assert.IsTrue(a.Color==b.Color);
     Assert.IsTrue(a.Rating == b.Rating);
     Assert.IsTrue(a.Timesplayed == b.Timesplayed);
     Assert.IsTrue(a.UserName == b.UserName);
 }
示例#2
0
 public void GetProfileTest()
 {
     TopcoderProvider target = new TopcoderProvider(); // TODO: 初始化为适当的值
     string user_id = "lmm333"; // TODO: 初始化为适当的值
     User expected = new User()
     {
         Color = "coderTextGray",
         MostRecentEvent = "SRM 532-02.09.12",
         Rating = 864,
         Timesplayed = 14,
         UserName = "******",
         Volatility = 180
     };
     User actual;
     actual = target.GetProfile(user_id);
     //Assert.AreEqual(expected, actual);
     AssertUser(expected, actual);
 }
示例#3
0
        /// <summary>
        /// 获得tc用户信息
        /// </summary>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public User GetProfile(string user_id)
        {
            if (user_id == null)
                return null;
            User user = new User();
            user.UserName = user_id.Trim();

            string web = GetProfilePage(user_id.Trim());

            string regexPattern = "<span class=\"(.*)\">(.*)</span>\\s";
            Regex reg = new Regex(regexPattern, RegexOptions.Compiled);
            var match = reg.Match(web);
            if (!match.Success)
                return null;
            user.Color = match.Result("$1").Trim();
            user.Rating = Convert.ToInt32(match.Result("$2").Trim());

            regexPattern = "<td class=\"valueR\">(\\d*?)</td>";
            reg = new Regex(regexPattern, RegexOptions.Compiled);

            var matches = reg.Matches(web);
            if (matches.Count<3)
                return null;
            user.Volatility = Convert.ToInt32(matches[0].Result("$1").Trim());
            //user.max_rating = Convert.ToInt32(matches[1].Result("$1").Trim());
            //user.min_raing = Convert.ToInt32(matches[2].Result("$1").Trim());

            regexPattern = ">(\\d+?)</a></td></tr>";
            reg = new Regex(regexPattern, RegexOptions.Compiled);
            match = reg.Match(web);
            if (!match.Success)
                return null;
            user.Timesplayed = Convert.ToInt32(match.Result("$1").Trim());

            regexPattern = "<td class=\"valueR\">(.+?)<br />(.+?)</td></tr>";
            reg = new Regex(regexPattern, RegexOptions.Compiled);
            match = reg.Match(web);
            if (!match.Success)
                return null;
            user.MostRecentEvent = match.Result("$1").Trim() +"-"+ match.Result("$2").Trim();
            return user;
        }