Exemplo n.º 1
0
        public QAServiceTests()
        {
            // Definindo quais serão as classes mockadas
            questionRepositoryMock = new Mock <IQuestionRepository>();
            answerRepositoryMock   = new Mock <IAnswerRepository>();
            likeRepositoryMock     = new Mock <ILikeRepository>();
            unitOfWorkMock         = new Mock <IUnitOfWork>();



            service = new QAService(questionRepositoryMock.Object, unitOfWorkMock.Object, new QuestionValidator(), answerRepositoryMock.Object, likeRepositoryMock.Object);

            questionRepositoryMock.Setup(repo => repo.Find(questionId1)).Returns(() =>
            {
                return(new Question()
                {
                    Id = questionId1
                });
            });

            answerRepositoryMock.Setup(repo => repo.Find(answerId1)).Returns(() =>
            {
                return(new Answer()
                {
                    Id = answerId1
                });
            });
        }
Exemplo n.º 2
0
        public ActionResult Ask(string page, string kw, string aid)
        {
            User user = UserUtil.getCurUser();
            int  tid  = 0;

            int.TryParse(aid, out tid);
            QA qa = QAService.GetInstance().Get(tid);

            if (qa != null && user != null && qa.username.Equals(user.username) && qa.status != QA.VALIDATE)
            {
                ViewData["qa"] = qa;
            }
            string username = user == null ? string.Empty : user.username;
            int    ipage    = 0;

            int.TryParse(page, out ipage);
            ipage = ipage < 1 ? 1 : ipage;
            IList <QA> qalist = QAService.GetInstance().Search(kw, QA.VALIDATE, string.IsNullOrEmpty(kw) ? username : string.Empty);

            if (string.IsNullOrEmpty(username))
            {
                qalist = qalist.Where(m => m.isRecommend).ToList <QA>();
            }
            Pager pager = new Pager();

            ViewData["page"]  = pager;
            pager.PageSize    = 10;
            pager.PageIndex   = ipage;
            pager.RecordCount = qalist.Count;
            qalist            = qalist.Skip((ipage - 1) * pager.PageSize).Take(pager.PageSize).ToList <QA>();
            return(View(qalist));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 如果当前用户的提问未审核可以重新编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult ShowAsk(string id)
        {
            User user = UserUtil.getCurUser();
            int  iid  = 0;

            int.TryParse(id, out iid);
            QA qa = QAService.GetInstance().Get(iid);

            if (qa != null && user != null && qa.username.Equals(user.username) && qa.status != QA.VALIDATE)
            {
                return(Redirect("/qa/ask/?aid=" + qa.id));
            }
            return(View(qa));
        }
Exemplo n.º 4
0
        public void GetQuestionListForBaZiTest()
        {
            QAService target    = new QAService();                                    // TODO: 初始化为适当的值
            int       pagesize  = 1;                                                  // TODO: 初始化为适当的值
            int       pageindex = 15;                                                 // TODO: 初始化为适当的值
            string    key       = string.Empty;                                       // TODO: 初始化为适当的值
            int       cate      = 0;                                                  // TODO: 初始化为适当的值
            string    orderby   = string.Empty;                                       // TODO: 初始化为适当的值
            ReturnValue <PageInfo <QA_QuestionShowMini <BaZiMod> > > expected = null; // TODO: 初始化为适当的值
            ReturnValue <PageInfo <QA_QuestionShowMini <BaZiMod> > > actual;

            actual = target.GetQuestionListForBaZi(pagesize, pageindex, key, cate, orderby);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemplo n.º 5
0
        public void AddQuestionWithChartTest()
        {
            QAService target = new QAService(); // TODO: 初始化为适当的值

            using (StreamReader sr = new StreamReader(@"D:\json.txt", System.Text.Encoding.UTF8))
            {
                string str          = sr.ReadToEnd();
                Stream openPageData = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(str));
                ReturnValue <USR_CustomerShow> expected = null; // TODO: 初始化为适当的值
                ReturnValue <USR_CustomerShow> actual   = ReturnValue <USR_CustomerShow> .Get404Error(str);

                actual = target.AddQuestionWithChart(openPageData);
                Assert.AreEqual(expected, actual);
                Assert.Inconclusive("验证此测试方法的正确性。");
            }
        }
Exemplo n.º 6
0
        public ActionResult PostAsk(QA qa)
        {
            string validatecode = Request["validatecode"];

            if (ValidateCodeUtil.Validated(validatecode))
            {
                User   user     = UserUtil.getCurUser();
                string username = user == null ? string.Empty : user.username;
                qa.createip = Request.UserHostAddress;
                qa.status   = QA.NORMAL;
                qa.username = user == null ? "匿名" : user.username;
                qa.qid      = 0;
                qa.pubdate  = DateTime.Now;
                QAService.GetInstance().Save(qa);
                TempData["message"] = "提问成功,请耐心等待管理员的解答!";
            }
            else
            {
                TempData["message"] = "验证码输入错误!";
            }
            return(Redirect("/qa/ask#ask"));
        }
Exemplo n.º 7
0
 public static int GetNumberOfAnswers(this Question question)
 {
     var questionsHelper = new QAService(new EntityQARepository(new YoyyinEntities1()));
     return questionsHelper.GetNumberOfAnswersByQuestion(question.QuestionID);
 }
Exemplo n.º 8
0
 public static bool DeleteAllowed(this Question question, Guid userId)
 {
     var questionsHelper = new QAService(new EntityQARepository(new YoyyinEntities1()))
     return questionsHelper.DeleteAllowed(question, userId);
 }
Exemplo n.º 9
0
            public override bool ShouldOverrideUrlLoading(WebView webView, string url)
            {
                var scheme = "hybrid:";
                // This handler will treat everything between the protocol and "?"
                // as the method name.  The querystring has all of the parameters.
                var resources = url.Substring(scheme.Length).Split('?');
                var method    = resources[0];
                var name      = resources[1].Split('&')[0];

                resources = resources[1].Split('&');

                Dictionary <string, string> qansList = new Dictionary <string, string>();

                foreach (string res in resources)
                {
                    var key   = res.Split('=')[0];
                    var value = res.Split('=')[1];
                    qansList.Add(key, value);
                }
                //var parameters = System.Web.HttpUtility.ParseQueryString(resources[1]);

                if (method == "Save")
                {
                    //var textbox = parameters["textbox"];

                    //// Add some text to our string here so that we know something
                    //// happened on the native part of the round trip.
                    //var prepended = string.Format("C# says \"{0}\"", textbox);

                    //// Build some javascript using the C#-modified result
                    //var js = string.Format("SetLabelText('{0}');", prepended);

                    //webView.L int i = 1;
                    List <QA> qalist = new List <QA>();

                    var username = qansList["fname"];
                    for (var i = 1; i < 5; i++)
                    {
                        string q1       = "q" + i + "h";
                        string q1a      = "q" + i;
                        var    question = qansList[q1];
                        var    ans      = qansList[q1a];
                        qalist.Add(new QA()
                        {
                            Question = question, Answer = ans, UserName = username
                        });
                    }



                    QAService serv = new QAService();
                    serv.SaveForm(qalist);

                    var prepended = "Saved Successfully";

                    var js = string.Format("SetLabelText('{0}');", prepended);

                    webView.LoadUrl("javascript:" + js);
                }

                return(true);
            }