Created
May 16, 2011 15:27
-
-
Save bartelink/974649 to your computer and use it in GitHub Desktop.
The consumption piece for HackedDisposableTrackingCustomization.cs
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
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