public void DeleteTest() { Report v = new Report(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.Temperature = 36; context.Set <Report>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(ReportVM)); ReportVM vm = rv.Model as ReportVM; v = new Report(); v.ID = vm.Entity.ID; vm.Entity = v; _controller.Delete(v.ID.ToString(), null); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { Assert.AreEqual(context.Set <Report>().Count(), 0); } }
public void Delete_WithID_ReturnsViewOfReport() { // Given Report ReturnReport = new Report() { Active = true }; // Adjust Mocked Components var _svc = new Mock <IReportService>(); _svc.Setup(m => m.GetById(1)) .Returns(ReturnReport); var _Controller = new ReportController(_db, _svc.Object); _Controller.TempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()); // When var Result = _Controller.Delete(1) as ViewResult; var Report = (Report)Result.ViewData.Model; // Then // Ensue Report Returned Assert.Equal(ReturnReport, Report); }
public void Delete_WithFalseID_RedirectsCorrectly() { // Given Report ReturnReport = null; // Adjust Mocked Components var _svc = new Mock <IReportService>(); _svc.Setup(m => m.GetById(1)) .Returns(ReturnReport); var _Controller = new ReportController(_db, _svc.Object); _Controller.TempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()); // When var Result = (RedirectToActionResult)_Controller.Delete(1); // Then Assert.Equal("ViewReports", Result.ActionName); Assert.Equal("Report", Result.ControllerName); }
public void Integration_DeleteAReport_Success() { // Given: Seed _Seeder.Seed(); _ReportController.TempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()); // Call Contoller to get report var ViewReport = _ReportController.ViewReport(1) as ViewResult; // From that page Load for delete var RetrievedReport = (Report)ViewReport.ViewData.Model; // Call Controller to Delete var Result = _ReportController.Delete(RetrievedReport.CityID) as ViewResult; // Check The Page Contains Report to be deleted var Report = (Report)Result.ViewData.Model; var ExpectedToDelete = _db.Reports.First(e => e.CityID == 1); Assert.Equal(ExpectedToDelete, Report); // Now Confirm Delete is hit var Return = (RedirectToActionResult)_ReportController .ConfirmDelete(Report.CityID); // Check Redirect Assert.Equal("ViewReports", Return.ActionName); Assert.Equal("Report", Return.ControllerName); // Check Report is removed from Database var Deleted = _db.Reports.FirstOrDefault(e => e.ThreeWordAddress == ExpectedToDelete.ThreeWordAddress); Assert.Null(Deleted); }
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(); }