mirror of
https://github.com/kevincolyar/CronNET.git
synced 2025-07-27 13:05:54 +02:00
Initial commit
This commit is contained in:
191
CronNETTests/CronScheduleTests.cs
Normal file
191
CronNETTests/CronScheduleTests.cs
Normal file
@@ -0,0 +1,191 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cron;
|
||||
using MbUnit.Framework;
|
||||
|
||||
namespace CronTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CronScheduleTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
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 * * *"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public 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 } );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public 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 } );
|
||||
}
|
||||
[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 } );
|
||||
}
|
||||
[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 } );
|
||||
}
|
||||
|
||||
[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 } );
|
||||
}
|
||||
|
||||
[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 } );
|
||||
}
|
||||
|
||||
[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 } );
|
||||
}
|
||||
|
||||
[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 } );
|
||||
}
|
||||
|
||||
[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 } );
|
||||
}
|
||||
|
||||
[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 } );
|
||||
}
|
||||
|
||||
[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 } );
|
||||
}
|
||||
|
||||
[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")));
|
||||
|
||||
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")));
|
||||
|
||||
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")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void is_time_hour_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("* 0 * * *");
|
||||
Assert.IsTrue(cron_schedule.is_time(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")));
|
||||
}
|
||||
|
||||
[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")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void is_time_month_test()
|
||||
{
|
||||
CronSchedule cron_schedule = new CronSchedule("* * * 1 *");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("1/1/08")));
|
||||
|
||||
cron_schedule = new CronSchedule("* * * 12 *");
|
||||
Assert.IsFalse(cron_schedule.is_time(DateTime.Parse("1/1/08")));
|
||||
|
||||
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")));
|
||||
}
|
||||
|
||||
[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")));
|
||||
|
||||
cron_schedule = new CronSchedule("* * * * */2");
|
||||
Assert.IsTrue(cron_schedule.is_time(DateTime.Parse("10/14/08")));
|
||||
}
|
||||
|
||||
[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")));
|
||||
}
|
||||
}
|
||||
}
|
54
CronNETTests/CronTests.csproj
Normal file
54
CronNETTests/CronTests.csproj
Normal file
@@ -0,0 +1,54 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>CronTests</RootNamespace>
|
||||
<AssemblyName>CronTests</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MbUnit.Framework, Version=2.4.2.130, Culture=neutral, PublicKeyToken=5e72ecd30bc408d5" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CronScheduleTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CronDaemon\Cron.csproj">
|
||||
<Project>{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}</Project>
|
||||
<Name>Cron</Name>
|
||||
</ProjectReference>
|
||||
</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.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
35
CronNETTests/Properties/AssemblyInfo.cs
Normal file
35
CronNETTests/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("CronNETTests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("CronNETTests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2008")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("6a430089-ab18-4d72-9d7a-5a4ee0883153")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
Reference in New Issue
Block a user