This file contains hidden or 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
public class Tests | |
{ | |
[Input(1)] | |
[Input(true)] | |
[Input("Cantaloupe Pantaloons")] | |
public void GenericTestMethod<T>(T input) | |
{ | |
Console.WriteLine(typeof(T).Name); | |
} | |
} |
This file contains hidden or 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
var instance = new Thing(); | |
var method = typeof(Thing).GetMethod("GenericMethod"); | |
var methodOfInt32 = method.MakeGenericMethod(typeof(int)); | |
methodOfInt32.Invoke(instance, new object[] { 1 }); | |
var methodOfBoolean = method.MakeGenericMethod(typeof(bool)); | |
methodOfBoolean.Invoke(instance, new object[] { true }); |
This file contains hidden or 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
var instance = new Thing(); | |
var method = typeof(Thing).GetMethod("GenericMethod"); | |
method.Invoke(instance, new object[] { 1 }); | |
method.Invoke(instance, new object[] { true }); | |
method.Invoke(instance, new object[] { "Cantaloupe Pantaloons" }); |
This file contains hidden or 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
var instance = new Thing(); | |
instance.GenericMethod(1); //Compile-time type is Int32, so prints "Int32". | |
instance.GenericMethod(true); //Compile-time type is Boolean, so prints "Boolean". | |
instance.GenericMethod("Cantaloupe Pantaloons"); //Compile-time type is String, so prints "String". |
This file contains hidden or 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
public class Thing | |
{ | |
public void GenericMethod<T>(T input) | |
{ | |
Console.WriteLine(typeof(T).Name); | |
} | |
} |
This file contains hidden or 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
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] | |
public class SkipAttribute : Attribute | |
{ | |
public string ExpirationDate { get; set; } | |
public bool HasExpired | |
{ | |
get | |
{ | |
DateTime expirationDate; |
This file contains hidden or 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
public class CustomConvention : Convention | |
{ | |
public CustomConvention() | |
{ | |
Classes | |
.NameEndsWith("Tests"); | |
Methods | |
.Where(method => method.IsVoid()); |
This file contains hidden or 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
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] | |
public class SkipAttribute : Attribute { } | |
public class CustomConvention : Convention | |
{ | |
public CustomConvention() | |
{ | |
Classes | |
.NameEndsWith("Tests"); |
This file contains hidden or 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
public class ExecuteCases : InstanceBehavior | |
{ | |
public void Execute(Fixture fixture) | |
{ | |
foreach (var @case in fixture.Cases) | |
{ | |
using (var console = new RedirectedConsole()) | |
{ | |
var stopwatch = new Stopwatch(); | |
stopwatch.Start(); |
This file contains hidden or 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
public class RedirectedConsole : IDisposable | |
{ | |
readonly TextWriter outBefore; | |
readonly TextWriter errBefore; | |
readonly StringWriter console; | |
public RedirectedConsole() | |
{ | |
console = new StringWriter(); | |
outBefore = Console.Out; |