public void DuplicateApplyTest() { _leave = CreateLeave("Unit Test: Apply with overlapping date."); LeaveProcessComponent upc = new LeaveProcessComponent(); // 1. Apply a new leave. _leave = upc.Apply(_leave); Assert.AreEqual(_leave.Status, LeaveStatuses.Pending, "Failed to apply new leave."); // Keep the previous workflow instance. Guid correlationId = _leave.CorrelationID; try { // 2. This will cause exception to occur. upc.Apply(_leave); } catch (ApplicationException ex) { if (ex.Message != "Date range is overlapping with another leave.") { throw ex; } } // 3. Cancel it. // Need to do this, otherwise, there will be an orphaned workflow instance. _leave.CorrelationID = correlationId; upc.Cancel(_leave); _leave = upc.GetLeaveById(_leave.LeaveID); Assert.AreEqual(_leave.Status, LeaveStatuses.Cancelled, "Failed to cancel leave."); }
public void ApplyThenRejectTest() { _leave = CreateLeave("Unit Test: Apply Then Reject"); LeaveProcessComponent upc = new LeaveProcessComponent(); // 1. Apply a new leave. _leave = upc.Apply(_leave); Assert.AreEqual(_leave.Status, LeaveStatuses.Pending, "Failed to apply new leave."); // 2. Reject it. upc.Reject(_leave); _leave = upc.GetLeaveById(_leave.LeaveID); Assert.AreEqual(_leave.Status, LeaveStatuses.Rejected, "Failed to reject leave."); }
public ActionResult Index(Leave leave) { ViewBag.Categories = GetCategories(); // Validate date. if (leave.StartDate > leave.EndDate) { ModelState.AddModelError("DateError", "Start date cannot be greater than End date."); } else { // Validate duration. var totalDays = leave.EndDate.Subtract(leave.StartDate).Days + 1; if (leave.Duration > totalDays) { ModelState.AddModelError("DurationError", "Duration cannot be greater than the number of days in selected date range."); } } leave.Status = LeaveStatuses.Pending; if (ModelState.IsValid) { try { var upc = new LeaveProcessComponent(); leave = upc.Apply(leave); _clients.All.LeaveApplied(leave); } catch (ApplicationException ex) { ModelState.AddModelError(string.Empty, ex.Message); } } return(View(leave)); }