Skip to content

Commit

Permalink
Added support for RemoveAllJobs and updated unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
GraceAtwood committed Jun 19, 2017
1 parent 188398d commit 46a16ca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Library/JobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@ public static void RemoveJob(string name)
_schedules.Remove(name);
}

/// <summary>
/// Removes all schedules.
/// </summary>
public static void RemoveAllJobs()
{
_schedules.RemoveAll();
}

#endregion

#region Calculating, scheduling & running
Expand Down
8 changes: 8 additions & 0 deletions Library/Util/ScheduleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ internal bool Remove(Schedule schedule)
}
}

internal void RemoveAll()
{
lock (_lock)
{
_schedules.Clear();
}
}

internal Schedule First()
{
lock (_lock)
Expand Down
17 changes: 17 additions & 0 deletions UnitTests/ScheduleTests/RemoveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ public void Should_Remove_Named_Job()
Assert.IsNull(JobManager.GetSchedule("remove named job"));
}

[TestMethod]
public void Should_Remove_All_Jobs()
{
// Act
JobManager.AddJob(() => { }, s => s.ToRunNow());
JobManager.AddJob(() => { }, s => s.ToRunNow());
JobManager.AddJob(() => { }, s => s.ToRunNow());
JobManager.AddJob(() => { }, s => s.ToRunNow());
JobManager.AddJob(() => { }, s => s.ToRunNow());
JobManager.AddJob(() => { }, s => s.ToRunNow());

JobManager.RemoveAllJobs();

// Assert
Assert.IsTrue(JobManager.AllSchedules.Count() == 0);
}

[TestMethod]
public void Should_Remove_LongRunning_Job_But_Keep_Running()
{
Expand Down

0 comments on commit 46a16ca

Please sign in to comment.