Skip to content

Commit

Permalink
Style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jgeurts committed Nov 19, 2013
1 parent acd0190 commit e6bac58
Show file tree
Hide file tree
Showing 8 changed files with 408 additions and 420 deletions.
160 changes: 80 additions & 80 deletions ConsoleTester/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,97 +11,97 @@ class Program
static void Main(string[] args)
{
Console.WriteLine("Which the test you'd like to run (enter the test number):");
Console.WriteLine("1. DelayFor");
Console.WriteLine("2. MiscTests (everything else)");

byte testNum;
if (byte.TryParse(Console.ReadLine(), out testNum))
{
// which test to run?
switch (testNum)
{
case 1: // DelayFor
DelayForTest();
break;
case 2: // MiscTests
MiscTests();
break;
default:
Console.WriteLine(string.Format("There's not test #{0}", testNum));
return;
}
}
else
{
MiscTests();
}
Console.WriteLine("1. DelayFor");
Console.WriteLine("2. MiscTests (everything else)");

byte testNum;
if (byte.TryParse(Console.ReadLine(), out testNum))
{
// which test to run?
switch (testNum)
{
case 1: // DelayFor
DelayForTest();
break;
case 2: // MiscTests
MiscTests();
break;
default:
Console.WriteLine(string.Format("There's not test #{0}", testNum));
return;
}
}
else
{
MiscTests();
}

Console.ReadKey();
}

static void DelayForTest()
{
Console.WriteLine("Testing DelayFor...");
static void DelayForTest()
{
Console.WriteLine("Testing DelayFor...");

TaskManager.AddTask(() => Console.WriteLine("ToRunNow() - not delayed: " + DateTime.Now), x => x.ToRunNow());
TaskManager.AddTask(() => Console.WriteLine("ToRunNow() - delayed 2 sec: " + DateTime.Now), x => x.ToRunNow().DelayFor(2).Seconds());
TaskManager.AddTask(() => Console.WriteLine("ToRunOnceAt() - not delayed: " + DateTime.Now), x => x.ToRunOnceAt(DateTime.Now));
TaskManager.AddTask(() => Console.WriteLine("ToRunOnceAt() - delayed 2 sec: " + DateTime.Now), x => x.ToRunOnceAt(DateTime.Now).DelayFor(2).Seconds());
TaskManager.AddTask(() => Console.WriteLine("ToRunEvery() - not delayed: " + DateTime.Now), x => x.ToRunEvery(2).Seconds());
TaskManager.AddTask(() => Console.WriteLine("ToRunEvery() - delayed 2 sec: " + DateTime.Now), x => x.ToRunEvery(2).Seconds().DelayFor(2).Seconds());

//TaskManager.AddTask(() => Console.WriteLine("recurring, not delayed: " + DateTime.Now), x => x.ToRunNow().DelayFor(3).Seconds());
//TaskManager.AddTask(() => Console.WriteLine("Inline task (delayed 5 sec): " + DateTime.Now), x => x.ToRunOnceAt(DateTime.Now).DelayFor(5).Seconds());
}

static void MiscTests()
{
TaskManager.TaskFactory = new MyTaskFactory();
TaskManager.TaskStart += (schedule, e) => Console.WriteLine(schedule.Name + " Started: " + schedule.StartTime);
TaskManager.TaskEnd += (schedule, e) => Console.WriteLine(schedule.Name + " Ended.\n\tStarted: " + schedule.StartTime + "\n\tDuration: " + schedule.Duration + "\n\tNext run: " + schedule.NextRunTime);

TaskManager.Initialize(new MyRegistry());
Console.WriteLine("Done initializing...");

// try to get the named schedule registered inside MyRegistry
FluentScheduler.Model.Schedule named = TaskManager.GetSchedule("named task");
if (named != null)
{
// success, execute it manually
named.Execute();
}

FluentScheduler.Model.Schedule removable = TaskManager.GetSchedule("removable task");
if (removable != null)
{
Console.WriteLine("before remove");
TaskManager.RemoveTask(removable.Name);
Console.WriteLine("after remove");
}

FluentScheduler.Model.Schedule longRemovable = TaskManager.GetSchedule("long removable task");
if (longRemovable != null)
{
Console.WriteLine("before remove long running");
TaskManager.RemoveTask(longRemovable.Name);
Console.WriteLine("after remove long running");
}

//Thread.Sleep(10000);
//TaskManager.Stop();

/* TaskManager.AddTask(() => Console.WriteLine("Inline task: " + DateTime.Now), x => x.ToRunEvery(15).Seconds());
TaskManager.AddTask(() => Console.WriteLine("Inline task (once): " + DateTime.Now), x => x.ToRunOnceAt(DateTime.Now.AddSeconds(5)));
TaskManager.AddTask<MyInlineTask>(x => x.ToRunNow());
*/
TaskManager.UnobservedTaskException += TaskManager_UnobservedTaskException;
/* TaskManager.AddTask(() => {
Console.WriteLine("Inline task: " + DateTime.Now);
throw new Exception("Hi"); }, x => x.ToRunNow());
*/
}


//TaskManager.AddTask(() => Console.WriteLine("recurring, not delayed: " + DateTime.Now), x => x.ToRunNow().DelayFor(3).Seconds());
//TaskManager.AddTask(() => Console.WriteLine("Inline task (delayed 5 sec): " + DateTime.Now), x => x.ToRunOnceAt(DateTime.Now).DelayFor(5).Seconds());
}

static void MiscTests()
{
TaskManager.TaskFactory = new MyTaskFactory();
TaskManager.TaskStart += (schedule, e) => Console.WriteLine(schedule.Name + " Started: " + schedule.StartTime);
TaskManager.TaskEnd += (schedule, e) => Console.WriteLine(schedule.Name + " Ended.\n\tStarted: " + schedule.StartTime + "\n\tDuration: " + schedule.Duration + "\n\tNext run: " + schedule.NextRunTime);

TaskManager.Initialize(new MyRegistry());
Console.WriteLine("Done initializing...");

// try to get the named schedule registered inside MyRegistry
FluentScheduler.Model.Schedule named = TaskManager.GetSchedule("named task");
if (named != null)
{
// success, execute it manually
named.Execute();
}

FluentScheduler.Model.Schedule removable = TaskManager.GetSchedule("removable task");
if (removable != null)
{
Console.WriteLine("before remove");
TaskManager.RemoveTask(removable.Name);
Console.WriteLine("after remove");
}

FluentScheduler.Model.Schedule longRemovable = TaskManager.GetSchedule("long removable task");
if (longRemovable != null)
{
Console.WriteLine("before remove long running");
TaskManager.RemoveTask(longRemovable.Name);
Console.WriteLine("after remove long running");
}

//Thread.Sleep(10000);
//TaskManager.Stop();

/* TaskManager.AddTask(() => Console.WriteLine("Inline task: " + DateTime.Now), x => x.ToRunEvery(15).Seconds());
TaskManager.AddTask(() => Console.WriteLine("Inline task (once): " + DateTime.Now), x => x.ToRunOnceAt(DateTime.Now.AddSeconds(5)));
TaskManager.AddTask<MyInlineTask>(x => x.ToRunNow());
*/
TaskManager.UnobservedTaskException += TaskManager_UnobservedTaskException;
/* TaskManager.AddTask(() => {
Console.WriteLine("Inline task: " + DateTime.Now);
throw new Exception("Hi"); }, x => x.ToRunNow());
*/
}

static void TaskManager_UnobservedTaskException(TaskExceptionInformation sender, UnhandledExceptionEventArgs e)
{
Expand Down
150 changes: 75 additions & 75 deletions FluentScheduler.Tests/ScheduleTests/DelayFor_ToRunEvery_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,79 @@

namespace FluentScheduler.Tests.ScheduleTests
{
[TestFixture]
public class DelayFor_ToRunEvery_Tests
{
[Test]
public void Should_Delay_ToRunEvery_For_2_Seconds()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Seconds").ToRunEvery(10).Seconds().DelayFor(2).Seconds());
DateTime expectedTime = DateTime.Now.AddSeconds(12);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Seconds").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Minutes()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Minutes").ToRunEvery(10).Seconds().DelayFor(2).Minutes());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddMinutes(2);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Minutes").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Hours()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Hours").ToRunEvery(10).Seconds().DelayFor(2).Hours());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddHours(2);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Hours").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Days()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Days").ToRunEvery(10).Seconds().DelayFor(2).Days());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddDays(2);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Days").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Weeks()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Weeks").ToRunEvery(10).Seconds().DelayFor(2).Weeks());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddDays(14);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Weeks").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Months()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Months").ToRunEvery(10).Seconds().DelayFor(2).Months());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddMonths(2);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Months").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Years()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Years").ToRunEvery(10).Seconds().DelayFor(2).Years());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddYears(2);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Years").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}

}
[TestFixture]
public class DelayFor_ToRunEvery_Tests
{
[Test]
public void Should_Delay_ToRunEvery_For_2_Seconds()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Seconds").ToRunEvery(10).Seconds().DelayFor(2).Seconds());
DateTime expectedTime = DateTime.Now.AddSeconds(12);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Seconds").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Minutes()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Minutes").ToRunEvery(10).Seconds().DelayFor(2).Minutes());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddMinutes(2);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Minutes").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Hours()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Hours").ToRunEvery(10).Seconds().DelayFor(2).Hours());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddHours(2);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Hours").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Days()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Days").ToRunEvery(10).Seconds().DelayFor(2).Days());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddDays(2);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Days").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Weeks()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Weeks").ToRunEvery(10).Seconds().DelayFor(2).Weeks());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddDays(14);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Weeks").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Months()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Months").ToRunEvery(10).Seconds().DelayFor(2).Months());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddMonths(2);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Months").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}
[Test]
public void Should_Delay_ToRunEvery_For_2_Years()
{
TaskManager.AddTask(() => { }, x => x.WithName("Should_Delay_ToRunEvery_For_2_Years").ToRunEvery(10).Seconds().DelayFor(2).Years());
DateTime expectedTime = DateTime.Now.AddSeconds(10).AddYears(2);

DateTime actualTime = TaskManager.GetSchedule("Should_Delay_ToRunEvery_For_2_Years").NextRunTime;

Assert.AreEqual(Math.Floor(expectedTime.TimeOfDay.TotalSeconds), Math.Floor(actualTime.TimeOfDay.TotalSeconds));
}

}
}
Loading

0 comments on commit e6bac58

Please sign in to comment.