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 ActionResult Cancel(Leave leave) { if (ModelState.IsValid) { var upc = new LeaveProcessComponent(); leave = upc.Cancel(leave); } return(GetJsonResult(leave)); }
public void ApplyThenCancelTest() { _leave = CreateLeave("Unit Test: Apply Then Cancel"); 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. Cancel it. upc.Cancel(_leave); _leave = upc.GetLeaveById(_leave.LeaveID); Assert.AreEqual(_leave.Status, LeaveStatuses.Cancelled, "Failed to cancel leave."); }