mirror of
https://github.com/kevincolyar/CronNET.git
synced 2025-07-27 13:05:54 +02:00
Merges changes from Mehdi Gholam (mgholam@hotmail.com)
This commit is contained in:
51
CronNETTests/CronNETTests.csproj
Normal file → Executable file
51
CronNETTests/CronNETTests.csproj
Normal file → Executable file
@@ -1,4 +1,5 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
@@ -9,6 +10,27 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>CronTests</RootNamespace>
|
||||
<AssemblyName>CronTests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>2.0</OldToolsVersion>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -28,7 +50,10 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MbUnit.Framework, Version=2.4.2.130, Culture=neutral, PublicKeyToken=5e72ecd30bc408d5" />
|
||||
<Reference Include="nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\framework\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
@@ -43,6 +68,28 @@
|
||||
<Name>CronNET</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
143
CronNETTests/CronScheduleTests.cs
Normal file → Executable file
143
CronNETTests/CronScheduleTests.cs
Normal file → Executable file
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CronNET;
|
||||
using MbUnit.Framework;
|
||||
using NUnit.Framework;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace CronTests
|
||||
{
|
||||
@@ -13,179 +15,178 @@ namespace CronTests
|
||||
public void is_valid_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule();
|
||||
Assert.IsTrue(cron_schedule.is_valid("* * * * *"));
|
||||
Assert.IsTrue(cron_schedule.is_valid("0 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.is_valid("0,1,2 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.is_valid("*/2 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.is_valid("1-4 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.is_valid("1-55 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.is_valid("1,10,20 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.is_valid("* 1,10,20 * * *"));
|
||||
Assert.IsTrue(cron_schedule.isValid("*/2"));
|
||||
Assert.IsTrue(cron_schedule.isValid("* * * * *"));
|
||||
Assert.IsTrue(cron_schedule.isValid("0 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.isValid("0,1,2 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.isValid("*/2 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.isValid("1-4 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.isValid("1-55/3 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.isValid("1,10,20 * * * *"));
|
||||
Assert.IsTrue(cron_schedule.isValid("* 1,10,20 * * *"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void divided_array_test()
|
||||
public static void divided_array_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule();
|
||||
List<int> results = cron_schedule.divided_array("*/2", 0, 10);
|
||||
ArrayAssert.AreEqual(results.ToArray(), new int[]{0, 2, 4, 6, 8 } );
|
||||
CronSchedule cron_schedule = new CronSchedule("*/2");
|
||||
List<int> results = cron_schedule.minutes.GetRange(0,5);//("*/2", 0, 10);
|
||||
Assert.AreEqual(results.ToArray(), new int[] { 0, 2, 4, 6, 8 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void range_array_test()
|
||||
public static void range_array_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule();
|
||||
List<int> results = cron_schedule.range_array("1-10");
|
||||
ArrayAssert.AreEqual(results.ToArray(), new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } );
|
||||
CronSchedule cron_schedule = new CronSchedule("1-10");
|
||||
List<int> results = cron_schedule.minutes.GetRange(0,10);//();
|
||||
Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||
var cs = new CronSchedule("1-10/3 20-45/4 * * *");
|
||||
results = cs.minutes;
|
||||
Assert.AreEqual(results.ToArray(), new int[] { 3, 6, 9 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void wild_array_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule();
|
||||
List<int> results = cron_schedule.wild_array("*", 0, 10);
|
||||
ArrayAssert.AreEqual(results.ToArray(), new int[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } );
|
||||
CronSchedule cron_schedule = new CronSchedule("*");
|
||||
List<int> results = cron_schedule.minutes.GetRange(0,10);//("*", 0, 10);
|
||||
Assert.AreEqual(results.ToArray(), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void list_array_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule();
|
||||
List<int> results = cron_schedule.list_array("1,2,3,4,5,6,7,8,9,10");
|
||||
ArrayAssert.AreEqual(results.ToArray(), new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } );
|
||||
CronSchedule cron_schedule = new CronSchedule("1,2,3,4,5,6,7,8,9,10");
|
||||
List<int> results = cron_schedule.minutes;
|
||||
Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void generate_values_divided_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule();
|
||||
List<int> results = cron_schedule.generate_values("*/2", 0, 10);
|
||||
ArrayAssert.AreEqual(results.ToArray(), new int[]{0, 2, 4, 6, 8 } );
|
||||
CronSchedule cron_schedule = new CronSchedule("*/2");
|
||||
List<int> results = cron_schedule.minutes.GetRange(0,5);//(, 0, 10);
|
||||
Assert.AreEqual(results.ToArray(), new int[] { 0, 2, 4, 6, 8 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void generate_values_range_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule();
|
||||
List<int> results = cron_schedule.generate_values("1-10", 0, 10);
|
||||
ArrayAssert.AreEqual(results.ToArray(), new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void generate_values_wild_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule();
|
||||
List<int> results = cron_schedule.generate_values("*", 0, 10);
|
||||
ArrayAssert.AreEqual(results.ToArray(), new int[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void generate_values_list_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule();
|
||||
List<int> results = cron_schedule.generate_values("1,2,3,4,5,6,7,8,9,10", 0, 10);
|
||||
ArrayAssert.AreEqual(results.ToArray(), new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } );
|
||||
CronSchedule cron_schedule = new CronSchedule("1-10");
|
||||
List<int> results = cron_schedule.minutes.GetRange(0,10);//(, 0, 10);
|
||||
Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void generate_minutes_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("1,2,3 * * * *");
|
||||
ArrayAssert.AreEqual(cron_schedule.minutes.ToArray(), new int[]{ 1, 2, 3 } );
|
||||
Assert.AreEqual(cron_schedule.minutes.ToArray(), new int[] { 1, 2, 3 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void generate_hours_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("* 1,2,3 * * *");
|
||||
ArrayAssert.AreEqual(cron_schedule.hours.ToArray(), new int[]{ 1, 2, 3 } );
|
||||
Assert.AreEqual(cron_schedule.hours.ToArray(), new int[] { 1, 2, 3 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void generate_days_of_month_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("* * 1,2,3 * *");
|
||||
ArrayAssert.AreEqual(cron_schedule.days_of_month.ToArray(), new int[]{ 1, 2, 3 } );
|
||||
Assert.AreEqual(cron_schedule.days_of_month.ToArray(), new int[] { 1, 2, 3 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void generate_months_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("* * * 1,2,3 *");
|
||||
ArrayAssert.AreEqual(cron_schedule.months.ToArray(), new int[]{ 1, 2, 3 } );
|
||||
Assert.AreEqual(cron_schedule.months.ToArray(), new int[] { 1, 2, 3 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void generate_days_of_weeks()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("* * * * 1,2,3 " );
|
||||
ArrayAssert.AreEqual(cron_schedule.days_of_week.ToArray(), new int[]{ 1, 2, 3 } );
|
||||
CronSchedule cron_schedule = new CronSchedule("* * * * 1,2,3 ");
|
||||
Assert.AreEqual(cron_schedule.days_of_week.ToArray(), new int[] { 1, 2, 3 });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void is_time_minute_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("0 * * * *");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("8:00 am")));
|
||||
Assert.IsFalse(cron_schedule.is_time(DateTime.Parse("8:01 am")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am")));
|
||||
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("8:01 am")));
|
||||
|
||||
cron_schedule = new CronSchedule("0-10 * * * *");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("8:00 am")));
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("8:03 am")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:03 am")));
|
||||
|
||||
cron_schedule = new CronSchedule("*/2 * * * *");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("8:00 am")));
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("8:02 am")));
|
||||
Assert.IsFalse(cron_schedule.is_time(DateTime.Parse("8:03 am")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:02 am")));
|
||||
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("8:03 am")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void is_time_hour_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("* 0 * * *");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("12:00 am")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 am")));
|
||||
|
||||
cron_schedule = new CronSchedule("* 0,12 * * *");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("12:00 am")));
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("12:00 pm")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 am")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 pm")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void is_time_day_of_month_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("* * 1 * *");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("10/1/08")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("2010/08/01")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void is_time_month_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("* * * 1 *");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("1/1/08")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("1/1/2008")));
|
||||
|
||||
cron_schedule = new CronSchedule("* * * 12 *");
|
||||
Assert.IsFalse(cron_schedule.is_time(DateTime.Parse("1/1/08")));
|
||||
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("1/1/2008")));
|
||||
|
||||
cron_schedule = new CronSchedule("* * * */3 *");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("3/1/08")));
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("6/1/08")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("3/1/2008")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("6/1/2008")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void is_time_day_of_week_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("* * * * 0");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("10/12/08")));
|
||||
Assert.IsFalse(cron_schedule.is_time(DateTime.Parse("10/13/08")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("10/12/2008")));
|
||||
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("10/13/2008")));
|
||||
|
||||
cron_schedule = new CronSchedule("* * * * */2");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("10/14/08")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("10/14/2008")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void is_time_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("0 0 12 10 *");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("12:00:00 am 10/12/08")));
|
||||
Assert.IsFalse(cron_schedule.is_time(DateTime.Parse("12:01:00 am 10/12/08")));
|
||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00:00 am 10/12/2008")));
|
||||
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("12:01:00 am 10/12/2008")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void ppp()
|
||||
{
|
||||
CronDaemon d = new CronDaemon();
|
||||
d.AddJob("*/1 * * * *", () => { Console.WriteLine(DateTime.Now.ToString()); });
|
||||
d.Start();
|
||||
//Thread.Sleep(60 * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
0
CronNETTests/Properties/AssemblyInfo.cs
Normal file → Executable file
0
CronNETTests/Properties/AssemblyInfo.cs
Normal file → Executable file
Reference in New Issue
Block a user