Skip to content

Instantly share code, notes, and snippets.

@Keboo
Last active Sep 20, 2020
Embed
What would you like to do?
Null constructor brain teaser. Simply replace ??? with any type that will cause the unit test to pass. Code used xUnit.
[Fact]
public static void NullReturnFromConstructor()
{
//Any Nullable<T> will work
Assert.Throws<InvalidOperationException>(() => SudoMakeMeSandwich<???>());
}
private static T SudoMakeMeSandwich<T>() where T : new()
{
return new T() ?? throw new InvalidOperationException();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment