public void NonGenericMethod() { Recorder.Records.Clear(); RecordingHandler handler = new RecordingHandler(); MethodBase method = typeof(GenericSpy <>).GetMethod("MethodWhichTakesGenericData"); Dictionary <MethodBase, List <IInterceptionHandler> > dictionary = new Dictionary <MethodBase, List <IInterceptionHandler> >(); List <IInterceptionHandler> handlers = new List <IInterceptionHandler>(); handlers.Add(handler); dictionary.Add(method, handlers); GenericSpy <int> result = WrapAndCreateType <GenericSpy <int> >(dictionary); result.MethodWhichTakesGenericData(24); Assert.Equal(3, Recorder.Records.Count); Assert.Equal("Before Method", Recorder.Records[0]); Assert.Equal("In method with data 24", Recorder.Records[1]); Assert.Equal("After Method", Recorder.Records[2]); }
public void ReturnsDataOfGenericType() { Recorder.Records.Clear(); RecordingHandler handler = new RecordingHandler(); MethodBase method = typeof(GenericSpy <>).GetMethod("GenericReturn"); Dictionary <MethodBase, List <IInterceptionHandler> > dictionary = new Dictionary <MethodBase, List <IInterceptionHandler> >(); List <IInterceptionHandler> handlers = new List <IInterceptionHandler>(); handlers.Add(handler); dictionary.Add(method, handlers); GenericSpy <int> result = WrapAndCreateType <GenericSpy <int> >(dictionary); int value = result.GenericReturn(256.9); Assert.Equal(3, Recorder.Records.Count); Assert.Equal("Before Method", Recorder.Records[0]); Assert.Equal("In method with data 256.9", Recorder.Records[1]); Assert.Equal("After Method", Recorder.Records[2]); Assert.Equal(default(int), value); }