Exemplo n.º 1
0
        public void CreateOjRankTest()
        {
            HdojRank target = new HdojRank(); // TODO: 初始化为适当的值
            string web = @"<tr><td>2</td><td><img width='42px' height='27px' src='/images/country/1.gif'/></td><td><a href='userstatus.php?user=lmm333'>c-lou</a></td><td><a href='mailto:[email protected]'>[email protected]</a></td><td>njust</td><td>71</td><td>5128</td></tr>"; // TODO: 初始化为适当的值
            OjRankEntity expected = new OjRankEntity()
            {
                Ac = 71,
                //Submit = 711,
                UserName = "******",
                NickName = "c-lou",
                School = "njust",
                Email = "*****@*****.**",
                No = 2
            }; // TODO: 初始化为适当的值
            OjRankEntity actual;
            actual = target.CreateOjRank(web);

            Assert.AreEqual(expected.Ac, actual.Ac);
            Assert.AreEqual(expected.Email, actual.Email);
            Assert.AreEqual(expected.NickName, actual.NickName);
            Assert.AreEqual(expected.No, actual.No);
            Assert.AreEqual(expected.School, actual.School);
            Assert.AreEqual(expected.Submit, actual.Submit);
            Assert.AreEqual(expected.UserName, actual.UserName);
            //Assert.AreEqual(loumingming, actual);
            //Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemplo n.º 2
0
 private static void AssertOjRankEntity(OjRankEntity actual, OjRankEntity expected)
 {
     Assert.AreEqual(expected.Ac, actual.Ac);
     Assert.AreEqual(expected.Email, actual.Email);
     Assert.AreEqual(expected.NickName, actual.NickName);
     Assert.AreEqual(expected.No, actual.No);
     Assert.AreEqual(expected.School, actual.School);
     Assert.AreEqual(expected.Submit, actual.Submit);
     Assert.AreEqual(expected.UserName, actual.UserName);
 }
Exemplo n.º 3
0
        public void GetUserStatusTest()
        {
            PojRank target = new PojRank(); // TODO: 初始化为适当的值
            string user_id = "ltj_njust"; // TODO: 初始化为适当的值
            OjRankEntity actual;
            actual = target.GetUserStatus(user_id);

            OjRankEntity expected = new OjRankEntity()// TODO: 初始化为适当的值
            {
                Ac = 347,
                Submit = 711,
                UserName = "******",
                NickName = "messiah",
                School = "njust",
                Email = "*****@*****.**",
                No = 1199
            };

            AssertOjRankEntity(actual, expected);
        }
Exemplo n.º 4
0
        public void GetRankListTest1()
        {
            HdojRank target = new HdojRank(); // TODO: 初始化为适当的值
            string web = target.GetSearchResult("lmm333"); // TODO: 初始化为适当的值
            Assert.IsNotNull(web);

            OjRankEntity lmm333 = new OjRankEntity()
            {
                Ac = 71,
                Submit = 0,
                UserName = "******",
                NickName = "c-lou",
                School = "njust",
                Email = "*****@*****.**",
                No = 5242
            }; // TODO: 初始化为适当的值

            List<OjRankEntity> actual;
            actual = target.GetRankList(web);

            Assert.IsTrue(actual.Count == 1);
            AssertOjRankEntity(actual[0], lmm333);
        }
Exemplo n.º 5
0
        public void GetUserStatusTest()
        {
            HdojRank target = new HdojRank(); // TODO: 初始化为适当的值
            string user_id = "lmm333"; // TODO: 初始化为适当的值

            OjRankEntity actual;
            actual = target.GetUserStatus(user_id);

            OjRankEntity lmm333 = new OjRankEntity()
            {
                Ac = 71,
                Submit = 178,
                UserName = "******",
                NickName = "c-lou",
                School = "njust",
                Email = "*****@*****.**",
                No = 5242
            }; // TODO: 初始化为适当的值

            AssertOjRankEntity(actual, lmm333);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 根据用户名查询用户信息
        /// </summary>
        /// <param name="user_id">用户名</param>
        /// <returns>用户信息</returns>
        public OjRankEntity GetUserStatus(string user_id)
        {
            OjRankEntity ojRankEntity = new OjRankEntity();
            ojRankEntity.UserName=user_id.Trim().ToLower();

            string url = string.Format("http://acm.hdu.edu.cn/userstatus.php?user={0}", user_id);
            string web = Http.Get(url, null);

            string regex = "<h1 style=\"color:#1A5CC8\" align=center><a href='mailto:(.*?)'>(.*?)</a></h1>";
            Regex reg = new Regex(regex, RegexOptions.Compiled);
            var match = reg.Match(web);
            if (!match.Success)
                return null;
            ojRankEntity.Email = match.Result("$1").Trim();
            ojRankEntity.NickName = match.Result("$2").Trim();

            regex = @"<tr><td>Rank</td><td align=center>(\d*?)</td></tr>";
            reg = new Regex(regex, RegexOptions.Compiled);
            match = reg.Match(web);
            if (!match.Success)
                return null;
            ojRankEntity.No = Convert.ToInt32(match.Result("$1"));

            regex = @"<tr><td>Problems Solved</td><td align=center>(\d*?)</td></tr>";
            reg = new Regex(regex, RegexOptions.Compiled);
            match = reg.Match(web);
            if (!match.Success)
                return null;
            ojRankEntity.Ac = Convert.ToInt32(match.Result("$1"));

            regex = @"<tr><td>Submissions</td><td align=center>(\d*?)</td></tr>";
            reg = new Regex(regex, RegexOptions.Compiled);
            match = reg.Match(web);
            if (!match.Success)
                return null;
            ojRankEntity.Submit = Convert.ToInt32(match.Result("$1"));

            regex = "<i style=\"color:blue\">from: (.*?)&nbsp;";
            reg = new Regex(regex, RegexOptions.Compiled);
            match = reg.Match(web);
            if (!match.Success)
                return null;
            ojRankEntity.School = match.Result("$1").Trim().ToLower();
            if(ojRankEntity.School=="unknown")
                ojRankEntity.School="";//没有学校的特殊情况

            return ojRankEntity;
        }
Exemplo n.º 7
0
        public void GetRankListTest2()
        {
            HdojRank target = new HdojRank(); // TODO: 初始化为适当的值
            string web = target.GetSearchResult("njust"); // TODO: 初始化为适当的值
            Assert.IsNotNull(web);

            OjRankEntity lmm333 = new OjRankEntity()
            {
                Ac = 71,
                Submit = 0,
                UserName = "******",
                NickName = "c-lou",
                School = "njust",
                Email = "*****@*****.**",
                No = 5242
            }; // TODO: 初始化为适当的值

            OjRankEntity stsky = new OjRankEntity()
            {
                Ac = 49,
                Submit = 0,
                UserName = "******",
                NickName = "*[njust]STsky",
                School = "",
                Email = "*****@*****.**",
                No = 7879
            };

            List<OjRankEntity> actual;
            actual = target.GetRankList(web);

            Assert.IsTrue(actual.Count == 62);
            AssertOjRankEntity(actual[1], lmm333);
            AssertOjRankEntity(actual[3], stsky);

            //Assert.AreEqual(loumingming, actual);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 根据oj用户名查询用户信息
        /// </summary>
        /// <param name="user_id">oj用户名</param>
        /// <returns>用户信息</returns>
        public OjRankEntity GetUserStatus(string user_id)
        {
            OjRankEntity ojRankEntity = new OjRankEntity();

            string url = string.Format("http://poj.org/userstatus?user_id={0}", user_id);
            string web = Http.Get(url, null);

            string regex = @"<font size=5 color=blue><a href=send\?to=(.*?)>(.*?)--(.*?)</a></font>";
            Regex reg = new Regex(regex, RegexOptions.Compiled);
            var match = reg.Match(web);
            if (!match.Success)
                return null;
            ojRankEntity.UserName = match.Result("$1").Trim();
            ojRankEntity.NickName = match.Result("$3").Trim();

            //<td align=center width=25%>(.*?)</td>
            string regexString = @"<td align=center width=25%>(.*?)</td>";
            Regex regex2 = new Regex(regexString, RegexOptions.Compiled);
            var matches = regex2.Matches(web);

            regex = @"<font color=red>(\d*?)</font>";
            reg = new Regex(regex, RegexOptions.Compiled);
            match = reg.Match(matches[0].Result("$0"));
            if (!match.Success)
                return null;
            ojRankEntity.No = Convert.ToInt32(match.Result("$1"));

            regex = string.Format(@"<a href=status\?result=0&user_id={0}>(\d*?)</a></td>", ojRankEntity.UserName);
            reg = new Regex(regex, RegexOptions.Compiled);
            match = reg.Match(matches[1].Result("$0"));
            if (!match.Success)
                return null;
            ojRankEntity.Ac = Convert.ToInt32(match.Result("$1"));

            regex = string.Format(@"<a href=status\?user_id={0}>(\d*?)</a></td>", ojRankEntity.UserName);
            reg = new Regex(regex, RegexOptions.Compiled);
            match = reg.Match(matches[2].Result("$0"));
            if (!match.Success)
                return null;
            ojRankEntity.Submit = Convert.ToInt32(match.Result("$1"));

            regex = @"<td align=center width=25%>(.*?)</td>";
            reg = new Regex(regex, RegexOptions.Compiled);
            match = reg.Match(matches[3].Result("$0"));
            if (!match.Success)
                return null;
            ojRankEntity.School = match.Result("$1").Trim().ToLower();

            regex = @"<td align=center width=25%>(.*?)</td>";
            reg = new Regex(regex, RegexOptions.Compiled);
            match = reg.Match(matches[4].Result("$0"));
            if (!match.Success)
                return null;
            ojRankEntity.Email = match.Result("$1").Trim();

            return ojRankEntity;
        }
Exemplo n.º 9
0
 /// <summary>
 /// 更新一条ojrank
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="OJTableName"></param>
 /// <returns></returns>
 public static string UpdateOJRank(OjRankEntity entity, string OJTableName)
 {
     string sql = string.Format("REPLACE INTO `{0}` VALUES (NULL, '{1}', '{2}', '{3}', '{4}', '{5}')",
         OJTableName, entity.UserName, entity.Ac, entity.Submit, DateTime.Today, DateTime.Today);
     return sql;
 }
Exemplo n.º 10
0
 public void UpdateOJRankTest()
 {
     Storage target = new Storage(); // TODO: 初始化为适当的值
     OjRankEntity entity = new OjRankEntity()
     {
         UserName="******",
         Ac=123,
     }; // TODO: 初始化为适当的值
     string OJTableName = "hdoj"; // TODO: 初始化为适当的值
     target.UpdateOJRank(entity, OJTableName);
     Assert.Inconclusive("无法验证不返回值的方法。");
 }
Exemplo n.º 11
0
 public void UpdateUser(OjRankEntity user)
 {
     //UpdateOJRank
     Storage storage = new Storage();
     storage.UpdateOJRank(user, "hdoj");
 }
Exemplo n.º 12
0
 private void UpdateUser(OjRankEntity user)
 {
     //UpdateOJRank
     storage.UpdateOJRank(user, "poj");
 }