示例#1
0
        public void CreateReportReturnsOkAndAddsUser()
        {
            var reportDTO = (new ReportDTO
            {
                UserId = 1,
                Date = new DateTime(2020, 1, 1, 11, 11, 11),
                Hours = 6,
                Note = "note"
            });

            // Arrange
            var serviceMoq = new Mock <IReportService>();

            serviceMoq.Setup(repo => repo.AddReport(reportDTO)).Returns(new ServiceResultDTO(true));

            ReportController reportController = new ReportController(serviceMoq.Object, AutomapperSingleton.Mapper);

            // Act
            var result = reportController.AddReport(reportDTO);

            // Assert
            var viewResult = Assert.IsType <OkObjectResult>(result);

            serviceMoq.Verify(r => r.AddReport(reportDTO));
        }
示例#2
0
        public void CreateReportWithModelErrorReturnsValidationErrorMessage()
        {
            var reportDTO = new ReportDTO();
            // Arrange
            var serviceMoq = new Mock <IReportService>();
            ReportController reportController = new ReportController(serviceMoq.Object, AutomapperSingleton.Mapper);

            reportController.ModelState.AddModelError("Note", "Required");

            // Act
            BadRequestObjectResult result = (BadRequestObjectResult)reportController.AddReport(reportDTO);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
            SerializableError errorMessages = (SerializableError)result.Value;

            Assert.Equal("Required", ((string[])errorMessages["Note"])[0]);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (dpEnd.Value > DateTime.Now)
            {
                if (dpEnd.Value.Date < dpStart.Value.Date)
                {
                    MessageBox.Show("Đặt lại deadline phải lớn hơn ngày bắt đầu");
                    return;
                }
                progress.idProject = this.txbID.Text.Trim();
                progress.Name      = this.txbName.Text.Trim();
                //progress.listStudent = null;
                progress.dateStart  = this.dpStart.Value;
                progress.finishTime = this.dpEnd.Value;
                //progress.submitTime = this.dpSubmitted.Value;
                if (txtMark.Enabled == false)
                {
                    progress.mark = 0;
                }
                else
                {
                    progress.mark = float.Parse(this.txtMark.Text.Trim());
                }
                if (this.txtSource.Text != "" && sourceEdit == false)
                {
                    progress.finished   = true;
                    progress.submitTime = this.dpSubmitted.Value;
                    source = txtSource.Text.Trim();
                }
                else if (this.txtSource.Text != "" && sourceEdit == true)
                {
                    progress.finished   = true;
                    progress.submitTime = DateTime.Now;
                    source = txtSource.Text.Trim();
                }
                edit = true;

                // thêm các lần Báo cáo
                for (int i = 0; i < dicReport.Count; i++)
                {
                    if (dicReport[dicReport.Keys.ElementAt(i)] == "")
                    {
                        dicReport[dicReport.Keys.ElementAt(i)] = this.rbComment.Text;
                    }
                }

                ReportController.Delete(progress.idProject);
                // Add rport vào database
                for (int i = 0; i < dicReport.Count; i++)
                {
                    Report rp = new Report();
                    rp.id      = progress.idProject + '-' + dicReport.Keys.ElementAt(i);//1811_lẦN 1
                    rp.comment = dicReport[dicReport.Keys.ElementAt(i)];
                    ReportController.AddReport(rp);
                }
            }
            else
            {
                MessageBox.Show("hết hạn nộp bài");
            }
            this.Close();
        }