Added IoC interfaces. Nuget auto restore

Added interfaces to allow injection and mocking.
Setup test to use nuget packages to allow easier setup
This commit is contained in:
derikwhittaker 2013-12-14 08:40:37 -05:00
parent 563fa78c55
commit 6be84f0cf9
19 changed files with 11221 additions and 32 deletions

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

File diff suppressed because one or more lines are too long

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>

BIN
packages/NUnit.2.6.3/NUnit.2.6.3.nupkg vendored Normal file

Binary file not shown.

27
packages/NUnit.2.6.3/NUnit.2.6.3.nuspec vendored Normal file
View File

@ -0,0 +1,27 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>NUnit</id>
<version>2.6.3</version>
<title>NUnit</title>
<authors>Charlie Poole</authors>
<owners>Charlie Poole</owners>
<licenseUrl>http://nunit.org/nuget/license.html</licenseUrl>
<projectUrl>http://nunit.org/</projectUrl>
<iconUrl>http://nunit.org/nuget/nunit_32x32.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>NUnit features a fluent assert syntax, parameterized, generic and theory tests and is user-extensible. A number of runners, both from the NUnit project and by third parties, are able to execute NUnit tests.
Version 2.6 is the seventh major release of this well-known and well-tested programming tool.
This package includes only the framework assembly. You will need to install the NUnit.Runners package unless you are using a third-party runner.</description>
<summary>NUnit is a unit-testing framework for all .Net languages with a strong TDD focus.</summary>
<releaseNotes>Version 2.6 is the seventh major release of NUnit.
Unlike earlier versions, this package includes only the framework assembly. You will need to install the NUnit.Runners package unless you are using a third-party runner.
The nunit.mocks assembly is now provided by the NUnit.Mocks package. The pnunit.framework assembly is provided by the pNUnit package.</releaseNotes>
<language>en-US</language>
<tags>nunit test testing tdd framework fluent assert theory plugin addin</tags>
</metadata>
</package>

Binary file not shown.

File diff suppressed because it is too large Load Diff

15
packages/NUnit.2.6.3/license.txt vendored Normal file
View File

@ -0,0 +1,15 @@
Copyright © 2002-2013 Charlie Poole
Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
Copyright © 2000-2002 Philip A. Craig
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment (see the following) in the product documentation is required.
Portions Copyright © 2002-2013 Charlie Poole or Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov or Copyright © 2000-2002 Philip A. Craig
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\CronNETTests\packages.config" />
</repositories>