Skip to content

Instantly share code, notes, and snippets.

@bartelink
Created May 16, 2011 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartelink/974649 to your computer and use it in GitHub Desktop.
Save bartelink/974649 to your computer and use it in GitHub Desktop.
The consumption piece for HackedDisposableTrackingCustomization.cs
static class SutContext
{
public static SutContext<T> Create<T>()
{
T sut;
return Create<T>( out sut );
}
public static SutContext<T> Create<T>( out T sut )
{
return SutContext<T>.Create( out sut );
}
}
public class Frozen<T>
{
readonly T _value;
private Frozen( T t )
{
_value = t;
}
public Frozen( Fixture fixture )
: this( fixture.Freeze<T>() )
{
}
public static Frozen<T> Create( T t )
{
return new Frozen<T>( t );
}
public static implicit operator T( Frozen<T> frozen )
{
return frozen.Value;
}
public T Value
{
get { return _value; }
}
}
class SutContext<T> : IDisposable
{
readonly Fixture _fixture;
readonly HackedDisposableTrackingCustomization _tracking;
readonly T _sut;
internal static SutContext<T> Create( out T sut )
{
var result = new SutContext<T>();
sut = result._sut;
return result;
}
SutContext()
{
_fixture = new Fixture();
_tracking = new HackedDisposableTrackingCustomization();
_fixture.Customize( _tracking );
_fixture.Inject( _fixture ); // Allow specimens to demand Fixture
_sut = _fixture.Freeze<T>();
}
void IDisposable.Dispose()
{
_tracking.Dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment