Merge pull request #2 from derikwhittaker/master

IoC/Mocking Support.  Added Nuget references
This commit is contained in:
Kevin Colyar 2013-12-14 12:20:43 -08:00
commit bfe1a1f92c
14 changed files with 383 additions and 35 deletions

175
.gitignore vendored
View File

@ -1,4 +1,173 @@
_Resharper*
*.resharper*
#################
## Customer
#################
_ReSharper*
TestResults
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover
## TODO: If you have NuGet Package Restore enabled, uncomment this
packages/
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
# ReSharper is a .NET coding add-in
_ReSharper*
# Installshield output folder
[Ee]xpress
#azure
*.PublishSettings
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish
# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
############
## Windows
############
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
obj
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
# Mac crap
.DS_Store

6
.nuget/NuGet.Config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>

BIN
.nuget/NuGet.exe Normal file

Binary file not shown.

136
.nuget/NuGet.targets Normal file
View File

@ -0,0 +1,136 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
</PropertyGroup>
<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://www.nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
<PackagesConfig>packages.config</PackagesConfig>
</PropertyGroup>
<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>
<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>
<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
</Target>
<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />
<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>

View File

@ -1,10 +1,19 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C# Express 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CronNET", "CronNET\CronNET.csproj", "{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CronNETTests", "CronNETTests\CronNETTests.csproj", "{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{EA4722C9-7FD3-4D8C-BA24-AAAFC5E52EAC}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\NuGet.exe = .nuget\NuGet.exe
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

Binary file not shown.

BIN
CronNET.v12.suo Normal file

Binary file not shown.

View File

@ -5,10 +5,17 @@ using System.Threading;
namespace CronNET
{
public class CronDaemon
public interface ICronDaemon
{
void AddJob(string schedule, ThreadStart action);
void Start();
void Stop();
}
public class CronDaemon : ICronDaemon
{
private readonly System.Timers.Timer timer = new System.Timers.Timer(30000);
private readonly List<CronJob> cron_jobs = new List<CronJob>();
private readonly List<ICronJob> cron_jobs = new List<ICronJob>();
private DateTime _last= DateTime.Now;
public CronDaemon()
@ -41,7 +48,7 @@ namespace CronNET
if (DateTime.Now.Minute != _last.Minute)
{
_last = DateTime.Now;
foreach (CronJob job in cron_jobs)
foreach (ICronJob job in cron_jobs)
job.execute(DateTime.Now);
}
}

View File

@ -3,9 +3,15 @@ using System.Threading;
namespace CronNET
{
public class CronJob
public interface ICronJob
{
private readonly CronSchedule _cron_schedule = new CronSchedule();
void execute(DateTime date_time);
void abort();
}
public class CronJob : ICronJob
{
private readonly ICronSchedule _cron_schedule = new CronSchedule();
private readonly ThreadStart _thread_start;
private Thread _thread;

View File

@ -4,7 +4,13 @@ using System.Text.RegularExpressions;
namespace CronNET
{
public class CronSchedule
public interface ICronSchedule
{
bool isValid(string expression);
bool isTime(DateTime date_time);
}
public class CronSchedule : ICronSchedule
{
#region Readonly Class Members

View File

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
//
// 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")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]

View File

@ -31,6 +31,8 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -50,9 +52,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<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 Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
@ -90,7 +91,11 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.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">

View File

@ -14,7 +14,7 @@ namespace CronTests
[Test]
public void is_valid_test()
{
CronSchedule cron_schedule = new CronSchedule();
var cron_schedule = new CronSchedule();
Assert.IsTrue(cron_schedule.isValid("*/2"));
Assert.IsTrue(cron_schedule.isValid("* * * * *"));
Assert.IsTrue(cron_schedule.isValid("0 * * * *"));
@ -29,7 +29,7 @@ namespace CronTests
[Test]
public static void divided_array_test()
{
CronSchedule cron_schedule = new CronSchedule("*/2");
var 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 });
}
@ -37,7 +37,7 @@ namespace CronTests
[Test]
public static void range_array_test()
{
CronSchedule cron_schedule = new CronSchedule("1-10");
var 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 * * *");
@ -48,7 +48,7 @@ namespace CronTests
[Test]
public void wild_array_test()
{
CronSchedule cron_schedule = new CronSchedule("*");
var 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 });
}
@ -56,7 +56,7 @@ namespace CronTests
[Test]
public void list_array_test()
{
CronSchedule cron_schedule = new CronSchedule("1,2,3,4,5,6,7,8,9,10");
var 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 });
}
@ -64,7 +64,7 @@ namespace CronTests
[Test]
public void generate_values_divided_test()
{
CronSchedule cron_schedule = new CronSchedule("*/2");
var 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 });
}
@ -72,7 +72,7 @@ namespace CronTests
[Test]
public void generate_values_range_test()
{
CronSchedule cron_schedule = new CronSchedule("1-10");
var 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 });
}
@ -80,42 +80,42 @@ namespace CronTests
[Test]
public void generate_minutes_test()
{
CronSchedule cron_schedule = new CronSchedule("1,2,3 * * * *");
var cron_schedule = new CronSchedule("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 * * *");
var cron_schedule = new CronSchedule("* 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 * *");
var cron_schedule = new CronSchedule("* * 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 *");
var cron_schedule = new CronSchedule("* * * 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 ");
var 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 * * * *");
var cron_schedule = new CronSchedule("0 * * * *");
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am")));
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("8:01 am")));
@ -132,7 +132,7 @@ namespace CronTests
[Test]
public void is_time_hour_test()
{
CronSchedule cron_schedule = new CronSchedule("* 0 * * *");
var cron_schedule = new CronSchedule("* 0 * * *");
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 am")));
cron_schedule = new CronSchedule("* 0,12 * * *");
@ -143,14 +143,14 @@ namespace CronTests
[Test]
public void is_time_day_of_month_test()
{
CronSchedule cron_schedule = new CronSchedule("* * 1 * *");
var cron_schedule = new CronSchedule("* * 1 * *");
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("2010/08/01")));
}
[Test]
public void is_time_month_test()
{
CronSchedule cron_schedule = new CronSchedule("* * * 1 *");
var cron_schedule = new CronSchedule("* * * 1 *");
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("1/1/2008")));
cron_schedule = new CronSchedule("* * * 12 *");
@ -164,7 +164,7 @@ namespace CronTests
[Test]
public void is_time_day_of_week_test()
{
CronSchedule cron_schedule = new CronSchedule("* * * * 0");
var cron_schedule = new CronSchedule("* * * * 0");
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("10/12/2008")));
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("10/13/2008")));
@ -175,7 +175,7 @@ namespace CronTests
[Test]
public void is_time_test()
{
CronSchedule cron_schedule = new CronSchedule("0 0 12 10 *");
var cron_schedule = new CronSchedule("0 0 12 10 *");
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")));
}
@ -183,7 +183,7 @@ namespace CronTests
[Test]
public static void ppp()
{
CronDaemon d = new CronDaemon();
var d = new CronDaemon();
d.AddJob("*/1 * * * *", () => { Console.WriteLine(DateTime.Now.ToString()); });
d.Start();
//Thread.Sleep(60 * 1000);

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.3" targetFramework="net40" />
</packages>