Skip to content

Instantly share code, notes, and snippets.

@adamjasinski
Last active August 29, 2015 13:56
Show Gist options
  • Save adamjasinski/8861215 to your computer and use it in GitHub Desktop.
Save adamjasinski/8861215 to your computer and use it in GitHub Desktop.
public static class ExceptionsFacts
{
[Theory, AutoData]
static void AllExceptionsShouldBeSerializable( SerializableAssertion assertion )
{
assertion.Verify( typeof( MyException ).Assembly.GetTypes()
.Where( x => typeof( Exception ).IsAssignableFrom( x ) ) );
}
}
class SerializableAssertion : IdiomaticAssertion
{
readonly ISpecimenContext _specimenResolver;
public SerializableAssertion( ISpecimenBuilder builder )
{
_specimenResolver = new SpecimenContext(builder);
}
public override void Verify( Type type )
{
var specimen = _specimenResolver.Resolve( type );
//Assert.IsType( type, specimen );
using ( var ms = new MemoryStream() )
new BinaryFormatter().Serialize( ms, specimen );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment