Example #1
0
        public async Task MessageBoardService_SendAsync_Throws_Exception_When_SendMessageRequest_Is_Null()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <MessageBoardDbContext>()
                          .UseInMemoryDatabase("MessageBoardDB")
                          .Options;

            using (var dbContext = new MessageBoardDbContext(options))
            {
                // Clear existing messages
                dbContext.Messages.RemoveRange(dbContext.Messages);
                await dbContext.SaveChangesAsync();

                // Initialize new messages
                dbContext.Messages.Add(new MessageDb {
                    User = "******", Content = "Hello Tom.", Created = DateTime.Now.AddMinutes(5)
                });
                dbContext.Messages.Add(new MessageDb {
                    User = "******", Content = "Hi, Rick.", Created = DateTime.Now.AddMinutes(5)
                });
                await dbContext.SaveChangesAsync();
            };

            SendMessageRequest request = null;
            var mapper = new MessageMapper();

            using (var dbContext = new MessageBoardDbContext(options))
            {
                var service = new MessageBoardService(mapper, dbContext);

                // Act and Assert
                await Assert.ThrowsAsync <ArgumentNullException>(() => service.SendAsync(request));
            };
        }
Example #2
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (txtUName.Text.Trim() == "")
        {
            return;
        }
        if (txtContent.Text.Trim() == "")
        {
            return;
        }
        MessageBoard mess = new MessageBoard();

        mess.M_UName   = txtUName.Text.Trim();
        mess.M_Content = txtContent.Text.Trim();
        mess.M_SID     = ((ServiceInfo)Session["serviceinfo"]).S_ID;
        mess.M_Emotion = "";
        int result = MessageBoardService.Insert_MessageBoard(mess);

        if (result > 0)
        {
            txtUName.Text   = "";
            txtContent.Text = "";
            CommonFunction.Alert(Literal1, "提交成功,谢谢您的参与!");
        }
    }
Example #3
0
        public void GetMessages_InsertVoid_ReturnMessageList()
        {
            //Arrange
            var service = new MessageBoardService(UserRepository, MessageRepository);

            //Act
            var actual = service.GetMessages();

            //Assert
            var expect = 1;

            Assert.AreEqual(expect, actual.Count());
        }
Example #4
0
        public void GetMessage_InsertOne_ReturnIDOne()
        {
            //Arrange
            var service = new MessageBoardService(UserRepository, MessageRepository);

            //Act
            var actual = service.GetMessage(1);

            //Assert
            var expect = 1;

            Assert.AreEqual(expect, actual.ID);
        }
Example #5
0
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "delRecord")
     {
         int mid = Convert.ToInt32(e.CommandArgument);
         MessageBoardService.Delete_MessageBoard(mid);
         binddata();
     }
     else if (e.CommandName == "updRecord")
     {
         int mid = Convert.ToInt32(e.CommandArgument);
         MessageBoardService.Open_MessageBoard(mid);
         binddata();
     }
 }
    void binddata()
    {
        DataTable dt = MessageBoardService.Get_OpenedMessageBoard();

        AspNetPager1.RecordCount = dt.Rows.Count;
        if (dt.Rows.Count >= 0)
        {
            PagedDataSource ps = new PagedDataSource();
            DataView        dv = new DataView(dt);
            ps.DataSource       = dv;
            ps.AllowPaging      = true;
            ps.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            ps.PageSize         = AspNetPager1.PageSize;
            rpt_Mess.DataSource = ps;
            rpt_Mess.DataBind();
        }
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         CommonFunction.isLoginCheck();
         int mid = Convert.ToInt32(Request.QueryString["mid"]);
         ViewState["mid"] = mid;
         DataTable dt = MessageBoardService.Get_MessageBoard(mid);
         if (dt != null && dt.Rows.Count > 0)
         {
             lblName.Text    = dt.Rows[0]["M_UName"].ToString();
             lblTime.Text    = dt.Rows[0]["M_Time"].ToString();
             lblContent.Text = dt.Rows[0]["M_Content"].ToString();
             lblReply.Text   = dt.Rows[0]["M_Reply"].ToString();
         }
     }
 }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        UserInfo info = (UserInfo)Session["ServiceUser"];

        if (e.CommandName == "delRecord")
        {
            int mid = Convert.ToInt32(e.CommandArgument);
            MessageBoardService.Delete_MessageBoard(mid);
            binddata(info.U_SID);
        }
        else if (e.CommandName == "updRecord")
        {
            int mid = Convert.ToInt32(e.CommandArgument);
            MessageBoardService.Update_MessageStatus(mid);
            binddata(info.U_SID);
        }
    }
Example #9
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         CommonFunction.isLoginCheck();
         if (Request.QueryString["mid"] != null)
         {
             mid = Convert.ToInt32(Request.QueryString["mid"]);
             DataTable dt = MessageBoardService.Get_MessageBoard(mid);
             txtUName.Text   = dt.Rows[0]["M_UName"].ToString();
             txtEmail.Text   = dt.Rows[0]["M_Email"].ToString();
             txtPhone.Text   = dt.Rows[0]["M_Phone"].ToString();
             txtTime.Text    = dt.Rows[0]["M_Time"].ToString();
             txtContent.Text = dt.Rows[0]["M_Content"].ToString();
             txtReply.Text   = dt.Rows[0]["M_Reply"].ToString();
         }
     }
 }
Example #10
0
    void binddata(int sid)
    {
        DataTable dt = MessageBoardService.Get_OpenMessage(sid);

        AspNetPager1.RecordCount = dt.Rows.Count;
        if (dt.Rows.Count >= 0)
        {
            PagedDataSource ps = new PagedDataSource();
            DataView        dv = new DataView(dt);
            ps.DataSource             = dv;
            ps.AllowPaging            = true;
            ps.CurrentPageIndex       = AspNetPager1.CurrentPageIndex - 1;
            ps.PageSize               = AspNetPager1.PageSize;
            rptMessageList.DataSource = ps;
            rptMessageList.DataBind();
            lblCount.Text = dt.Rows.Count.ToString();
        }
    }
Example #11
0
        public async Task MessageBoardService_SendAsync_Returns_ThreeMessages()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <MessageBoardDbContext>()
                          .UseInMemoryDatabase("MessageBoardDB")
                          .Options;

            using (var dbContext = new MessageBoardDbContext(options))
            {
                // Clear existing messages
                dbContext.Messages.RemoveRange(dbContext.Messages);
                await dbContext.SaveChangesAsync();

                // Initialize new messages
                dbContext.Messages.Add(new MessageDb {
                    User = "******", Content = "Hello Tom.", Created = DateTime.Now.AddMinutes(5)
                });
                dbContext.Messages.Add(new MessageDb {
                    User = "******", Content = "Hi, Rick.", Created = DateTime.Now.AddMinutes(5)
                });
                await dbContext.SaveChangesAsync();
            };

            var request = new SendMessageRequest
            {
                User    = "******",
                Message = "It works."
            };
            var mapper = new MessageMapper();

            using (var dbContext = new MessageBoardDbContext(options))
            {
                var service = new MessageBoardService(mapper, dbContext);

                // Act
                await service.SendAsync(request);

                var response = await service.GetAsync();

                // Assert
                Assert.Equal(3, response.Messages.Count);
            };
        }
Example #12
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (txtUName.Text.Trim() == "")
        {
            CommonFunction.AjaxAlert(UpdatePanel1, "请输入您的姓名");
            return;
        }
        if (txtEMail.Text.Trim() == "")
        {
            CommonFunction.AjaxAlert(UpdatePanel1, "请输入电子邮件");
            return;
        }
        if (txtPhone.Text.Trim() == "")
        {
            CommonFunction.AjaxAlert(UpdatePanel1, "请输入联系电话");
            return;
        }
        if (txtContent.Text.Trim() == "")
        {
            CommonFunction.AjaxAlert(UpdatePanel1, "请输入留言内容");
            return;
        }
        MainModel.MessageBoard mess = new MainModel.MessageBoard();
        mess.M_UName   = txtUName.Text.Trim();
        mess.M_Email   = txtEMail.Text.Trim();
        mess.M_Phone   = txtPhone.Text.Trim();
        mess.M_Content = txtContent.Text.Trim();
        int result = MessageBoardService.Insert_MessageBoard(mess);

        if (result > 0)
        {
            txtUName.Text   = "";
            txtEMail.Text   = "";
            txtPhone.Text   = "";
            txtContent.Text = "";
            CommonFunction.AjaxAlertAndRedirect(UpdatePanel1, "提交成功,我们将会在最短的时间内给您回复", "MessageBoard.aspx");
        }
        else
        {
            CommonFunction.AjaxAlert(UpdatePanel1, "提交失败,请检查数据是否规范重新提交");
        }
    }
Example #13
0
 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
 {
     MessageBoardService.Reply_MessageBoard(mid, txtReply.Text);
     CommonFunction.AlertAndRedirect(Literal1, "操作成功", "MessageBoardMgr.aspx");
 }
Example #14
0
 protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
 {
     MessageBoardService.Reply_MessageBoard(Convert.ToInt32(ViewState["mid"]), lblReply.Text);
     CommonFunction.AlertAndRedirect(Literal1, "操作成功", "MessageBoardList.aspx");
 }