Commits

Anonymous committed 4c33e7f

initial commit

Comments (0)

Files changed (35)

+# Ignore file for Visual Studio 2008
+# use glob syntax
+syntax: glob
+
+*.orig
+*.dbproj.schemaview
+
+# Ignore Visual Studio 2008 files
+*.suo
+*.sdf
+*.dbmdl
+*.obj
+*.exe
+*.pdb
+*.user
+*.aps
+*.pch
+*.vspscc
+*_i.c
+*_p.c
+*.ncb
+*.suo
+*.tlb
+*.tlh
+*.bak
+*.cache
+*.ilk
+*.log
+*.lib
+*.sbr
+*.scc
+[Bb]in
+[Db]ebug*/
+obj/
+[Rr]elease*/
+_ReSharper*/
+[Tt]est[Rr]esult*
+[Bb]uild[Ll]og.*
+*.[Pp]ublish.xml
+
+[Bb]in\*
+Bin/*
+UpgradeLog.XML
+_UpgradeReoprt*
+
+# Ignore RubyMine files
+.bundle
+.git/*
+db/*.sqlite3*
+log/*.log
+*.log
+.idea/*
+.hg/*
+/tmp/
+tmp/*
+doc/api
+doc/app
+*.swp
+*~
+.DS_Store

Dynamic/CSharpDynamic/CSharpDynamic.sln

+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicFeaturesSamples", "DynamicFeaturesSamples\DynamicFeaturesSamples.csproj", "{DA52FB8C-8B0A-40F4-8BCA-FAB35964ECB7}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicFeaturesSamples.Tests", "DynamicFeaturesSamples.Tests\DynamicFeaturesSamples.Tests.csproj", "{6EC15B18-762F-4AC2-B10B-4B1FD594DFCE}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{DA52FB8C-8B0A-40F4-8BCA-FAB35964ECB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{DA52FB8C-8B0A-40F4-8BCA-FAB35964ECB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{DA52FB8C-8B0A-40F4-8BCA-FAB35964ECB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{DA52FB8C-8B0A-40F4-8BCA-FAB35964ECB7}.Release|Any CPU.Build.0 = Release|Any CPU
+		{6EC15B18-762F-4AC2-B10B-4B1FD594DFCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{6EC15B18-762F-4AC2-B10B-4B1FD594DFCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{6EC15B18-762F-4AC2-B10B-4B1FD594DFCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{6EC15B18-762F-4AC2-B10B-4B1FD594DFCE}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

Dynamic/CSharpDynamic/DynamicFeaturesSamples.Tests/DynamicFeaturesSamples.Tests.csproj

+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{6EC15B18-762F-4AC2-B10B-4B1FD594DFCE}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>DynamicFeaturesSamples.Tests</RootNamespace>
+    <AssemblyName>DynamicFeaturesSamples.Tests</AssemblyName>
+    <TargetFrameworkVersion>v4.0</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="Should">
+      <HintPath>..\packages\Should.1.1.12.0\lib\Should.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+    <Reference Include="xunit">
+      <HintPath>..\packages\xunit.1.8.0.1549\lib\xunit.dll</HintPath>
+    </Reference>
+    <Reference Include="xunit.extensions">
+      <HintPath>..\packages\xunit.extensions.1.8.0.1549\lib\xunit.extensions.dll</HintPath>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Dynamic_customer_tests.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="SubSpec\SubSpec.cs" />
+    <Compile Include="SubSpec\SubSpec.Thesis.cs" />
+    <Compile Include="SubSpec\SubSpecUtils.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\DynamicFeaturesSamples\DynamicFeaturesSamples.csproj">
+      <Project>{DA52FB8C-8B0A-40F4-8BCA-FAB35964ECB7}</Project>
+      <Name>DynamicFeaturesSamples</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="SubSpec\LICENSE.txt" />
+  </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>

Dynamic/CSharpDynamic/DynamicFeaturesSamples.Tests/Dynamic_customer_tests.cs

+using System.Collections.Generic;
+using Should;
+using SubSpec;
+
+namespace DynamicFeaturesSamples.Tests
+{
+    public class Dynamic_customer_tests
+    {
+        dynamic _customer;
+        Dictionary<string, object> _additionalData = new Dictionary<string, object>();
+
+        [Specification]
+        public void dynamic_properties()
+        {
+            "Given additional dynamic data for a customer"
+                .Context(() => make_data_for_a_customer());
+            "When constructing a customer object"
+                .Do(() => { _customer = GetCustomer(); });
+            "Then the object should expose the additional data as properties"
+                .Assert(properties_are_exposed);
+            " And getters are available"
+                .Assert(getters_are_exposed);
+            " And setters are available"
+                .Assert(setters_are_exposed);
+        }
+
+        void make_data_for_a_customer()
+        {
+            _additionalData.Clear();
+            _additionalData.Add("Comments", "Some comments...");    
+            _additionalData.Add("NumberOfDependents", 3);
+        }
+
+        Customer GetCustomer()
+        {
+            return new Customer(_additionalData);
+        }
+
+        void properties_are_exposed()
+        {
+            (_customer as DynamicEntity).RespondTo("Comments").ShouldBeTrue();
+            (_customer as DynamicEntity).RespondTo("NumberOfDependents").ShouldBeTrue();
+        }
+
+        void getters_are_exposed()
+        {
+            ((string) _customer.Comments).ShouldEqual("Some comments...");
+            ((int) _customer.NumberOfDependents).ShouldEqual(3);
+        }
+
+        void setters_are_exposed()
+        {
+            _customer.Comments = "New comments";
+            _customer.NumberOfDependents = 9;
+
+            ((string)_customer.Comments).ShouldEqual("New comments");
+            ((int)_customer.NumberOfDependents).ShouldEqual(9);
+        }
+    }
+}

Dynamic/CSharpDynamic/DynamicFeaturesSamples.Tests/Properties/AssemblyInfo.cs

+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("DynamicFeaturesSamples.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("DynamicFeaturesSamples.Tests")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[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("901911f8-5413-45e9-9ba3-61aaf77ec5af")]
+
+// 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")]

Dynamic/CSharpDynamic/DynamicFeaturesSamples.Tests/SubSpec/LICENSE.txt

+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
+
+1. Definitions
+
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+
+A "contributor" is any person that distributes its contribution under this license.
+
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
+
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
+
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
+
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

Dynamic/CSharpDynamic/DynamicFeaturesSamples.Tests/SubSpec/SubSpec.Thesis.cs

+using System;
+using System.Collections.Generic;
+using Xunit.Sdk;
+using Xunit.Extensions;
+
+namespace SubSpec
+{
+    [AttributeUsage( AttributeTargets.Method, AllowMultiple = false, Inherited = true )]
+    public class ThesisAttribute : TheoryAttribute
+    {
+        protected override IEnumerable<ITestCommand> EnumerateTestCommands( IMethodInfo method )
+        {
+            // prepare specification invocations  
+            var theoryTestCommands = base.EnumerateTestCommands( method );
+
+            var commands = new List<ITestCommand>();
+
+            foreach (var item in theoryTestCommands)
+            {
+                if (item is TheoryCommand)
+                {
+                    commands.AddRange( SubSpec.Core.SpecificationContext.SafelyEnumerateTestCommands( method,
+                        m =>
+                        {
+                            // Create a new test class instance
+                            object obj = item.ShouldCreateInstance ? Activator.CreateInstance( method.MethodInfo.ReflectedType ) : null;
+                            
+                            // create method
+                            item.Execute( obj );
+                        } ) );
+
+                }
+                else
+                {
+                    commands.Clear();
+                    commands.Add( item );
+                    break;
+                }
+            }
+
+            return commands;
+        }
+    }
+}

Dynamic/CSharpDynamic/DynamicFeaturesSamples.Tests/SubSpec/SubSpec.cs

+using System;
+using System.Collections.Generic;
+using System.Text;
+using Xunit;
+using Xunit.Sdk;
+using System.Xml;
+using System.Diagnostics;
+using System.Reflection;
+using System.Linq;
+
+namespace SubSpec
+{
+    /// <remarks>
+    /// We declare our own delegate instead of using Func 
+    /// because we can't use implicit covariance on the generic type parameter in .net 3.5"/>
+    /// </remarks>
+    public delegate IDisposable ContextDelegate();
+
+    public class DisposableAction : IDisposable
+    {
+        public static readonly DisposableAction None = new DisposableAction( () => { } );
+
+        private readonly Action _action;
+
+        public DisposableAction( Action action )
+        {
+            if (action == null)
+                throw new ArgumentNullException( "action" );
+
+            _action = action;
+        }
+
+        public void Dispose()
+        {
+            _action();
+        }
+    }
+
+    public interface ISpecificationPrimitive
+    {
+        /// <summary>
+        /// Indicate that execution of this delegate should be canceled after a specified timeout.
+        /// </summary>
+        /// <param name="timeoutMs">The timeout in milliseconds.</param>
+        ISpecificationPrimitive WithTimeout( int timeoutMs );
+    }
+
+    internal static class Core
+    {
+        private class SpecificationPrimitive<T> : ISpecificationPrimitive
+        {
+            private readonly string _message;
+            private readonly T _action;
+            private int _timeoutMs;
+
+            /// <summary>
+            /// Initializes a new instance of the Context class.
+            /// </summary>
+            /// <param name="message"></param>
+            /// <param name="action"></param>
+            public SpecificationPrimitive( string message, T action )
+            {
+                if (message == null)
+                    throw new ArgumentNullException( "message" );
+                if (action == null)
+                    throw new ArgumentNullException( "action" );
+
+                _message = message;
+                _action = action;
+            }
+
+            public string Message
+            {
+                get { return _message; }
+            }
+            public T ActionDelegate
+            {
+                get { return _action; }
+            }
+            public int TimeoutMs
+            {
+                get { return _timeoutMs; }
+            }
+
+            public ISpecificationPrimitive WithTimeout( int timeoutMs )
+            {
+                _timeoutMs = timeoutMs;
+                return this;
+            }
+        }
+
+        private static class SpecificationPrimitiveExecutor
+        {
+            public static void Execute( SpecificationPrimitive<Action> primitive )
+            {
+                Debug.Assert( primitive.ActionDelegate != null );
+
+                if (primitive.TimeoutMs > 0)
+                {
+#if SILVERLIGHT
+                IAsyncResult asyncResult = AsyncDelegatesCompatibility.WorkingBeginInvoke( primitive.ActionDelegate, null, null );
+#else
+                    IAsyncResult asyncResult = primitive.ActionDelegate.BeginInvoke( null, null );
+#endif
+
+                    if (!asyncResult.AsyncWaitHandle.WaitOne( primitive.TimeoutMs ))
+                        throw new Xunit.Sdk.TimeoutException( primitive.TimeoutMs );
+                    else
+                    {
+#if SILVERLIGHT
+                    primitive.ActionDelegate.WorkingEndInvoke( asyncResult );
+#else
+                        primitive.ActionDelegate.EndInvoke( asyncResult );
+#endif
+
+                    }
+                }
+                else
+                    primitive.ActionDelegate();
+            }
+
+            public static IDisposable Execute( SpecificationPrimitive<ContextDelegate> primitive )
+            {
+                Debug.Assert( primitive.ActionDelegate != null );
+
+                if (primitive.TimeoutMs > 0)
+                {
+#if SILVERLIGHT
+                IAsyncResult asyncResult = AsyncDelegatesCompatibility.WorkingBeginInvoke( primitive.ActionDelegate, null, null );
+#else
+                    IAsyncResult asyncResult = primitive.ActionDelegate.BeginInvoke( null, null );
+#endif
+
+                    if (!asyncResult.AsyncWaitHandle.WaitOne( primitive.TimeoutMs ))
+                        throw new Xunit.Sdk.TimeoutException( primitive.TimeoutMs );
+                    else
+                    {
+#if SILVERLIGHT
+                    return (IDisposable)primitive.ActionDelegate.WorkingEndInvoke( asyncResult );
+#else
+                        return primitive.ActionDelegate.EndInvoke( asyncResult );
+#endif
+
+                    }
+                }
+                else
+                    return primitive.ActionDelegate();
+            }
+        }
+
+        private class ActionTestCommand : TestCommand, ITestCommand
+        {
+            private readonly Action _action;
+
+            public ActionTestCommand( IMethodInfo method, string name, int timeout, Action action )
+                : base( method, name, timeout )
+            {
+                _action = action;
+            }
+
+            public override MethodResult Execute( object testClass )
+            {
+                try
+                {
+                    _action();
+                    return new PassedResult( testMethod, DisplayName );
+                }
+                catch (Exception ex)
+                {
+                    return new FailedResult( testMethod, ex, DisplayName );
+                }
+            }
+        }
+
+        private class ExceptionTestCommand : ActionTestCommand
+        {
+            public ExceptionTestCommand( IMethodInfo method, Xunit.Assert.ThrowsDelegate action )
+                : base( method, null, 0, () => action() )
+            {
+            }
+
+            public override bool ShouldCreateInstance
+            {
+                get { return false; }
+            }
+        }
+
+        private class AssertExecutor
+        {
+            private readonly List<SpecificationPrimitive<Action>> _asserts;
+            private readonly SpecificationPrimitive<ContextDelegate> _context;
+            private readonly SpecificationPrimitive<Action> _do;
+
+            public AssertExecutor( SpecificationPrimitive<ContextDelegate> context, SpecificationPrimitive<Action> @do, List<SpecificationPrimitive<Action>> asserts )
+            {
+                _asserts = asserts;
+                _context = context;
+                _do = @do;
+            }
+
+            public IEnumerable<ITestCommand> AssertCommands( string name, IMethodInfo method )
+            {
+                foreach (var assertion in _asserts)
+                {
+                    // do not capture the iteration variable because 
+                    // all tests would point to the same assertion
+                    var capturableAssertion = assertion;
+                    Action test =
+                        () =>
+                        {
+                            using (SpecificationPrimitiveExecutor.Execute( _context ))
+                            {
+                                if (_do != null)
+                                    SpecificationPrimitiveExecutor.Execute( _do );
+
+                                SpecificationPrimitiveExecutor.Execute( capturableAssertion );
+                            }
+                        };
+
+                    string testDescription = String.Format( "{0}, {1}", name, assertion.Message );
+
+                    yield return new ActionTestCommand( method, testDescription, MethodUtility.GetTimeoutParameter( method ), test );
+                }
+            }
+        }
+
+        private class ObservationExecutor
+        {
+            private readonly IEnumerable<SpecificationPrimitive<Action>> _observations;
+            private readonly SpecificationPrimitive<ContextDelegate> _context;
+            private readonly SpecificationPrimitive<Action> _do;
+
+            public ObservationExecutor( SpecificationPrimitive<ContextDelegate> context, SpecificationPrimitive<Action> @do, IEnumerable<SpecificationPrimitive<Action>> observations )
+            {
+                _observations = observations;
+                _context = context;
+                _do = @do;
+            }
+
+            public IEnumerable<ITestCommand> ObservationCommands( string name, IMethodInfo method )
+            {
+                if (_observations.Count() == 0)
+                    yield break;
+
+                bool setupExceptionOccurred = false;
+                IDisposable systemUnderTest = default( IDisposable );
+
+                Action setupAction = () =>
+                {
+                    try
+                    {
+                        systemUnderTest = SpecificationPrimitiveExecutor.Execute( _context );
+
+                        if (_do != null)
+                            SpecificationPrimitiveExecutor.Execute( _do );
+                    }
+                    catch (Exception)
+                    {
+                        setupExceptionOccurred = true;
+                        throw;
+                    }
+                };
+
+                yield return new ActionTestCommand( method, "{ " + name, 0, setupAction );
+
+                foreach (var observation in _observations)
+                {
+                    // do not capture the iteration variable because 
+                    // all tests would point to the same observation
+                    var capturableObservation = observation;
+                    Action perform = () =>
+                    {
+                        if (setupExceptionOccurred)
+                            throw new ContextSetupFailedException( "Setting up Context failed" );
+
+                        SpecificationPrimitiveExecutor.Execute( capturableObservation );
+                    };
+
+                    yield return new ActionTestCommand( method, "\t- " + capturableObservation.Message, 0, perform );
+                }
+
+                Action tearDownAction = () =>
+                {
+                    if (systemUnderTest != null)
+                        systemUnderTest.Dispose();
+
+                    if (setupExceptionOccurred)
+                        throw new ContextSetupFailedException( "Setting up Context failed, but Fixtures were disposed." );
+                };
+
+                yield return new ActionTestCommand( method, "} " + name, 0, tearDownAction );
+            }
+        }
+
+        /// <summary>
+        /// An exception that is thrown from Observations or their teardown whenever the corresponding setup failed.
+        /// </summary>
+        private class ContextSetupFailedException : Exception
+        {
+            public ContextSetupFailedException( string message ) : base( message ) { }
+        }
+
+        internal static class SpecificationContext
+        {
+            [ThreadStatic]
+            private static bool _threadStaticInitialized;
+            [ThreadStatic]
+            private static SpecificationPrimitive<ContextDelegate> _context;
+            [ThreadStatic]
+            private static SpecificationPrimitive<Action> _do;
+            [ThreadStatic]
+            private static List<SpecificationPrimitive<Action>> _asserts;
+            [ThreadStatic]
+            private static List<SpecificationPrimitive<Action>> _observations;
+            [ThreadStatic]
+            private static List<SpecificationPrimitive<Action>> _skips;
+            [ThreadStatic]
+            private static List<Action> _exceptions;
+
+            private static void Reset()
+            {
+                _exceptions = new List<Action>();
+                _context = null;
+                _do = null;
+                _asserts = new List<SpecificationPrimitive<Action>>();
+                _observations = new List<SpecificationPrimitive<Action>>();
+                _skips = new List<SpecificationPrimitive<Action>>();
+            }
+
+            private static void EnsureThreadStaticInitialized()
+            {
+                if (_threadStaticInitialized)
+                    return;
+
+                Reset();
+                _threadStaticInitialized = true;
+            }
+
+            public static ISpecificationPrimitive Context( string message, ContextDelegate arrange )
+            {
+                EnsureThreadStaticInitialized();
+
+                if (_context == null)
+                    _context = new SpecificationPrimitive<ContextDelegate>( message, arrange );
+                else
+                    _exceptions.Add( () => { throw new InvalidOperationException( "Cannot have more than one Context statement in a specification" ); } );
+
+                return _context;
+            }
+
+            public static ISpecificationPrimitive Do( string message, Action doAction )
+            {
+                EnsureThreadStaticInitialized();
+
+                if (_do == null)
+                    _do = new SpecificationPrimitive<Action>( message, doAction );
+                else
+                    _exceptions.Add( () => { throw new InvalidOperationException( "Cannot have more than one Do statement in a specification" ); } );
+
+                return _do;
+            }
+
+            public static ISpecificationPrimitive Assert( string message, Action assertAction )
+            {
+                EnsureThreadStaticInitialized();
+
+                SpecificationPrimitive<Action> assert = new SpecificationPrimitive<Action>( message, assertAction );
+                _asserts.Add( assert );
+
+                return assert;
+            }
+
+            public static ISpecificationPrimitive Observation( string message, Action observationAction )
+            {
+                EnsureThreadStaticInitialized();
+
+                var observation = new SpecificationPrimitive<Action>( message, observationAction );
+                _observations.Add( observation );
+
+                return observation;
+            }
+
+            public static ISpecificationPrimitive Todo( string message, Action skippedAction )
+            {
+                EnsureThreadStaticInitialized();
+
+                SpecificationPrimitive<Action> skip = new SpecificationPrimitive<Action>( message, skippedAction );
+                _skips.Add( skip );
+
+                return skip;
+            }
+
+            private static string PrepareSetupDescription()
+            {
+                string name = _context.Message;
+
+                if (_do != null)
+                    name += " " + _do.Message;
+                return name;
+            }
+
+            public static IEnumerable<ITestCommand> SafelyEnumerateTestCommands( IMethodInfo method, Action<IMethodInfo> registerPrimitives )
+            {
+                try
+                {
+                    registerPrimitives( method );
+
+                    IEnumerable<ITestCommand> testCommands = SpecificationContext.BuildCommandsFromRegisteredPrimitives( method );
+
+                    return testCommands;
+                }
+                catch (Exception ex)
+                {
+                    return new ITestCommand[] {
+                        new SubSpec.Core.ExceptionTestCommand(method, () =>
+                          {
+                                              		throw new InvalidOperationException(string.Format("An exception was thrown while building tests from Specification {0}.{1}:\r\n" + ex.ToString(), 
+                                                                                            method.TypeName, 
+                                                                                            method.Name));
+                                              })};
+                }
+            }
+
+            private static IEnumerable<ITestCommand> BuildCommandsFromRegisteredPrimitives( IMethodInfo method )
+            {
+                EnsureThreadStaticInitialized();
+
+                try
+                {
+                    var validationException = ValidateSpecification( method );
+                    if (validationException != null)
+                    {
+                        yield return validationException;
+                        yield break;
+                    }
+
+                    int testsReturned = 0;
+                    string name = PrepareSetupDescription();
+
+                    var ax = new AssertExecutor( _context, _do, _asserts );
+                    foreach (var item in ax.AssertCommands( name, method ))
+                    {
+                        yield return item;
+                        testsReturned++;
+                    }
+
+                    var ox = new ObservationExecutor( _context, _do, _observations );
+                    foreach (var item in ox.ObservationCommands( name, method ))
+                    {
+                        yield return item;
+                        testsReturned++;
+                    }
+                                                                                                                                     
+                    foreach (var item in SkipCommands( name, method ))
+                    {
+                        yield return item;
+                        testsReturned++;
+                    }
+
+                    if (testsReturned == 0)
+                        yield return new ExceptionTestCommand( method, () => { throw new InvalidOperationException( "Must have at least one Assert or Observation in each specification" ); } );
+                }
+                finally
+                {
+                    Reset();
+                }
+            }
+
+            private static ExceptionTestCommand ValidateSpecification( IMethodInfo method )
+            {
+                if (_context == null)
+                    _exceptions.Add( () => { throw new InvalidOperationException( "Must have a Context in each specification" ); } );
+
+                // check if we have any recorded exceptions
+                if (_exceptions.Count > 0)
+                {
+                    // throw the first recorded exception, preserves stacktraces nicely.
+                    return new ExceptionTestCommand( method, () => _exceptions[0]() );
+                }
+
+                return null;
+            }
+
+            private static IEnumerable<ITestCommand> SkipCommands( string name, IMethodInfo method )
+            {
+                foreach (var kvp in _skips)
+                    yield return new SkipCommand( method, name + ", " + kvp.Message, "Action is Todo (instead of Observation or Assert)" );
+            }
+        }
+    }
+
+    [AttributeUsage( AttributeTargets.Method, AllowMultiple = false, Inherited = true )]
+    public class SpecificationAttribute : FactAttribute
+    {
+        protected override IEnumerable<ITestCommand> EnumerateTestCommands( IMethodInfo method )
+        {
+            return SubSpec.Core.SpecificationContext.SafelyEnumerateTestCommands( method, RegisterSpecificationPrimitives);
+        }
+
+        public static IEnumerable<ITestCommand> FtoEnumerateTestCommands( IMethodInfo method )
+        {
+            return SubSpec.Core.SpecificationContext.SafelyEnumerateTestCommands( method, RegisterSpecificationPrimitives );
+        }
+
+        private static void RegisterSpecificationPrimitives( IMethodInfo method )
+        {
+            if (method.IsStatic)
+                method.Invoke( null, null );
+            else
+            {
+                ConstructorInfo defaultConstructor = method.MethodInfo.ReflectedType.GetConstructor( Type.EmptyTypes );
+
+                if (defaultConstructor == null)
+                    throw new InvalidOperationException( "Specification class does not have a default constructor" );
+
+                object instance = defaultConstructor.Invoke( null );
+                method.Invoke( instance, null );
+            }
+        }
+    }
+
+    /// <summary>
+    /// Provides extensions for a fluent specification syntax
+    /// </summary>
+    public static class SpecificationExtensions
+    {
+        private const string IDisposableHintMessaage = "Your context implements IDisposable. Use ContextFixture() to have its lifecycle managed by SubSpec.";
+
+        /// <summary>
+        /// Records a context setup for this specification.
+        /// </summary>
+        /// <param name="message">A message describing the established context.</param>
+        /// <param name="arrange">The action that will establish the context.</param>
+        public static ISpecificationPrimitive Context( this string message, Action arrange )
+        {
+            return SubSpec.Core.SpecificationContext.Context( message,
+                                          () =>
+                                          {
+                                              arrange();
+                                              return DisposableAction.None;
+                                          } );
+        }
+
+        /// <summary>
+        /// Trap for using contexts implementing IDisposable with the wrong overload.
+        /// </summary>
+        /// <param name="message">A message describing the established context.</param>
+        /// <param name="arrange">The action that will establish and return the context for this test.</param>
+        [Obsolete( IDisposableHintMessaage )]
+        public static void Context( this string message, ContextDelegate arrange )
+        {
+            throw new InvalidOperationException( IDisposableHintMessaage );
+        }
+
+        /// <summary>
+        /// Records a disposable context for this specification. The context lifecycle will be managed by SubSpec.
+        /// </summary>
+        /// <param name="message">A message describing the established context.</param>
+        /// <param name="arrange">The action that will establish and return the context for this test.</param>
+        public static ISpecificationPrimitive ContextFixture( this string message, ContextDelegate arrange )
+        {
+            return SubSpec.Core.SpecificationContext.Context( message, arrange );
+        }
+
+        /// <summary>
+        /// Records an action to be performed on the context for this specification.
+        /// </summary>
+        /// <param name="message">A message describing the action.</param>
+        /// <param name="arrange">The action to perform.</param>
+        public static ISpecificationPrimitive Do( this string message, Action act )
+        {
+            return SubSpec.Core.SpecificationContext.Do( message, act );
+        }
+
+        /// <summary>
+        /// Records an assertion for this specification.
+        /// Each assertion is executed on an isolated context.
+        /// </summary>
+        /// <param name="message">A message describing the expected result.</param>
+        /// <param name="assert">The action that will verify the expectation.</param>
+        public static ISpecificationPrimitive Assert( this string message, Action assert )
+        {
+            return SubSpec.Core.SpecificationContext.Assert( message, assert );
+        }
+
+        /// <summary>
+        /// Records an observation for this specification.
+        /// All observations are executed on the same context.
+        /// </summary>
+        /// <param name="message">A message describing the expected result.</param>
+        /// <param name="observation">The action that will verify the expectation.</param>
+        public static ISpecificationPrimitive Observation( this string message, Action observation )
+        {
+            return SubSpec.Core.SpecificationContext.Observation( message, observation );
+        }
+
+        /// <summary>
+        /// Records a skipped assertion for this specification.
+        /// </summary>
+        /// <param name="message">A message describing the expected result.</param>
+        /// <param name="skippedAction">The action that will verify the expectation.</param>
+        public static ISpecificationPrimitive Todo( this string message, Action skippedAction )
+        {
+            return SubSpec.Core.SpecificationContext.Todo( message, skippedAction );
+        }
+    }
+}

Dynamic/CSharpDynamic/DynamicFeaturesSamples.Tests/SubSpec/SubSpecUtils.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Collections;
+using System.Collections.ObjectModel;
+
+namespace SubSpec
+{
+    internal abstract class TheoryDataProvider : IEnumerable<object[]>
+    {
+        public IEnumerator<object[]> GetEnumerator()
+        {
+            return DataSource().GetEnumerator();
+        }
+
+        IEnumerator IEnumerable.GetEnumerator()
+        {
+            return DataSource().GetEnumerator();
+        }
+
+        protected abstract IEnumerable<object[]> DataSource();
+    }
+
+    internal abstract class SingleItemTheoryDataProvider : TheoryDataProvider
+    {
+        protected override sealed IEnumerable<object[]> DataSource()
+        {
+            return SingleItemDataSource().Select( x => new[] { x } );
+        }
+
+        protected abstract IEnumerable<object> SingleItemDataSource();
+    }
+
+    /// <summary>
+    /// Use this class in conjunction with ContextFixture() method to return a disposable object containing a list of all 
+    /// objects that need to be disposed that were created within your ContextFixture. 
+    /// </summary>
+    internal class CompositeFixture : List<IDisposable>, IDisposable
+    {
+        /// <summary>
+        /// Disposes all registered items in reversed order than items have been added.
+        /// </summary>
+        public void Dispose()
+        {
+            var _exceptions = new List<Exception>();
+            foreach (var disposable in Enumerable.Reverse( this ))
+                try
+                {
+                    disposable.Dispose();
+                }
+                catch (Exception exception)
+                {
+                    _exceptions.Add( exception );
+                }
+
+            // Always throw AggregateException, prevents stack trace loss without us having
+            // to resort on reflection hacks to preserve stack traces.
+            if (_exceptions.Count > 0)
+                throw new AggregateException( _exceptions );
+        }
+
+        // Nested as want to use one in TPL when on FX4
+        internal class AggregateException : Exception
+        {
+            public AggregateException( IEnumerable<Exception> exceptions )
+            {
+                InnerExceptions = new ReadOnlyCollection<Exception>( exceptions.ToList() );
+            }
+
+            public ReadOnlyCollection<Exception> InnerExceptions { get; private set; }
+
+            public override string ToString()
+            {
+                string splitter = Environment.NewLine + "\t";
+                return "AggregateException:" + splitter + string.Join( splitter, InnerExceptions.Select( _ => _.ToString() ).ToArray() );
+            }
+        }
+    }
+}

Dynamic/CSharpDynamic/DynamicFeaturesSamples.Tests/packages.config

+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Should" version="1.1.12.0" />
+  <package id="SubSpec" version="1.8.0.0" />
+  <package id="xunit" version="1.8.0.1549" />
+  <package id="xunit.extensions" version="1.8.0.1549" />
+</packages>

Dynamic/CSharpDynamic/DynamicFeaturesSamples/Customer.cs

+using System.Collections.Generic;
+
+namespace DynamicFeaturesSamples
+{
+    public class Customer : DynamicEntity
+    {
+        public Customer(IEnumerable<KeyValuePair<string, object>> additionalData) : base(additionalData)
+        {
+        }
+
+        public string FirstName { get; set; }
+        public string LastName { get; set; }
+    }
+}

Dynamic/CSharpDynamic/DynamicFeaturesSamples/DynamicEntity.cs

+using System.Collections.Generic;
+using System.Dynamic;
+
+namespace DynamicFeaturesSamples
+{
+    public class DynamicEntity : DynamicObject
+    {
+        Dictionary<string, object> _additionalData = new Dictionary<string, object>();
+
+        public DynamicEntity(IEnumerable<KeyValuePair<string, object>> additionalData)
+        {
+            foreach (var keyValuePair in additionalData)
+            {
+                _additionalData.Add(keyValuePair.Key, keyValuePair.Value);
+            }
+        }
+
+        public override bool TryGetMember(GetMemberBinder binder, out object result)
+        {
+            if (_additionalData.ContainsKey(binder.Name))
+            {
+                result = _additionalData[binder.Name];
+                return true;
+            }
+            return base.TryGetMember(binder, out result);
+        }
+
+        public override bool TrySetMember(SetMemberBinder binder, object value)
+        {
+            if (_additionalData.ContainsKey(binder.Name))
+            {
+                _additionalData[binder.Name] = value;
+                return true;
+            }
+
+            return base.TrySetMember(binder, value);
+        }
+
+        public bool RespondTo(string message)
+        {
+            return _additionalData.ContainsKey(message);
+        }
+    }
+}

Dynamic/CSharpDynamic/DynamicFeaturesSamples/DynamicFeaturesSamples.csproj

+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{DA52FB8C-8B0A-40F4-8BCA-FAB35964ECB7}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>DynamicFeaturesSamples</RootNamespace>
+    <AssemblyName>DynamicFeaturesSamples</AssemblyName>
+    <TargetFrameworkVersion>v4.0</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="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Customer.cs" />
+    <Compile Include="DynamicEntity.cs" />
+    <Compile Include="Properties\AssemblyInfo.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>

Dynamic/CSharpDynamic/DynamicFeaturesSamples/Properties/AssemblyInfo.cs

+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("DynamicFeaturesSamples")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("DynamicFeaturesSamples")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[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("a6ce196b-b856-4605-b7cf-b9fb3998371d")]
+
+// 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")]

Dynamic/CSharpDynamic/packages/Should.1.1.12.0/Should.1.1.12.0.nupkg

Binary file added.

Dynamic/CSharpDynamic/packages/Should.1.1.12.0/lib/Should.dll

Binary file added.

Dynamic/CSharpDynamic/packages/SubSpec.1.8.0.0/SubSpec.1.8.0.0.nupkg

Binary file added.

Dynamic/CSharpDynamic/packages/SubSpec.1.8.0.0/content/SubSpec/LICENSE.txt

+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
+
+1. Definitions
+
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+
+A "contributor" is any person that distributes its contribution under this license.
+
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+
+3. Conditions and Limitations
+
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
+
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
+
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
+
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

Dynamic/CSharpDynamic/packages/SubSpec.1.8.0.0/content/SubSpec/SubSpec.Thesis.cs

+using System;
+using System.Collections.Generic;
+using Xunit.Sdk;
+using Xunit.Extensions;
+
+namespace SubSpec
+{
+    [AttributeUsage( AttributeTargets.Method, AllowMultiple = false, Inherited = true )]
+    public class ThesisAttribute : TheoryAttribute
+    {
+        protected override IEnumerable<ITestCommand> EnumerateTestCommands( IMethodInfo method )
+        {
+            // prepare specification invocations  
+            var theoryTestCommands = base.EnumerateTestCommands( method );
+
+            var commands = new List<ITestCommand>();
+
+            foreach (var item in theoryTestCommands)
+            {
+                if (item is TheoryCommand)
+                {
+                    commands.AddRange( SubSpec.Core.SpecificationContext.SafelyEnumerateTestCommands( method,
+                        m =>
+                        {
+                            // Create a new test class instance
+                            object obj = item.ShouldCreateInstance ? Activator.CreateInstance( method.MethodInfo.ReflectedType ) : null;
+                            
+                            // create method
+                            item.Execute( obj );
+                        } ) );
+
+                }
+                else
+                {
+                    commands.Clear();
+                    commands.Add( item );
+                    break;
+                }
+            }
+
+            return commands;
+        }
+    }
+}

Dynamic/CSharpDynamic/packages/SubSpec.1.8.0.0/content/SubSpec/SubSpec.cs

+using System;
+using System.Collections.Generic;
+using System.Text;
+using Xunit;
+using Xunit.Sdk;
+using System.Xml;
+using System.Diagnostics;
+using System.Reflection;
+using System.Linq;
+
+namespace SubSpec
+{
+    /// <remarks>
+    /// We declare our own delegate instead of using Func 
+    /// because we can't use implicit covariance on the generic type parameter in .net 3.5"/>
+    /// </remarks>
+    public delegate IDisposable ContextDelegate();
+
+    public class DisposableAction : IDisposable
+    {
+        public static readonly DisposableAction None = new DisposableAction( () => { } );
+
+        private readonly Action _action;
+
+        public DisposableAction( Action action )
+        {
+            if (action == null)
+                throw new ArgumentNullException( "action" );
+
+            _action = action;
+        }
+
+        public void Dispose()
+        {
+            _action();
+        }
+    }
+
+    public interface ISpecificationPrimitive
+    {
+        /// <summary>
+        /// Indicate that execution of this delegate should be canceled after a specified timeout.
+        /// </summary>
+        /// <param name="timeoutMs">The timeout in milliseconds.</param>
+        ISpecificationPrimitive WithTimeout( int timeoutMs );
+    }
+
+    internal static class Core
+    {
+        private class SpecificationPrimitive<T> : ISpecificationPrimitive
+        {
+            private readonly string _message;
+            private readonly T _action;
+            private int _timeoutMs;
+
+            /// <summary>
+            /// Initializes a new instance of the Context class.
+            /// </summary>
+            /// <param name="message"></param>
+            /// <param name="action"></param>
+            public SpecificationPrimitive( string message, T action )
+            {
+                if (message == null)
+                    throw new ArgumentNullException( "message" );
+                if (action == null)
+                    throw new ArgumentNullException( "action" );
+
+                _message = message;
+                _action = action;
+            }
+
+            public string Message
+            {
+                get { return _message; }
+            }
+            public T ActionDelegate
+            {
+                get { return _action; }
+            }
+            public int TimeoutMs
+            {
+                get { return _timeoutMs; }
+            }
+
+            public ISpecificationPrimitive WithTimeout( int timeoutMs )
+            {
+                _timeoutMs = timeoutMs;
+                return this;
+            }
+        }
+
+        private static class SpecificationPrimitiveExecutor
+        {
+            public static void Execute( SpecificationPrimitive<Action> primitive )
+            {
+                Debug.Assert( primitive.ActionDelegate != null );
+
+                if (primitive.TimeoutMs > 0)
+                {
+#if SILVERLIGHT
+                IAsyncResult asyncResult = AsyncDelegatesCompatibility.WorkingBeginInvoke( primitive.ActionDelegate, null, null );
+#else
+                    IAsyncResult asyncResult = primitive.ActionDelegate.BeginInvoke( null, null );
+#endif
+
+                    if (!asyncResult.AsyncWaitHandle.WaitOne( primitive.TimeoutMs ))
+                        throw new Xunit.Sdk.TimeoutException( primitive.TimeoutMs );
+                    else
+                    {
+#if SILVERLIGHT
+                    primitive.ActionDelegate.WorkingEndInvoke( asyncResult );
+#else
+                        primitive.ActionDelegate.EndInvoke( asyncResult );
+#endif
+
+                    }
+                }
+                else
+                    primitive.ActionDelegate();
+            }
+
+            public static IDisposable Execute( SpecificationPrimitive<ContextDelegate> primitive )
+            {
+                Debug.Assert( primitive.ActionDelegate != null );
+
+                if (primitive.TimeoutMs > 0)
+                {
+#if SILVERLIGHT
+                IAsyncResult asyncResult = AsyncDelegatesCompatibility.WorkingBeginInvoke( primitive.ActionDelegate, null, null );
+#else
+                    IAsyncResult asyncResult = primitive.ActionDelegate.BeginInvoke( null, null );
+#endif
+
+                    if (!asyncResult.AsyncWaitHandle.WaitOne( primitive.TimeoutMs ))
+                        throw new Xunit.Sdk.TimeoutException( primitive.TimeoutMs );
+                    else
+                    {
+#if SILVERLIGHT
+                    return (IDisposable)primitive.ActionDelegate.WorkingEndInvoke( asyncResult );
+#else
+                        return primitive.ActionDelegate.EndInvoke( asyncResult );
+#endif
+
+                    }
+                }
+                else
+                    return primitive.ActionDelegate();
+            }
+        }
+
+        private class ActionTestCommand : TestCommand, ITestCommand
+        {
+            private readonly Action _action;
+
+            public ActionTestCommand( IMethodInfo method, string name, int timeout, Action action )
+                : base( method, name, timeout )
+            {
+                _action = action;
+            }
+
+            public override MethodResult Execute( object testClass )
+            {
+                try
+                {
+                    _action();
+                    return new PassedResult( testMethod, DisplayName );
+                }
+                catch (Exception ex)
+                {
+                    return new FailedResult( testMethod, ex, DisplayName );
+                }
+            }
+        }
+
+        private class ExceptionTestCommand : ActionTestCommand
+        {
+            public ExceptionTestCommand( IMethodInfo method, Xunit.Assert.ThrowsDelegate action )
+                : base( method, null, 0, () => action() )
+            {
+            }
+
+            public override bool ShouldCreateInstance
+            {
+                get { return false; }
+            }
+        }
+
+        private class AssertExecutor
+        {
+            private readonly List<SpecificationPrimitive<Action>> _asserts;
+            private readonly SpecificationPrimitive<ContextDelegate> _context;
+            private readonly SpecificationPrimitive<Action> _do;
+
+            public AssertExecutor( SpecificationPrimitive<ContextDelegate> context, SpecificationPrimitive<Action> @do, List<SpecificationPrimitive<Action>> asserts )
+            {
+                _asserts = asserts;
+                _context = context;
+                _do = @do;
+            }
+
+            public IEnumerable<ITestCommand> AssertCommands( string name, IMethodInfo method )
+            {
+                foreach (var assertion in _asserts)
+                {
+                    // do not capture the iteration variable because 
+                    // all tests would point to the same assertion
+                    var capturableAssertion = assertion;
+                    Action test =
+                        () =>
+                        {
+                            using (SpecificationPrimitiveExecutor.Execute( _context ))
+                            {
+                                if (_do != null)
+                                    SpecificationPrimitiveExecutor.Execute( _do );
+
+                                SpecificationPrimitiveExecutor.Execute( capturableAssertion );
+                            }
+                        };
+
+                    string testDescription = String.Format( "{0}, {1}", name, assertion.Message );
+
+                    yield return new ActionTestCommand( method, testDescription, MethodUtility.GetTimeoutParameter( method ), test );
+                }
+            }
+        }
+
+        private class ObservationExecutor
+        {
+            private readonly IEnumerable<SpecificationPrimitive<Action>> _observations;
+            private readonly SpecificationPrimitive<ContextDelegate> _context;
+            private readonly SpecificationPrimitive<Action> _do;
+
+            public ObservationExecutor( SpecificationPrimitive<ContextDelegate> context, SpecificationPrimitive<Action> @do, IEnumerable<SpecificationPrimitive<Action>> observations )
+            {
+                _observations = observations;
+                _context = context;
+                _do = @do;
+            }
+
+            public IEnumerable<ITestCommand> ObservationCommands( string name, IMethodInfo method )
+            {
+                if (_observations.Count() == 0)
+                    yield break;
+
+                bool setupExceptionOccurred = false;
+                IDisposable systemUnderTest = default( IDisposable );
+
+                Action setupAction = () =>
+                {
+                    try
+                    {
+                        systemUnderTest = SpecificationPrimitiveExecutor.Execute( _context );
+
+                        if (_do != null)
+                            SpecificationPrimitiveExecutor.Execute( _do );
+                    }
+                    catch (Exception)
+                    {
+                        setupExceptionOccurred = true;
+                        throw;
+                    }
+                };
+
+                yield return new ActionTestCommand( method, "{ " + name, 0, setupAction );
+
+                foreach (var observation in _observations)
+                {
+                    // do not capture the iteration variable because 
+                    // all tests would point to the same observation
+                    var capturableObservation = observation;
+                    Action perform = () =>
+                    {
+                        if (setupExceptionOccurred)
+                            throw new ContextSetupFailedException( "Setting up Context failed" );
+
+                        SpecificationPrimitiveExecutor.Execute( capturableObservation );
+                    };
+
+                    yield return new ActionTestCommand( method, "\t- " + capturableObservation.Message, 0, perform );
+                }
+
+                Action tearDownAction = () =>
+                {
+                    if (systemUnderTest != null)
+                        systemUnderTest.Dispose();
+
+                    if (setupExceptionOccurred)
+                        throw new ContextSetupFailedException( "Setting up Context failed, but Fixtures were disposed." );
+                };
+
+                yield return new ActionTestCommand( method, "} " + name, 0, tearDownAction );
+            }
+        }
+
+        /// <summary>
+        /// An exception that is thrown from Observations or their teardown whenever the corresponding setup failed.
+        /// </summary>
+        private class ContextSetupFailedException : Exception
+        {
+            public ContextSetupFailedException( string message ) : base( message ) { }
+        }
+
+        internal static class SpecificationContext
+        {
+            [ThreadStatic]
+            private static bool _threadStaticInitialized;
+            [ThreadStatic]
+            private static SpecificationPrimitive<ContextDelegate> _context;
+            [ThreadStatic]
+            private static SpecificationPrimitive<Action> _do;
+            [ThreadStatic]
+            private static List<SpecificationPrimitive<Action>> _asserts;
+            [ThreadStatic]
+            private static List<SpecificationPrimitive<Action>> _observations;
+            [ThreadStatic]
+            private static List<SpecificationPrimitive<Action>> _skips;
+            [ThreadStatic]
+            private static List<Action> _exceptions;
+
+            private static void Reset()
+            {
+                _exceptions = new List<Action>();
+                _context = null;
+                _do = null;
+                _asserts = new List<SpecificationPrimitive<Action>>();
+                _observations = new List<SpecificationPrimitive<Action>>();
+                _skips = new List<SpecificationPrimitive<Action>>();
+            }
+
+            private static void EnsureThreadStaticInitialized()
+            {
+                if (_threadStaticInitialized)
+                    return;
+
+                Reset();
+                _threadStaticInitialized = true;
+            }
+
+            public static ISpecificationPrimitive Context( string message, ContextDelegate arrange )
+            {
+                EnsureThreadStaticInitialized();
+
+                if (_context == null)
+                    _context = new SpecificationPrimitive<ContextDelegate>( message, arrange );
+                else
+                    _exceptions.Add( () => { throw new InvalidOperationException( "Cannot have more than one Context statement in a specification" ); } );
+
+                return _context;
+            }
+
+            public static ISpecificationPrimitive Do( string message, Action doAction )
+            {
+                EnsureThreadStaticInitialized();
+
+                if (_do == null)
+                    _do = new SpecificationPrimitive<Action>( message, doAction );
+                else
+                    _exceptions.Add( () => { throw new InvalidOperationException( "Cannot have more than one Do statement in a specification" ); } );
+
+                return _do;
+            }
+
+            public static ISpecificationPrimitive Assert( string message, Action assertAction )
+            {
+                EnsureThreadStaticInitialized();
+
+                SpecificationPrimitive<Action> assert = new SpecificationPrimitive<Action>( message, assertAction );
+                _asserts.Add( assert );
+
+                return assert;
+            }
+
+            public static ISpecificationPrimitive Observation( string message, Action observationAction )
+            {
+                EnsureThreadStaticInitialized();
+
+                var observation = new SpecificationPrimitive<Action>( message, observationAction );
+                _observations.Add( observation );
+
+                return observation;
+            }
+
+            public static ISpecificationPrimitive Todo( string message, Action skippedAction )
+            {
+                EnsureThreadStaticInitialized();
+
+                SpecificationPrimitive<Action> skip = new SpecificationPrimitive<Action>( message, skippedAction );
+                _skips.Add( skip );
+
+                return skip;
+            }
+
+            private static string PrepareSetupDescription()
+            {
+                string name = _context.Message;
+
+                if (_do != null)
+                    name += " " + _do.Message;
+                return name;
+            }
+
+            public static IEnumerable<ITestCommand> SafelyEnumerateTestCommands( IMethodInfo method, Action<IMethodInfo> registerPrimitives )
+            {
+                try
+                {
+                    registerPrimitives( method );
+