Last active
August 29, 2015 14:09
-
-
Save DarranShepherd/39225bf32eb3655854d8 to your computer and use it in GitHub Desktop.
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
public abstract class MyBaseClass { } | |
public class DerivedClass : MyBaseClass { } | |
public class SubjectClass | |
{ | |
private readonly IGenericFoo foo; | |
public SubjectClass(IGenericFoo foo) | |
{ | |
this.foo = foo; | |
} | |
public object GetObjectFromType(object input) | |
{ | |
return this.GetType().GetMethod("GetObjectFrom").MakeGenericMethod(input.GetType()).Invoke(this, new[] { input }); | |
} | |
public object GetObjectFrom<T>(T input) | |
{ | |
return this.foo.GetObjectFrom<T>(); | |
} | |
} | |
public interface IGenericFoo | |
{ | |
object GetObjectFrom<T>(); | |
} | |
public class Test : WithSubject<SubjectClass> | |
{ | |
static MyBaseClass input; | |
static object o; | |
Establish context = () => input = new DerivedClass(); | |
Because of = () => o = Subject.GetObjectFromType(input); | |
It should_have_called_with_derived = () => The<IGenericFoo>().WasToldTo(f => f.GetObjectFrom<DerivedClass>()); | |
It should_not_have_called_with_base = () => The<IGenericFoo>().WasNotToldTo(f => f.GetObjectFrom<MyBaseClass>()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment