Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit a2450e9b45f0b9fb5caf7240f4ab7a551f77f9ef 0 parents
dnewman authored
9 .gitignore
@@ -0,0 +1,9 @@
+*.suo
+*.cache
+*csproj.user
+src/*/bin
+src/*/obj
+*resharper*
+_ReSharper*
+
+build
26 Shouldly.sln
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shouldly", "src\Shouldly\Shouldly.csproj", "{CF49E8A3-57E1-4F43-B2DC-7092D2B7677F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "src\Tests\Tests.csproj", "{7E798127-21FE-4F49-A221-53B53B40D6BE}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {CF49E8A3-57E1-4F43-B2DC-7092D2B7677F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CF49E8A3-57E1-4F43-B2DC-7092D2B7677F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CF49E8A3-57E1-4F43-B2DC-7092D2B7677F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CF49E8A3-57E1-4F43-B2DC-7092D2B7677F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7E798127-21FE-4F49-A221-53B53B40D6BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7E798127-21FE-4F49-A221-53B53B40D6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7E798127-21FE-4F49-A221-53B53B40D6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7E798127-21FE-4F49-A221-53B53B40D6BE}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
BIN  lib/NUnit-2.5.3.9345/nunit.framework.dll
Binary file not shown
10,113 lib/NUnit-2.5.3.9345/nunit.framework.xml
10,113 additions, 0 deletions not shown
36 src/Shouldly/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+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("Shouldly")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Shouldly")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[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("bed144e8-93e0-4a1e-9a59-491a29d1f430")]
+
+// 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 Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
53 src/Shouldly/ShouldBeTestExtensions.cs
@@ -0,0 +1,53 @@
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using NUnit.Framework;
+using NUnit.Framework.Constraints;
+
+namespace Shouldly
+{
+ [DebuggerStepThrough]
+ public static class ShouldBeTestExtensions
+ {
+ public static void ShouldBe<T>(this T actual, T expected)
+ {
+ actual.AssertAwesomely(Is.EqualTo(expected), actual, expected);
+ }
+
+ public static void ShouldBe(this float actual, float expected, double tolerance)
+ {
+ actual.AssertAwesomely(Is.EqualTo(expected).Within(tolerance), actual, expected);
+ }
+
+ public static void ShouldContain(this string actual, string expected)
+ {
+ actual.AssertAwesomely(Is.StringContaining(expected).IgnoreCase, actual, expected);
+ }
+
+ public static void ShouldContain<T>(this IEnumerable<T> actual, T expected)
+ {
+ if (!actual.Contains(expected))
+ {
+ throw new AssertionException(new ShouldlyMessage(expected, actual).ToString());
+ }
+ }
+
+ public static void ShouldNotContain(this string actual, string expected)
+ {
+ actual.AssertAwesomely(Is.Not.StringContaining(expected).IgnoreCase, actual, expected);
+ }
+
+ public static void ShouldBeGreaterThan(this int actual, int expected)
+ {
+ actual.AssertAwesomely(Is.GreaterThan(expected), actual, expected);
+ }
+
+ private static void AssertAwesomely<T>(this T actual, IResolveConstraint specifiedConstraint, object originalActual, object originalExpected)
+ {
+ var constraint = specifiedConstraint.Resolve();
+ if (constraint.Matches(actual)) return;
+
+ throw new AssertionException(new ShouldlyMessage(originalExpected, originalActual).ToString());
+ }
+ }
+}
67 src/Shouldly/Shouldly.csproj
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{CF49E8A3-57E1-4F43-B2DC-7092D2B7677F}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Shouldly</RootNamespace>
+ <AssemblyName>Shouldly</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\..\build\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="nunit.framework">
+ <HintPath>..\..\lib\NUnit-2.5.3.9345\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.IdentityModel">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="ShouldBeTestExtensions.cs" />
+ <Compile Include="ShouldlyMessage.cs" />
+ <Compile Include="StringHelpers.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\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>
91 src/Shouldly/ShouldlyMessage.cs
@@ -0,0 +1,91 @@
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+
+namespace Shouldly
+{
+ public class ShouldlyMessage
+ {
+ private readonly object expected;
+ private readonly object actual;
+ private readonly bool hasActual;
+
+ public ShouldlyMessage(object expected)
+ {
+ this.expected = expected;
+ }
+
+ public ShouldlyMessage(object expected, object actual)
+ {
+ this.actual = actual;
+ this.expected = expected;
+ hasActual = true;
+ }
+
+
+ public override string ToString()
+ {
+ return hasActual ?
+ GenerateShouldMessage(actual, expected) :
+ GenerateShouldMessage(expected);
+ }
+
+ private static string GenerateShouldMessage(object actual, object expected)
+ {
+ var frame = GetStackFrameForOriginatingTestMethod();
+
+ var shouldMethod = frame.GetMethod().Name;
+ var lineNumber = frame.GetFileLineNumber() - 1;
+ var fileName = frame.GetFileName();
+
+ var codeLines = string.Join("\n",
+ File.ReadAllLines(fileName)
+ .Skip(lineNumber).ToArray());
+
+ var codePart = codeLines.Substring(0, codeLines.IndexOf(shouldMethod) - 1).Trim();
+
+ return string.Format(
+ @"{0}
+ {1}
+ {2}
+ but was
+ {3}",
+ codePart, shouldMethod.PascalToSpaced(), expected.Inspect(), actual.Inspect());
+ }
+
+ private static string GenerateShouldMessage(object expected)
+ {
+ var frame = GetStackFrameForOriginatingTestMethod();
+
+ var shouldMethod = frame.GetMethod().Name;
+ var lineNumber = frame.GetFileLineNumber() - 1;
+ var fileName = frame.GetFileName();
+
+ var codeLines = string.Join("\n",
+ File.ReadAllLines(fileName)
+ .Skip(lineNumber).ToArray());
+
+ var codePart = codeLines.Substring(0, codeLines.IndexOf(shouldMethod) - 1).Trim();
+
+ return string.Format(
+ @"{0}
+ {1}
+ {2}
+ but does not",
+ codePart, shouldMethod.PascalToSpaced(), expected.Inspect());
+ }
+
+ private static StackFrame GetStackFrameForOriginatingTestMethod()
+ {
+ var stackTrace = new StackTrace(true);
+ var i = 0;
+ var frame = stackTrace.GetFrame(i);
+ while (!frame.GetMethod().GetCustomAttributes(typeof(TestAttribute), true).Any())
+ {
+ frame = stackTrace.GetFrame(++i);
+ }
+ return frame;
+ }
+ }
+}
39 src/Shouldly/StringHelpers.cs
@@ -0,0 +1,39 @@
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
+
+namespace Shouldly
+{
+ public static class StringHelpers
+ {
+ public static string Inspect(this object value)
+ {
+ if (value is string)
+ return "\"" + value + "\"";
+
+ if (value is IEnumerable)
+ {
+ var objects = ((IEnumerable)value).Cast<object>();
+ return "[" + objects.Select(o => o.Inspect()).Delimited() + "]";
+ }
+
+ return value == null ? "null" : value.ToString();
+ }
+
+ public static string Delimited<T>(this IEnumerable<T> enumerable, string separator) where T : class
+ {
+ return string.Join(separator, enumerable.Select(i => Equals(i, default(T)) ? null : i.ToString()).ToArray());
+ }
+
+ public static string Delimited<T>(this IEnumerable<T> enumerable) where T : class
+ {
+ return enumerable.Delimited(", ");
+ }
+
+ public static string PascalToSpaced(this string pascal)
+ {
+ return Regex.Replace(pascal, @"([A-Z])", match => " " + match.Value.ToLower()).Trim();
+ }
+ }
+}
36 src/Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+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("Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Tests")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[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("b90cb144-9bb3-4740-8f84-4ea50c0e4575")]
+
+// 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 Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
22 src/Tests/ShouldBeTests.cs
@@ -0,0 +1,22 @@
+using NUnit.Framework;
+using Shouldly;
+
+namespace Tests
+{
+ [TestFixture]
+ public class ShouldBeTests
+ {
+ [Test]
+ public void ShouldBe_WhenTrue_ShouldNotThrow()
+ {
+ true.ShouldBe(true);
+ }
+
+ [Test]
+ public void ShouldBe_WhenFalse_ShouldThrow_WithAwesomeMessage()
+ {
+ Assert.Throws<AssertionException>(() =>
+ "this string".ShouldBe("some other string"));
+ }
+ }
+}
18 src/Tests/ShouldlyMessageTests.cs
@@ -0,0 +1,18 @@
+using NUnit.Framework;
+using Shouldly;
+
+namespace Tests
+{
+ [TestFixture]
+ public class ShouldlyMessageTests
+ {
+ [Test]
+ public void CanGenerateErrorMessage()
+ {
+ new ShouldlyMessage("expected", "actual").ToString()
+ .ShouldBe("Expected expected but was actual");
+
+
+ }
+ }
+}
70 src/Tests/Tests.csproj
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{7E798127-21FE-4F49-A221-53B53B40D6BE}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Tests</RootNamespace>
+ <AssemblyName>Tests</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </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="nunit.framework, Version=2.5.3.9345, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\NUnit-2.5.3.9345\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ShouldBeTests.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="ShouldlyMessageTests.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Shouldly\Shouldly.csproj">
+ <Project>{CF49E8A3-57E1-4F43-B2DC-7092D2B7677F}</Project>
+ <Name>Shouldly</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\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>
Please sign in to comment.
Something went wrong with that request. Please try again.