This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from laurensb/check
Fixed precondition checks
- Loading branch information
Showing
7 changed files
with
188 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ HttpServer.Sample/bin | |
HttpServer.Test/bin | ||
HttpServer/bin | ||
Tutorial/bin | ||
HttpServer_Test/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using HttpServer; | ||
using NUnit.Framework; | ||
|
||
namespace HttpServer_Test | ||
{ | ||
[TestFixture] | ||
public class CheckTests | ||
{ | ||
[Test] | ||
public void TestNotEmpty() | ||
{ | ||
Check.NotEmpty("string", "error"); | ||
Check.NotEmpty("another string", "another error"); | ||
|
||
// Even though the argument to check is non empty an exception is expected, | ||
// if this was not the case the missing error message would only be discovered when the check fails (possibly in production) | ||
Assert.That(() => Check.NotEmpty("something not empty", null), Throws.TypeOf<ArgumentException>()); | ||
|
||
Assert.That(() => Check.NotEmpty("", "error"), Throws.TypeOf<ArgumentException>()); | ||
Assert.That(() => Check.NotEmpty("", "bad parameter"), Throws.TypeOf<ArgumentException>()); | ||
Assert.That(() => Check.NotEmpty("", null), Throws.TypeOf<ArgumentException>()); | ||
|
||
Assert.That(() => Check.NotEmpty(null, "null"), Throws.TypeOf<ArgumentException>()); | ||
Assert.That(() => Check.NotEmpty(null, "cannot be null"), Throws.TypeOf<ArgumentException>()); | ||
Assert.That(() => Check.NotEmpty(null, null), Throws.TypeOf<ArgumentException>()); | ||
} | ||
|
||
[Test] | ||
public void testRequire() | ||
{ | ||
Object someObject = "some string"; | ||
|
||
Check.Require(someObject, "parameter"); | ||
Check.Require(someObject, "error message"); | ||
Assert.That(() => Check.Require(someObject, null), Throws.TypeOf<ArgumentException>()); | ||
|
||
Assert.That(() => Check.Require(null, "null"), Throws.TypeOf<ArgumentNullException>()); | ||
Assert.That(() => Check.Require(null, "cannot be null"), Throws.TypeOf<ArgumentNullException>()); | ||
Assert.That(() => Check.Require(null, null), Throws.TypeOf<ArgumentException>()); | ||
} | ||
|
||
[Test] | ||
public void TestMin() | ||
{ | ||
Check.Min(0, 100, "value"); | ||
Check.Min(-100, 0, "value"); | ||
Check.Min(int.MaxValue, int.MaxValue, "value"); | ||
Assert.That(() => Check.Min(0, 100, null), Throws.TypeOf<ArgumentException>()); | ||
|
||
Assert.That(() => Check.Min(100, 0, "value"), Throws.TypeOf<ArgumentException>()); | ||
Assert.That(() => Check.Min(0, -100, "value"), Throws.TypeOf<ArgumentException>()); | ||
Assert.That(() => Check.Min(int.MaxValue, int.MinValue, "value"), Throws.TypeOf<ArgumentException>()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> | ||
<PropertyGroup> | ||
<ProjectGuid>{C3CC0769-9814-4896-8599-9EB0B807E785}</ProjectGuid> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>HttpServer_Test</RootNamespace> | ||
<AssemblyName>HttpServer_Test</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<TargetFrameworkProfile>Client</TargetFrameworkProfile> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DebugSymbols>True</DebugSymbols> | ||
<DebugType>Full</DebugType> | ||
<Optimize>False</Optimize> | ||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DebugSymbols>False</DebugSymbols> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> | ||
<DefineConstants>TRACE</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="CheckTests.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\HttpServer\HttpServer.csproj"> | ||
<Project>{455E7D70-1C85-4D7F-9F01-DC801B8B8C34}</Project> | ||
<Name>HttpServer</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#region Using directives | ||
|
||
using System; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
#endregion | ||
|
||
// 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("HttpServer_Test")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("HttpServer_Test")] | ||
[assembly: AssemblyCopyright("Copyright 2015")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// This sets the default COM visibility of types in the assembly to invisible. | ||
// If you need to expose a type to COM, use [ComVisible(true)] on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The assembly version has following format : | ||
// | ||
// Major.Minor.Build.Revision | ||
// | ||
// You can specify all the values or you can use the default the Revision and | ||
// Build Numbers by using the '*' as shown below: | ||
[assembly: AssemblyVersion("1.0.*")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="NUnit" version="2.6.4" targetFramework="net40-Client" /> | ||
</packages> |